1+ // Copyright The OpenTelemetry Authors
2+ // SPDX-License-Identifier: Apache-2.0
3+
4+ #include < gtest/gtest.h>
5+ #include < opentelemetry/sdk/trace/tracer_config.h>
6+
7+ namespace trace_sdk = opentelemetry::sdk::trace;
8+ namespace instrumentation_scope = opentelemetry::sdk::instrumentationscope;
9+
10+ /* * Tests to verify the basic behavior of trace_sdk::TracerConfig */
11+
12+ TEST (TracerConfig, CheckDisabledWorksAsExpected)
13+ {
14+ trace_sdk::TracerConfig disabled_config = trace_sdk::TracerConfig::Disabled ();
15+ ASSERT_FALSE (disabled_config.IsEnabled ());
16+ }
17+
18+ TEST (TracerConfig, CheckEnabledWorksAsExpected)
19+ {
20+ trace_sdk::TracerConfig enabled_config = trace_sdk::TracerConfig::Enabled ();
21+ ASSERT_TRUE (enabled_config.IsEnabled ());
22+ }
23+
24+ TEST (TracerConfig, CheckDefaultConfigWorksAccToSpec)
25+ {
26+ trace_sdk::TracerConfig default_config = trace_sdk::TracerConfig::Default ();
27+ ASSERT_TRUE (default_config.IsEnabled ());
28+ }
29+
30+ /* * Tests to verify the behavior of trace_sdk::TracerConfig::DefaultConfigurator */
31+
32+ std::pair<opentelemetry::nostd::string_view, opentelemetry::common::AttributeValue> attr1 = {
33+ " accept_single_attr" , true };
34+ std::pair<opentelemetry::nostd::string_view, opentelemetry::common::AttributeValue> attr2 = {
35+ " accept_second_attr" , " some other attr" };
36+ std::pair<opentelemetry::nostd::string_view, opentelemetry::common::AttributeValue> attr3 = {
37+ " accept_third_attr" , 3 };
38+
39+ const instrumentation_scope::InstrumentationScope instrumentation_scopes[] = {
40+ *instrumentation_scope::InstrumentationScope::Create (" test_scope_1" ).get (),
41+ *instrumentation_scope::InstrumentationScope::Create (" test_scope_2" , " 1.0" ).get (),
42+ *instrumentation_scope::InstrumentationScope::Create (" test_scope_3" , " 0" , " https://opentelemetry.io/schemas/v1.18.0" ).get (),
43+ *instrumentation_scope::InstrumentationScope::Create (" test_scope_3" , " 0" , " https://opentelemetry.io/schemas/v1.18.0" , {attr1})
44+ .get (),
45+ *instrumentation_scope::InstrumentationScope::Create (" test_scope_4" , " 0" , " https://opentelemetry.io/schemas/v1.18.0" , {attr1, attr2, attr3})
46+ .get (),
47+ };
48+
49+ // Test fixture for VerifyDefaultConfiguratorBehavior
50+ class DefaultTracerConfiguratorTestFixture : public ::testing::TestWithParam<instrumentation_scope::InstrumentationScope>
51+ {};
52+
53+ // verifies that the default configurator always returns the default tracer config
54+ TEST_P (DefaultTracerConfiguratorTestFixture, VerifyDefaultConfiguratorBehavior)
55+ {
56+ const instrumentation_scope::InstrumentationScope& scope = GetParam ();
57+ trace_sdk::TracerConfigurator default_configurator = trace_sdk::TracerConfig::DefaultConfigurator ();
58+
59+ ASSERT_EQ (default_configurator (scope), trace_sdk::TracerConfig::Default ());
60+ }
61+
62+ INSTANTIATE_TEST_SUITE_P (InstrumentationScopes, DefaultTracerConfiguratorTestFixture, ::testing::ValuesIn(instrumentation_scopes));
0 commit comments