diff --git a/.github/workflows/clang-tidy.yaml b/.github/workflows/clang-tidy.yaml index 1d8e068777..35505e8512 100644 --- a/.github/workflows/clang-tidy.yaml +++ b/.github/workflows/clang-tidy.yaml @@ -17,9 +17,9 @@ jobs: matrix: include: - cmake_options: all-options-abiv1-preview - warning_limit: 490 + warning_limit: 330 - cmake_options: all-options-abiv2-preview - warning_limit: 492 + warning_limit: 332 env: CC: /usr/bin/clang-18 CXX: /usr/bin/clang++-18 diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a6485e3d3..a7788e32f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,9 @@ Increment the: * [EXAMPLES] Deprecated semantic conventions used [#3905](https://github.com/open-telemetry/opentelemetry-cpp/pull/3905) +* [CODE HEALTH] Fix clang-tidy misc-use-internal-linkage warnings + [#3600](https://github.com/open-telemetry/opentelemetry-cpp/pull/3600) + Important changes: * [BUILD] Revisit EventLogger deprecation diff --git a/api/test/baggage/baggage_test.cc b/api/test/baggage/baggage_test.cc index be7b4ccdf4..cd19be487a 100644 --- a/api/test/baggage/baggage_test.cc +++ b/api/test/baggage/baggage_test.cc @@ -15,7 +15,7 @@ using namespace opentelemetry::baggage; -std::string header_with_custom_entries(size_t num_entries) +static std::string header_with_custom_entries(size_t num_entries) { std::string header; for (size_t i = 0; i < num_entries; i++) @@ -31,7 +31,7 @@ std::string header_with_custom_entries(size_t num_entries) return header; } -std::string header_with_custom_size(size_t key_value_size, size_t num_entries) +static std::string header_with_custom_size(size_t key_value_size, size_t num_entries) { std::string header = ""; for (size_t i = 0; i < num_entries; i++) diff --git a/api/test/nostd/function_ref_test.cc b/api/test/nostd/function_ref_test.cc index 460561e765..2159e6d2ee 100644 --- a/api/test/nostd/function_ref_test.cc +++ b/api/test/nostd/function_ref_test.cc @@ -8,12 +8,12 @@ using namespace opentelemetry::nostd; -int Call(function_ref f) +static int Call(function_ref f) { return f(); } -int Return3() +static int Return3() { return 3; } diff --git a/api/test/singleton/singleton_test.cc b/api/test/singleton/singleton_test.cc index 36101df86f..ad945b9084 100644 --- a/api/test/singleton/singleton_test.cc +++ b/api/test/singleton/singleton_test.cc @@ -32,7 +32,7 @@ using namespace opentelemetry; -void do_something() +static void do_something() { do_something_in_a(); do_something_in_b(); @@ -111,33 +111,33 @@ void do_something() #endif /* BAZEL_BUILD */ } -int span_a_lib_count = 0; -int span_a_f1_count = 0; -int span_a_f2_count = 0; -int span_b_lib_count = 0; -int span_b_f1_count = 0; -int span_b_f2_count = 0; -int span_c_lib_count = 0; -int span_c_f1_count = 0; -int span_c_f2_count = 0; -int span_d_lib_count = 0; -int span_d_f1_count = 0; -int span_d_f2_count = 0; -int span_e_lib_count = 0; -int span_e_f1_count = 0; -int span_e_f2_count = 0; -int span_f_lib_count = 0; -int span_f_f1_count = 0; -int span_f_f2_count = 0; -int span_g_lib_count = 0; -int span_g_f1_count = 0; -int span_g_f2_count = 0; -int span_h_lib_count = 0; -int span_h_f1_count = 0; -int span_h_f2_count = 0; -int unknown_span_count = 0; - -void reset_counts() +static int span_a_lib_count = 0; +static int span_a_f1_count = 0; +static int span_a_f2_count = 0; +static int span_b_lib_count = 0; +static int span_b_f1_count = 0; +static int span_b_f2_count = 0; +static int span_c_lib_count = 0; +static int span_c_f1_count = 0; +static int span_c_f2_count = 0; +static int span_d_lib_count = 0; +static int span_d_f1_count = 0; +static int span_d_f2_count = 0; +static int span_e_lib_count = 0; +static int span_e_f1_count = 0; +static int span_e_f2_count = 0; +static int span_f_lib_count = 0; +static int span_f_f1_count = 0; +static int span_f_f2_count = 0; +static int span_g_lib_count = 0; +static int span_g_f1_count = 0; +static int span_g_f2_count = 0; +static int span_h_lib_count = 0; +static int span_h_f1_count = 0; +static int span_h_f2_count = 0; +static int unknown_span_count = 0; + +static void reset_counts() { span_a_lib_count = 0; span_a_f1_count = 0; @@ -331,7 +331,7 @@ class MyTracerProvider : public trace::TracerProvider #endif }; -void setup_otel() +static void setup_otel() { std::shared_ptr provider = MyTracerProvider::Create(); @@ -343,7 +343,7 @@ void setup_otel() trace_api::Provider::SetTracerProvider(provider); } -void cleanup_otel() +static void cleanup_otel() { std::shared_ptr provider( new opentelemetry::trace::NoopTracerProvider()); diff --git a/exporters/ostream/src/metric_exporter.cc b/exporters/ostream/src/metric_exporter.cc index 39f5b017e7..89e47f96af 100644 --- a/exporters/ostream/src/metric_exporter.cc +++ b/exporters/ostream/src/metric_exporter.cc @@ -76,7 +76,7 @@ namespace metrics { template -inline void printVec(std::ostream &os, Container &vec) +static inline void printVec(std::ostream &os, Container &vec) { using T = typename std::decay::type; os << '['; diff --git a/exporters/ostream/src/span_exporter.cc b/exporters/ostream/src/span_exporter.cc index f41d33ae6c..228ca65127 100644 --- a/exporters/ostream/src/span_exporter.cc +++ b/exporters/ostream/src/span_exporter.cc @@ -40,7 +40,7 @@ namespace exporter namespace trace { -std::ostream &operator<<(std::ostream &os, trace_api::SpanKind span_kind) +static std::ostream &operator<<(std::ostream &os, trace_api::SpanKind span_kind) { switch (span_kind) { diff --git a/exporters/otlp/test/otlp_http_exporter_test.cc b/exporters/otlp/test/otlp_http_exporter_test.cc index 85a27022a3..3cbfa9d16c 100644 --- a/exporters/otlp/test/otlp_http_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_exporter_test.cc @@ -56,8 +56,8 @@ static nostd::span MakeSpan(T (&array)[N]) return nostd::span(array); } -OtlpHttpClientOptions MakeOtlpHttpClientOptions(HttpRequestContentType content_type, - bool async_mode) +static OtlpHttpClientOptions MakeOtlpHttpClientOptions(HttpRequestContentType content_type, + bool async_mode) { std::shared_ptr not_instrumented; OtlpHttpExporterOptions options; diff --git a/exporters/otlp/test/otlp_http_log_record_exporter_test.cc b/exporters/otlp/test/otlp_http_log_record_exporter_test.cc index f887b2372e..3fca7a06ea 100644 --- a/exporters/otlp/test/otlp_http_log_record_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_log_record_exporter_test.cc @@ -51,8 +51,8 @@ static nostd::span MakeSpan(T (&array)[N]) return nostd::span(array); } -OtlpHttpClientOptions MakeOtlpHttpClientOptions(HttpRequestContentType content_type, - bool async_mode) +static OtlpHttpClientOptions MakeOtlpHttpClientOptions(HttpRequestContentType content_type, + bool async_mode) { std::shared_ptr not_instrumented; OtlpHttpLogRecordExporterOptions options; diff --git a/exporters/otlp/test/otlp_http_metric_exporter_test.cc b/exporters/otlp/test/otlp_http_metric_exporter_test.cc index f27c186e2e..cd3b89183c 100644 --- a/exporters/otlp/test/otlp_http_metric_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_metric_exporter_test.cc @@ -72,8 +72,8 @@ static IntegerType JsonToInteger(nlohmann::json value) return value.get(); } -OtlpHttpClientOptions MakeOtlpHttpClientOptions(HttpRequestContentType content_type, - bool async_mode) +static OtlpHttpClientOptions MakeOtlpHttpClientOptions(HttpRequestContentType content_type, + bool async_mode) { std::shared_ptr not_instrumented; OtlpHttpMetricExporterOptions options; diff --git a/exporters/prometheus/src/exporter_options.cc b/exporters/prometheus/src/exporter_options.cc index 0798f47cf9..a713cf3c2c 100644 --- a/exporters/prometheus/src/exporter_options.cc +++ b/exporters/prometheus/src/exporter_options.cc @@ -13,7 +13,7 @@ namespace exporter namespace metrics { -inline const std::string GetPrometheusDefaultHttpEndpoint() +static inline const std::string GetPrometheusDefaultHttpEndpoint() { constexpr char kPrometheusEndpointEnv[] = "PROMETHEUS_EXPORTER_ENDPOINT"; constexpr char kPrometheusEndpointDefault[] = "localhost:9464"; @@ -25,7 +25,7 @@ inline const std::string GetPrometheusDefaultHttpEndpoint() return exists ? endpoint : kPrometheusEndpointDefault; } -inline bool GetPrometheusWithoutOtelScope() +static inline bool GetPrometheusWithoutOtelScope() { constexpr char kPrometheusWithoutOtelScope[] = "OTEL_CPP_PROMETHEUS_EXPORTER_WITHOUT_OTEL_SCOPE"; @@ -36,7 +36,7 @@ inline bool GetPrometheusWithoutOtelScope() return exists ? setting : false; } -inline bool GetPrometheusPopulateTargetInfo() +static inline bool GetPrometheusPopulateTargetInfo() { constexpr char kPrometheusPopulateTargetInfo[] = "OTEL_CPP_PROMETHEUS_EXPORTER_POPULATE_TARGET_INFO"; @@ -48,7 +48,7 @@ inline bool GetPrometheusPopulateTargetInfo() return exists ? setting : true; } -inline bool GetPrometheusWithoutUnits() +static inline bool GetPrometheusWithoutUnits() { constexpr char kPrometheusWithoutUnits[] = "OTEL_CPP_PROMETHEUS_EXPORTER_WITHOUT_UNITS"; bool setting{}; @@ -58,7 +58,7 @@ inline bool GetPrometheusWithoutUnits() return exists ? setting : false; } -inline bool GetPrometheusWithoutTypeSuffix() +static inline bool GetPrometheusWithoutTypeSuffix() { constexpr char kPrometheusWithoutTypeSuffix[] = "OTEL_CPP_PROMETHEUS_EXPORTER_WITHOUT_TYPE_SUFFIX"; diff --git a/exporters/prometheus/test/exporter_utils_test.cc b/exporters/prometheus/test/exporter_utils_test.cc index 4ad329f0ec..b5dcd554fe 100644 --- a/exporters/prometheus/test/exporter_utils_test.cc +++ b/exporters/prometheus/test/exporter_utils_test.cc @@ -79,12 +79,12 @@ class SanitizeNameTester } // namespace exporter template -void assert_basic(prometheus_client::MetricFamily &metric, - const std::string &expected_name, - const std::string &description, - prometheus_client::MetricType type, - size_t label_num, - std::vector vals) +static void assert_basic(prometheus_client::MetricFamily &metric, + const std::string &expected_name, + const std::string &description, + prometheus_client::MetricType type, + size_t label_num, + std::vector vals) { ASSERT_EQ(metric.name, expected_name); // name sanitized ASSERT_EQ(metric.help, description); // description not changed @@ -130,9 +130,9 @@ void assert_basic(prometheus_client::MetricFamily &metric, } } -void assert_histogram(prometheus_client::MetricFamily &metric, - const std::list &boundaries, - std::vector correct) +static void assert_histogram(prometheus_client::MetricFamily &metric, + const std::list &boundaries, + std::vector correct) { int cumulative_count = 0; auto buckets = metric.metric[0].histogram.bucket; diff --git a/exporters/zipkin/src/recordable.cc b/exporters/zipkin/src/recordable.cc index 7152e7c92b..24325ffd24 100644 --- a/exporters/zipkin/src/recordable.cc +++ b/exporters/zipkin/src/recordable.cc @@ -70,9 +70,9 @@ void Recordable::SetIdentity(const trace_api::SpanContext &span_context, span_["traceId"] = std::string(trace_id_lower_base16, 32); } -void PopulateAttribute(nlohmann::json &attribute, - nostd::string_view key, - const common::AttributeValue &value) +static void PopulateAttribute(nlohmann::json &attribute, + nostd::string_view key, + const common::AttributeValue &value) { // Assert size of variant to ensure that this method gets updated if the variant // definition changes diff --git a/exporters/zipkin/test/zipkin_exporter_test.cc b/exporters/zipkin/test/zipkin_exporter_test.cc index acb0db5402..36a78edf9c 100644 --- a/exporters/zipkin/test/zipkin_exporter_test.cc +++ b/exporters/zipkin/test/zipkin_exporter_test.cc @@ -101,7 +101,7 @@ class IsValidMessageMatcher std::string trace_id_; }; -PolymorphicMatcher IsValidMessage(const std::string &trace_id) +static PolymorphicMatcher IsValidMessage(const std::string &trace_id) { return MakePolymorphicMatcher(IsValidMessageMatcher(trace_id)); } diff --git a/ext/src/http/client/curl/http_client_curl.cc b/ext/src/http/client/curl/http_client_curl.cc index 7c5ddd19e8..3a25e82181 100644 --- a/ext/src/http/client/curl/http_client_curl.cc +++ b/ext/src/http/client/curl/http_client_curl.cc @@ -67,7 +67,7 @@ nostd::shared_ptr HttpCurlGlobalInitializer::GetInsta #ifdef ENABLE_OTLP_COMPRESSION_PREVIEW // Original source: // https://stackoverflow.com/questions/12398377/is-it-possible-to-have-zlib-read-from-and-write-to-the-same-memory-buffer/12412863#12412863 -int deflateInPlace(z_stream *strm, unsigned char *buf, uint32_t len, uint32_t *max_len) +static int deflateInPlace(z_stream *strm, unsigned char *buf, uint32_t len, uint32_t *max_len) { // must be large enough to hold zlib or gzip header (if any) and one more byte -- 11 works for the // worst case here, but if gzip encoding is used and a deflateSetHeader() call is inserted in this diff --git a/ext/test/w3c_tracecontext_http_test_server/main.cc b/ext/test/w3c_tracecontext_http_test_server/main.cc index 57edb0860b..adb5ddbfc0 100644 --- a/ext/test/w3c_tracecontext_http_test_server/main.cc +++ b/ext/test/w3c_tracecontext_http_test_server/main.cc @@ -138,7 +138,7 @@ class NoopEventHandler : public http_client::EventHandler } // namespace // Sends an HTTP POST request to the given url, with the given body. -void send_request(curl::HttpClient &client, const std::string &url, const std::string &body) +static void send_request(curl::HttpClient &client, const std::string &url, const std::string &body) { static std::shared_ptr handler(new NoopEventHandler()); diff --git a/functional/otlp/func_grpc_main.cc b/functional/otlp/func_grpc_main.cc index bd51b6a85a..d7082c2e6b 100644 --- a/functional/otlp/func_grpc_main.cc +++ b/functional/otlp/func_grpc_main.cc @@ -47,15 +47,15 @@ enum class TestMode : std::uint8_t kHttps }; -bool opt_help = false; -bool opt_list = false; -bool opt_debug = false; -bool opt_secure = false; +static bool opt_help = false; +static bool opt_list = false; +static bool opt_debug = false; +static bool opt_secure = false; // HTTPS by default -std::string opt_endpoint = "https://127.0.0.1:4317"; -std::string opt_cert_dir; -std::string opt_test_name; -TestMode opt_mode = TestMode::kNone; +static std::string opt_endpoint = "https://127.0.0.1:4317"; +static std::string opt_cert_dir; +static std::string opt_test_name; +static TestMode opt_mode = TestMode::kNone; /* Log parsing @@ -79,9 +79,9 @@ struct TestResult } }; -struct TestResult g_test_result; +static struct TestResult g_test_result; -void parse_error_msg(TestResult *result, const std::string &msg) +static void parse_error_msg(TestResult *result, const std::string &msg) { static std::string connection_failed("failed to connect to all addresses"); @@ -112,11 +112,11 @@ void parse_error_msg(TestResult *result, const std::string &msg) } } -void parse_warning_msg(TestResult * /* result */, const std::string & /* msg */) {} +static void parse_warning_msg(TestResult * /* result */, const std::string & /* msg */) {} -void parse_info_msg(TestResult * /* result */, const std::string & /* msg */) {} +static void parse_info_msg(TestResult * /* result */, const std::string & /* msg */) {} -void parse_debug_msg(TestResult *result, const std::string &msg) +static void parse_debug_msg(TestResult *result, const std::string &msg) { static std::string export_success("Export 1 trace span(s) success"); @@ -164,7 +164,7 @@ class TestLogHandler : public opentelemetry::sdk::common::internal_log::LogHandl } }; -void init(const otlp::OtlpGrpcExporterOptions &opts) +static void init(const otlp::OtlpGrpcExporterOptions &opts) { // Create OTLP exporter instance auto exporter = otlp::OtlpGrpcExporterFactory::Create(opts); @@ -175,7 +175,7 @@ void init(const otlp::OtlpGrpcExporterOptions &opts) trace_sdk::Provider::SetTracerProvider(provider); } -void payload() +static void payload() { static const nostd::string_view k_tracer_name("func_test"); static const nostd::string_view k_span_name("func_grpc_main"); @@ -189,13 +189,13 @@ void payload() span->End(); } -void cleanup() +static void cleanup() { std::shared_ptr none; trace_sdk::Provider::SetTracerProvider(none); } -void instrumented_payload(const otlp::OtlpGrpcExporterOptions &opts) +static void instrumented_payload(const otlp::OtlpGrpcExporterOptions &opts) { g_test_result.reset(); init(opts); @@ -203,7 +203,7 @@ void instrumented_payload(const otlp::OtlpGrpcExporterOptions &opts) cleanup(); } -void usage(FILE *out) +static void usage(FILE *out) { static const char *msg = "Usage: func_otlp_grpc [options] test_name\n" @@ -219,7 +219,7 @@ void usage(FILE *out) fprintf(out, "%s", msg); } -int parse_args(int argc, char *argv[]) +static int parse_args(int argc, char *argv[]) { int remaining_argc = argc; char **remaining_argv = argv; @@ -320,20 +320,22 @@ struct test_case test_func_t m_func; }; -int test_basic(); +static int test_basic(); -int test_cert_not_found(); -int test_cert_invalid(); -int test_cert_unreadable(); -int test_client_cert_not_found(); -int test_client_cert_invalid(); -int test_client_cert_unreadable(); -int test_client_cert_no_key(); -int test_client_key_not_found(); -int test_client_key_invalid(); -int test_client_key_unreadable(); +static int test_cert_not_found(); +static int test_cert_invalid(); +static int test_cert_unreadable(); -int test_mtls_ok(); +#ifdef ENABLE_OTLP_GRPC_SSL_MTLS_PREVIEW +static int test_client_cert_not_found(); +static int test_client_cert_invalid(); +static int test_client_cert_unreadable(); +static int test_client_cert_no_key(); +static int test_client_key_not_found(); +static int test_client_key_invalid(); +static int test_client_key_unreadable(); +static int test_mtls_ok(); +#endif // ENABLE_OTLP_GRPC_SSL_MTLS_PREVIEW static const test_case all_tests[] = {{"basic", test_basic}, {"cert-not-found", test_cert_not_found}, @@ -362,7 +364,7 @@ void list_test_cases() } } -int run_test_case(const std::string &name) +static int run_test_case(const std::string &name) { const test_case *current = all_tests; @@ -424,7 +426,7 @@ int main(int argc, char *argv[]) return rc; } -void set_common_opts(otlp::OtlpGrpcExporterOptions &opts) +static void set_common_opts(otlp::OtlpGrpcExporterOptions &opts) { opts.endpoint = opt_endpoint; opts.timeout = std::chrono::milliseconds{100}; @@ -436,7 +438,7 @@ void set_common_opts(otlp::OtlpGrpcExporterOptions &opts) #endif } -int expect_connection_failed() +static int expect_connection_failed() { if (g_test_result.found_export_error && (g_test_result.found_connection_failed || g_test_result.deadline_exceeded || @@ -447,7 +449,7 @@ int expect_connection_failed() return TEST_FAILED; } -int expect_success() +static int expect_success() { if (g_test_result.found_export_success) { @@ -456,7 +458,7 @@ int expect_success() return TEST_FAILED; } -int expect_export_failed() +static int expect_export_failed() { /* Can not test exact root cause: @@ -473,7 +475,7 @@ int expect_export_failed() return TEST_FAILED; } -int test_basic() +static int test_basic() { otlp::OtlpGrpcExporterOptions opts; @@ -504,7 +506,7 @@ int test_basic() return expect_connection_failed(); } -int test_cert_not_found() +static int test_cert_not_found() { otlp::OtlpGrpcExporterOptions opts; @@ -531,7 +533,7 @@ int test_cert_not_found() return expect_connection_failed(); } -int test_cert_invalid() +static int test_cert_invalid() { otlp::OtlpGrpcExporterOptions opts; @@ -558,7 +560,7 @@ int test_cert_invalid() return expect_connection_failed(); } -int test_cert_unreadable() +static int test_cert_unreadable() { otlp::OtlpGrpcExporterOptions opts; @@ -586,7 +588,7 @@ int test_cert_unreadable() } #ifdef ENABLE_OTLP_GRPC_SSL_MTLS_PREVIEW -int test_client_cert_not_found() +static int test_client_cert_not_found() { otlp::OtlpGrpcExporterOptions opts; @@ -614,7 +616,7 @@ int test_client_cert_not_found() return expect_connection_failed(); } -int test_client_cert_invalid() +static int test_client_cert_invalid() { otlp::OtlpGrpcExporterOptions opts; @@ -642,7 +644,7 @@ int test_client_cert_invalid() return expect_connection_failed(); } -int test_client_cert_unreadable() +static int test_client_cert_unreadable() { otlp::OtlpGrpcExporterOptions opts; @@ -670,7 +672,7 @@ int test_client_cert_unreadable() return expect_connection_failed(); } -int test_client_cert_no_key() +static int test_client_cert_no_key() { otlp::OtlpGrpcExporterOptions opts; @@ -698,7 +700,7 @@ int test_client_cert_no_key() return expect_connection_failed(); } -int test_client_key_not_found() +static int test_client_key_not_found() { otlp::OtlpGrpcExporterOptions opts; @@ -727,7 +729,7 @@ int test_client_key_not_found() return expect_connection_failed(); } -int test_client_key_invalid() +static int test_client_key_invalid() { otlp::OtlpGrpcExporterOptions opts; @@ -756,7 +758,7 @@ int test_client_key_invalid() return expect_connection_failed(); } -int test_client_key_unreadable() +static int test_client_key_unreadable() { otlp::OtlpGrpcExporterOptions opts; @@ -785,7 +787,7 @@ int test_client_key_unreadable() return expect_connection_failed(); } -int test_mtls_ok() +static int test_mtls_ok() { otlp::OtlpGrpcExporterOptions opts; diff --git a/functional/otlp/func_http_main.cc b/functional/otlp/func_http_main.cc index 874c8bec04..fed702e9cc 100644 --- a/functional/otlp/func_http_main.cc +++ b/functional/otlp/func_http_main.cc @@ -46,15 +46,15 @@ enum test_mode : std::uint8_t MODE_HTTPS }; -bool opt_help = false; -bool opt_list = false; -bool opt_debug = false; -bool opt_secure = false; +static bool opt_help = false; +static bool opt_list = false; +static bool opt_debug = false; +static bool opt_secure = false; // HTTPS by default -std::string opt_endpoint = "https://localhost:4318/v1/traces"; -std::string opt_cert_dir; -std::string opt_test_name; -test_mode opt_mode = MODE_NONE; +static std::string opt_endpoint = "https://localhost:4318/v1/traces"; +static std::string opt_cert_dir; +static std::string opt_test_name; +static test_mode opt_mode = MODE_NONE; /* Log parsing @@ -82,9 +82,9 @@ struct TestResult } }; -struct TestResult g_test_result; +static struct TestResult g_test_result; -void parse_error_msg(TestResult *result, const std::string &msg) +static void parse_error_msg(TestResult *result, const std::string &msg) { static std::string connection_failed("Session state: connection failed."); @@ -129,11 +129,11 @@ void parse_error_msg(TestResult *result, const std::string &msg) } } -void parse_warning_msg(TestResult * /* result */, const std::string & /* msg */) {} +static void parse_warning_msg(TestResult * /* result */, const std::string & /* msg */) {} -void parse_info_msg(TestResult * /* result */, const std::string & /* msg */) {} +static void parse_info_msg(TestResult * /* result */, const std::string & /* msg */) {} -void parse_debug_msg(TestResult *result, const std::string &msg) +static void parse_debug_msg(TestResult *result, const std::string &msg) { static std::string export_success("Export 1 trace span(s) success"); @@ -181,7 +181,7 @@ class TestLogHandler : public opentelemetry::sdk::common::internal_log::LogHandl } }; -void init(const otlp::OtlpHttpExporterOptions &opts) +static void init(const otlp::OtlpHttpExporterOptions &opts) { // Create OTLP exporter instance auto exporter = otlp::OtlpHttpExporterFactory::Create(opts); @@ -192,7 +192,7 @@ void init(const otlp::OtlpHttpExporterOptions &opts) trace_sdk::Provider::SetTracerProvider(provider); } -void payload() +static void payload() { static const nostd::string_view k_tracer_name("func_test"); static const nostd::string_view k_span_name("func_http_main"); @@ -206,13 +206,13 @@ void payload() span->End(); } -void cleanup() +static void cleanup() { std::shared_ptr none; trace_sdk::Provider::SetTracerProvider(none); } -void instrumented_payload(const otlp::OtlpHttpExporterOptions &opts) +static void instrumented_payload(const otlp::OtlpHttpExporterOptions &opts) { g_test_result.reset(); init(opts); @@ -220,7 +220,7 @@ void instrumented_payload(const otlp::OtlpHttpExporterOptions &opts) cleanup(); } -void usage(FILE *out) +static void usage(FILE *out) { static const char *msg = "Usage: func_otlp_http [options] test_name\n" @@ -236,7 +236,7 @@ void usage(FILE *out) fprintf(out, "%s", msg); } -int parse_args(int argc, char *argv[]) +static int parse_args(int argc, char *argv[]) { int remaining_argc = argc; char **remaining_argv = argv; @@ -337,49 +337,49 @@ struct test_case test_func_t m_func; }; -int test_basic(); - -int test_cert_not_found(); -int test_cert_invalid(); -int test_cert_unreadable(); -int test_cert_ok(); -int test_client_cert_not_found(); -int test_client_cert_invalid(); -int test_client_cert_unreadable(); -int test_client_cert_no_key(); -int test_client_key_not_found(); -int test_client_key_invalid(); -int test_client_key_unreadable(); -int test_client_key_ok(); - -int test_min_tls_unknown(); -int test_min_tls_10(); -int test_min_tls_11(); -int test_min_tls_12(); -int test_min_tls_13(); -int test_max_tls_unknown(); -int test_max_tls_10(); -int test_max_tls_11(); -int test_max_tls_12(); -int test_max_tls_13(); -int test_range_tls_10(); -int test_range_tls_11(); -int test_range_tls_12(); -int test_range_tls_13(); -int test_range_tls_10_11(); -int test_range_tls_10_12(); -int test_range_tls_10_13(); -int test_range_tls_11_10(); -int test_range_tls_11_12(); -int test_range_tls_11_13(); -int test_range_tls_12_10(); -int test_range_tls_12_11(); -int test_range_tls_12_13(); -int test_range_tls_13_10(); -int test_range_tls_13_11(); -int test_range_tls_13_12(); - -int test_gzip_compression(); +static int test_basic(); + +static int test_cert_not_found(); +static int test_cert_invalid(); +static int test_cert_unreadable(); +static int test_cert_ok(); +static int test_client_cert_not_found(); +static int test_client_cert_invalid(); +static int test_client_cert_unreadable(); +static int test_client_cert_no_key(); +static int test_client_key_not_found(); +static int test_client_key_invalid(); +static int test_client_key_unreadable(); +static int test_client_key_ok(); + +static int test_min_tls_unknown(); +static int test_min_tls_10(); +static int test_min_tls_11(); +static int test_min_tls_12(); +static int test_min_tls_13(); +static int test_max_tls_unknown(); +static int test_max_tls_10(); +static int test_max_tls_11(); +static int test_max_tls_12(); +static int test_max_tls_13(); +static int test_range_tls_10(); +static int test_range_tls_11(); +static int test_range_tls_12(); +static int test_range_tls_13(); +static int test_range_tls_10_11(); +static int test_range_tls_10_12(); +static int test_range_tls_10_13(); +static int test_range_tls_11_10(); +static int test_range_tls_11_12(); +static int test_range_tls_11_13(); +static int test_range_tls_12_10(); +static int test_range_tls_12_11(); +static int test_range_tls_12_13(); +static int test_range_tls_13_10(); +static int test_range_tls_13_11(); +static int test_range_tls_13_12(); + +static int test_gzip_compression(); static const test_case all_tests[] = {{"basic", test_basic}, {"cert-not-found", test_cert_not_found}, @@ -423,7 +423,7 @@ static const test_case all_tests[] = {{"basic", test_basic}, {"gzip-compression", test_gzip_compression}, {"", nullptr}}; -void list_test_cases() +static void list_test_cases() { const test_case *current = all_tests; @@ -434,7 +434,7 @@ void list_test_cases() } } -int run_test_case(const std::string &name) +static int run_test_case(const std::string &name) { const test_case *current = all_tests; @@ -496,7 +496,7 @@ int main(int argc, char *argv[]) return rc; } -void set_common_opts(otlp::OtlpHttpExporterOptions &opts) +static void set_common_opts(otlp::OtlpHttpExporterOptions &opts) { opts.url = opt_endpoint; @@ -511,7 +511,7 @@ void set_common_opts(otlp::OtlpHttpExporterOptions &opts) #endif } -int expect_connection_failed() +static int expect_connection_failed() { if (g_test_result.found_export_error && g_test_result.found_connection_failed) { @@ -520,7 +520,7 @@ int expect_connection_failed() return TEST_FAILED; } -int expect_success() +static int expect_success() { if (g_test_result.found_export_success) { @@ -529,7 +529,8 @@ int expect_success() return TEST_FAILED; } -int expect_request_send_failed() +#if 0 +static int expect_request_send_failed() { if (g_test_result.found_export_error && g_test_result.found_request_send_failure) { @@ -537,8 +538,9 @@ int expect_request_send_failed() } return TEST_FAILED; } +#endif -int expect_unknown_min_tls() +static int expect_unknown_min_tls() { if (g_test_result.found_export_error && g_test_result.found_unknown_min_tls) { @@ -547,7 +549,7 @@ int expect_unknown_min_tls() return TEST_FAILED; } -int expect_unknown_max_tls() +static int expect_unknown_max_tls() { if (g_test_result.found_export_error && g_test_result.found_unknown_max_tls) { @@ -556,7 +558,7 @@ int expect_unknown_max_tls() return TEST_FAILED; } -int expect_export_failed() +static int expect_export_failed() { /* Can not test exact root cause: @@ -573,7 +575,7 @@ int expect_export_failed() return TEST_FAILED; } -int test_basic() +static int test_basic() { otlp::OtlpHttpExporterOptions opts; @@ -604,7 +606,7 @@ int test_basic() return expect_connection_failed(); } -int test_cert_not_found() +static int test_cert_not_found() { otlp::OtlpHttpExporterOptions opts; @@ -631,7 +633,7 @@ int test_cert_not_found() return expect_connection_failed(); } -int test_cert_invalid() +static int test_cert_invalid() { otlp::OtlpHttpExporterOptions opts; @@ -658,7 +660,7 @@ int test_cert_invalid() return expect_connection_failed(); } -int test_cert_unreadable() +static int test_cert_unreadable() { otlp::OtlpHttpExporterOptions opts; @@ -685,7 +687,7 @@ int test_cert_unreadable() return expect_connection_failed(); } -int test_cert_ok() +static int test_cert_ok() { otlp::OtlpHttpExporterOptions opts; @@ -717,7 +719,7 @@ int test_cert_ok() return expect_success(); } -int test_client_cert_not_found() +static int test_client_cert_not_found() { otlp::OtlpHttpExporterOptions opts; @@ -745,7 +747,7 @@ int test_client_cert_not_found() return expect_connection_failed(); } -int test_client_cert_invalid() +static int test_client_cert_invalid() { otlp::OtlpHttpExporterOptions opts; @@ -773,7 +775,7 @@ int test_client_cert_invalid() return expect_connection_failed(); } -int test_client_cert_unreadable() +static int test_client_cert_unreadable() { otlp::OtlpHttpExporterOptions opts; @@ -801,7 +803,7 @@ int test_client_cert_unreadable() return expect_connection_failed(); } -int test_client_cert_no_key() +static int test_client_cert_no_key() { otlp::OtlpHttpExporterOptions opts; @@ -829,7 +831,7 @@ int test_client_cert_no_key() return expect_connection_failed(); } -int test_client_key_not_found() +static int test_client_key_not_found() { otlp::OtlpHttpExporterOptions opts; @@ -858,7 +860,7 @@ int test_client_key_not_found() return expect_connection_failed(); } -int test_client_key_invalid() +static int test_client_key_invalid() { otlp::OtlpHttpExporterOptions opts; @@ -887,7 +889,7 @@ int test_client_key_invalid() return expect_connection_failed(); } -int test_client_key_unreadable() +static int test_client_key_unreadable() { otlp::OtlpHttpExporterOptions opts; @@ -916,7 +918,7 @@ int test_client_key_unreadable() return expect_connection_failed(); } -int test_client_key_ok() +static int test_client_key_ok() { otlp::OtlpHttpExporterOptions opts; @@ -950,7 +952,7 @@ int test_client_key_ok() return expect_success(); } -int test_min_tls_unknown() +static int test_min_tls_unknown() { otlp::OtlpHttpExporterOptions opts; @@ -980,7 +982,7 @@ int test_min_tls_unknown() return expect_unknown_min_tls(); } -int test_min_tls_10() +static int test_min_tls_10() { otlp::OtlpHttpExporterOptions opts; @@ -1015,7 +1017,7 @@ int test_min_tls_10() return expect_unknown_min_tls(); } -int test_min_tls_11() +static int test_min_tls_11() { otlp::OtlpHttpExporterOptions opts; @@ -1050,7 +1052,7 @@ int test_min_tls_11() return expect_unknown_min_tls(); } -int test_min_tls_12() +static int test_min_tls_12() { otlp::OtlpHttpExporterOptions opts; @@ -1085,7 +1087,7 @@ int test_min_tls_12() return expect_success(); } -int test_min_tls_13() +static int test_min_tls_13() { otlp::OtlpHttpExporterOptions opts; @@ -1120,7 +1122,7 @@ int test_min_tls_13() return expect_success(); } -int test_max_tls_unknown() +static int test_max_tls_unknown() { otlp::OtlpHttpExporterOptions opts; @@ -1150,7 +1152,7 @@ int test_max_tls_unknown() return expect_unknown_max_tls(); } -int test_max_tls_10() +static int test_max_tls_10() { otlp::OtlpHttpExporterOptions opts; @@ -1186,7 +1188,7 @@ int test_max_tls_10() return expect_unknown_max_tls(); } -int test_max_tls_11() +static int test_max_tls_11() { otlp::OtlpHttpExporterOptions opts; @@ -1222,7 +1224,7 @@ int test_max_tls_11() return expect_unknown_max_tls(); } -int test_max_tls_12() +static int test_max_tls_12() { otlp::OtlpHttpExporterOptions opts; @@ -1257,7 +1259,7 @@ int test_max_tls_12() return expect_success(); } -int test_max_tls_13() +static int test_max_tls_13() { otlp::OtlpHttpExporterOptions opts; @@ -1292,7 +1294,7 @@ int test_max_tls_13() return expect_success(); } -int test_range_tls_10() +static int test_range_tls_10() { otlp::OtlpHttpExporterOptions opts; @@ -1329,7 +1331,7 @@ int test_range_tls_10() return expect_unknown_min_tls(); } -int test_range_tls_11() +static int test_range_tls_11() { otlp::OtlpHttpExporterOptions opts; @@ -1366,7 +1368,7 @@ int test_range_tls_11() return expect_unknown_min_tls(); } -int test_range_tls_12() +static int test_range_tls_12() { otlp::OtlpHttpExporterOptions opts; @@ -1402,7 +1404,7 @@ int test_range_tls_12() return expect_success(); } -int test_range_tls_13() +static int test_range_tls_13() { otlp::OtlpHttpExporterOptions opts; @@ -1438,7 +1440,7 @@ int test_range_tls_13() return expect_success(); } -int test_range_tls_10_11() +static int test_range_tls_10_11() { otlp::OtlpHttpExporterOptions opts; @@ -1475,7 +1477,7 @@ int test_range_tls_10_11() return expect_unknown_min_tls(); } -int test_range_tls_10_12() +static int test_range_tls_10_12() { otlp::OtlpHttpExporterOptions opts; @@ -1511,7 +1513,7 @@ int test_range_tls_10_12() return expect_unknown_min_tls(); } -int test_range_tls_10_13() +static int test_range_tls_10_13() { otlp::OtlpHttpExporterOptions opts; @@ -1547,7 +1549,7 @@ int test_range_tls_10_13() return expect_unknown_min_tls(); } -int test_range_tls_11_10() +static int test_range_tls_11_10() { otlp::OtlpHttpExporterOptions opts; @@ -1579,7 +1581,7 @@ int test_range_tls_11_10() return expect_connection_failed(); } -int test_range_tls_11_12() +static int test_range_tls_11_12() { otlp::OtlpHttpExporterOptions opts; @@ -1615,7 +1617,7 @@ int test_range_tls_11_12() return expect_unknown_min_tls(); } -int test_range_tls_11_13() +static int test_range_tls_11_13() { otlp::OtlpHttpExporterOptions opts; @@ -1651,7 +1653,7 @@ int test_range_tls_11_13() return expect_unknown_min_tls(); } -int test_range_tls_12_10() +static int test_range_tls_12_10() { otlp::OtlpHttpExporterOptions opts; @@ -1683,7 +1685,7 @@ int test_range_tls_12_10() return expect_connection_failed(); } -int test_range_tls_12_11() +static int test_range_tls_12_11() { otlp::OtlpHttpExporterOptions opts; @@ -1715,7 +1717,7 @@ int test_range_tls_12_11() return expect_connection_failed(); } -int test_range_tls_12_13() +static int test_range_tls_12_13() { otlp::OtlpHttpExporterOptions opts; @@ -1751,7 +1753,7 @@ int test_range_tls_12_13() return expect_success(); } -int test_range_tls_13_10() +static int test_range_tls_13_10() { otlp::OtlpHttpExporterOptions opts; @@ -1783,7 +1785,7 @@ int test_range_tls_13_10() return expect_connection_failed(); } -int test_range_tls_13_11() +static int test_range_tls_13_11() { otlp::OtlpHttpExporterOptions opts; @@ -1815,7 +1817,7 @@ int test_range_tls_13_11() return expect_connection_failed(); } -int test_range_tls_13_12() +static int test_range_tls_13_12() { otlp::OtlpHttpExporterOptions opts; @@ -1847,7 +1849,7 @@ int test_range_tls_13_12() return expect_connection_failed(); } -int test_gzip_compression() +static int test_gzip_compression() { otlp::OtlpHttpExporterOptions opts; diff --git a/sdk/src/common/env_variables.cc b/sdk/src/common/env_variables.cc index b72933a802..296cef6306 100644 --- a/sdk/src/common/env_variables.cc +++ b/sdk/src/common/env_variables.cc @@ -26,7 +26,7 @@ namespace sdk namespace common { -bool GetRawEnvironmentVariable(const char *env_var_name, std::string &value) +static bool GetRawEnvironmentVariable(const char *env_var_name, std::string &value) { #if !defined(NO_GETENV) const char *endpoint_from_env = nullptr; diff --git a/sdk/src/metrics/aggregation/base2_exponential_histogram_aggregation.cc b/sdk/src/metrics/aggregation/base2_exponential_histogram_aggregation.cc index aaac9a0d0e..70d915bb04 100644 --- a/sdk/src/metrics/aggregation/base2_exponential_histogram_aggregation.cc +++ b/sdk/src/metrics/aggregation/base2_exponential_histogram_aggregation.cc @@ -218,9 +218,9 @@ void Base2ExponentialHistogramAggregation::Downscale(uint32_t by) noexcept // Merge A and B into a new circular buffer C. // Caller must ensure that A and B are used as buckets at the same scale. -AdaptingCircularBufferCounter MergeBuckets(size_t max_buckets, - const AdaptingCircularBufferCounter &A, - const AdaptingCircularBufferCounter &B) +static AdaptingCircularBufferCounter MergeBuckets(size_t max_buckets, + const AdaptingCircularBufferCounter &A, + const AdaptingCircularBufferCounter &B) { AdaptingCircularBufferCounter C = AdaptingCircularBufferCounter(max_buckets); C.Clear(); diff --git a/sdk/src/metrics/export/periodic_exporting_metric_reader_options.cc b/sdk/src/metrics/export/periodic_exporting_metric_reader_options.cc index 94dbed48f8..4b9f86d2a9 100644 --- a/sdk/src/metrics/export/periodic_exporting_metric_reader_options.cc +++ b/sdk/src/metrics/export/periodic_exporting_metric_reader_options.cc @@ -14,8 +14,8 @@ namespace sdk namespace metrics { -std::chrono::milliseconds GetEnvDuration(nostd::string_view env_var_name, - std::chrono::milliseconds default_value) +static std::chrono::milliseconds GetEnvDuration(nostd::string_view env_var_name, + std::chrono::milliseconds default_value) { std::chrono::system_clock::duration duration; if (common::GetDurationEnvironmentVariable(env_var_name.data(), duration)) diff --git a/sdk/test/common/circular_buffer_test.cc b/sdk/test/common/circular_buffer_test.cc index 64075d5a6e..6dc1b627cc 100644 --- a/sdk/test/common/circular_buffer_test.cc +++ b/sdk/test/common/circular_buffer_test.cc @@ -63,9 +63,9 @@ static void RunNumberProducers(CircularBuffer &buffer, } } -void RunNumberConsumer(CircularBuffer &buffer, - std::atomic &exit, - std::vector &numbers) +static void RunNumberConsumer(CircularBuffer &buffer, + std::atomic &exit, + std::vector &numbers) { while (true) { diff --git a/sdk/test/common/random_test.cc b/sdk/test/common/random_test.cc index 96cf24dd5c..e5711ef1a1 100644 --- a/sdk/test/common/random_test.cc +++ b/sdk/test/common/random_test.cc @@ -42,7 +42,7 @@ TEST(RandomTest, GenerateRandomBuffer) } } -void doSomethingOnce(std::atomic_uint *count) +static void doSomethingOnce(std::atomic_uint *count) { static std::atomic_flag flag; if (!flag.test_and_set()) diff --git a/sdk/test/metrics/instrument_descriptor_test.cc b/sdk/test/metrics/instrument_descriptor_test.cc index f17189355c..6e689a2db0 100644 --- a/sdk/test/metrics/instrument_descriptor_test.cc +++ b/sdk/test/metrics/instrument_descriptor_test.cc @@ -8,7 +8,7 @@ using namespace opentelemetry::sdk::metrics; -InstrumentDescriptor CreateInstrumentDescriptor( +static InstrumentDescriptor CreateInstrumentDescriptor( const std::string &name = "counter", const std::string &description = "description", const std::string &unit = "unit", diff --git a/sdk/test/metrics/sync_instruments_test.cc b/sdk/test/metrics/sync_instruments_test.cc index 0cff06a9ca..263441d38c 100644 --- a/sdk/test/metrics/sync_instruments_test.cc +++ b/sdk/test/metrics/sync_instruments_test.cc @@ -21,7 +21,7 @@ using namespace opentelemetry; using namespace opentelemetry::sdk::instrumentationscope; using namespace opentelemetry::sdk::metrics; -auto instrumentation_scope = InstrumentationScope::Create("opentelemetry-cpp", "0.1.0"); +static auto instrumentation_scope = InstrumentationScope::Create("opentelemetry-cpp", "0.1.0"); using M = std::map;