66#include < datadog/tracer_config.h>
77
88#include < cmath>
9+ #include < cstddef>
910#include < cstdlib>
1011#include < filesystem>
1112#include < fstream>
@@ -985,6 +986,20 @@ TEST_CASE("TracerConfig propagation styles") {
985986 TracerConfig config;
986987 config.defaults .service = " testsvc" ;
987988
989+ SECTION (" DD_TRACE_PROPAGATION_STYLE overrides defaults" ) {
990+ const EnvGuard guard{" DD_TRACE_PROPAGATION_STYLE" , " B3" };
991+ auto finalized = finalize_config (config);
992+ REQUIRE (finalized);
993+
994+ REQUIRE (!finalized->injection_styles .datadog );
995+ REQUIRE (finalized->injection_styles .b3 );
996+ REQUIRE (!finalized->injection_styles .none );
997+
998+ REQUIRE (!finalized->extraction_styles .datadog );
999+ REQUIRE (finalized->extraction_styles .b3 );
1000+ REQUIRE (!finalized->extraction_styles .none );
1001+ }
1002+
9881003 SECTION (" injection_styles" ) {
9891004 SECTION (" defaults to just Datadog" ) {
9901005 auto finalized = finalize_config (config);
@@ -1001,9 +1016,31 @@ TEST_CASE("TracerConfig propagation styles") {
10011016 REQUIRE (finalized.error ().code == Error::MISSING_SPAN_INJECTION_STYLE);
10021017 }
10031018
1004- SECTION (" DD_PROPAGATION_STYLE_INJECT " ) {
1019+ SECTION (" DD_TRACE_PROPAGATION_STYLE_INJECT " ) {
10051020 SECTION (" overrides injection_styles" ) {
1006- const EnvGuard guard{" DD_PROPAGATION_STYLE_INJECT" , " B3" };
1021+ const EnvGuard guard{" DD_TRACE_PROPAGATION_STYLE_INJECT" , " B3" };
1022+ auto finalized = finalize_config (config);
1023+ REQUIRE (finalized);
1024+ REQUIRE (!finalized->injection_styles .datadog );
1025+ REQUIRE (finalized->injection_styles .b3 );
1026+ REQUIRE (!finalized->injection_styles .none );
1027+ }
1028+
1029+ SECTION (" overrides DD_PROPAGATION_STYLE_INJECT" ) {
1030+ const EnvGuard guard1{" DD_TRACE_PROPAGATION_STYLE_INJECT" , " B3" };
1031+ const EnvGuard guard2{" DD_PROPAGATION_STYLE_INJECT" , " Datadog" };
1032+ config.logger = std::make_shared<MockLogger>(); // suppress warning
1033+ auto finalized = finalize_config (config);
1034+ REQUIRE (finalized);
1035+ REQUIRE (!finalized->injection_styles .datadog );
1036+ REQUIRE (finalized->injection_styles .b3 );
1037+ REQUIRE (!finalized->injection_styles .none );
1038+ }
1039+
1040+ SECTION (" overrides DD_TRACE_PROPAGATION_STYLE" ) {
1041+ const EnvGuard guard1{" DD_TRACE_PROPAGATION_STYLE_INJECT" , " B3" };
1042+ const EnvGuard guard2{" DD_TRACE_PROPAGATION_STYLE" , " Datadog" };
1043+ config.logger = std::make_shared<MockLogger>(); // suppress warning
10071044 auto finalized = finalize_config (config);
10081045 REQUIRE (finalized);
10091046 REQUIRE (!finalized->injection_styles .datadog );
@@ -1045,7 +1082,7 @@ TEST_CASE("TracerConfig propagation styles") {
10451082 CAPTURE (test_case.line );
10461083 CAPTURE (test_case.env_value );
10471084
1048- const EnvGuard guard{" DD_PROPAGATION_STYLE_INJECT " ,
1085+ const EnvGuard guard{" DD_TRACE_PROPAGATION_STYLE_INJECT " ,
10491086 test_case.env_value };
10501087 auto finalized = finalize_config (config);
10511088 if (test_case.expected_error ) {
@@ -1083,9 +1120,31 @@ TEST_CASE("TracerConfig propagation styles") {
10831120 REQUIRE (finalized.error ().code == Error::MISSING_SPAN_EXTRACTION_STYLE);
10841121 }
10851122
1086- SECTION (" DD_PROPAGATION_STYLE_EXTRACT " ) {
1123+ SECTION (" DD_TRACE_PROPAGATION_STYLE_EXTRACT " ) {
10871124 SECTION (" overrides extraction_styles" ) {
1088- const EnvGuard guard{" DD_PROPAGATION_STYLE_EXTRACT" , " B3" };
1125+ const EnvGuard guard{" DD_TRACE_PROPAGATION_STYLE_EXTRACT" , " B3" };
1126+ auto finalized = finalize_config (config);
1127+ REQUIRE (finalized);
1128+ REQUIRE (!finalized->extraction_styles .datadog );
1129+ REQUIRE (finalized->extraction_styles .b3 );
1130+ REQUIRE (!finalized->extraction_styles .none );
1131+ }
1132+
1133+ SECTION (" overrides DD_PROPAGATION_STYLE_EXTRACT" ) {
1134+ const EnvGuard guard1{" DD_TRACE_PROPAGATION_STYLE_EXTRACT" , " B3" };
1135+ const EnvGuard guard2{" DD_PROPAGATION_STYLE_EXTRACT" , " Datadog" };
1136+ config.logger = std::make_shared<MockLogger>(); // suppress warning
1137+ auto finalized = finalize_config (config);
1138+ REQUIRE (finalized);
1139+ REQUIRE (!finalized->extraction_styles .datadog );
1140+ REQUIRE (finalized->extraction_styles .b3 );
1141+ REQUIRE (!finalized->extraction_styles .none );
1142+ }
1143+
1144+ SECTION (" overrides DD_TRACE_PROPAGATION_STYLE" ) {
1145+ const EnvGuard guard1{" DD_TRACE_PROPAGATION_STYLE_EXTRACT" , " B3" };
1146+ const EnvGuard guard2{" DD_TRACE_PROPAGATION_STYLE" , " Datadog" };
1147+ config.logger = std::make_shared<MockLogger>(); // suppress warning
10891148 auto finalized = finalize_config (config);
10901149 REQUIRE (finalized);
10911150 REQUIRE (!finalized->extraction_styles .datadog );
@@ -1104,4 +1163,53 @@ TEST_CASE("TracerConfig propagation styles") {
11041163 }
11051164 }
11061165 }
1166+
1167+ SECTION (" warn if one env var overrides another" ) {
1168+ const auto logger = std::make_shared<MockLogger>();
1169+ config.logger = logger;
1170+ const auto ts = " DD_TRACE_PROPAGATION_STYLE" ;
1171+ const auto tse = " DD_TRACE_PROPAGATION_STYLE_EXTRACT" ;
1172+ const auto se = " DD_PROPAGATION_STYLE_EXTRACT" ;
1173+ const auto tsi = " DD_TRACE_PROPAGATION_STYLE_INJECT" ;
1174+ const auto si = " DD_PROPAGATION_STYLE_INJECT" ;
1175+ const char * const vars[] = {ts, tse, se, tsi, si};
1176+ constexpr auto n = sizeof (vars) / sizeof (vars[0 ]);
1177+ // clang-format off
1178+ const bool x = false ; // ignored values
1179+ const bool expect_warning[n][n] = {
1180+ // ts tse se tsi si
1181+ // --- --- --- --- ---
1182+ /* ts */ { x, true , true , true , true },
1183+
1184+ /* tse */ { x, x, true , false , false },
1185+
1186+ /* se */ { x, x, x, false , false },
1187+
1188+ /* tsi */ { x, x, x, x, true },
1189+
1190+ /* si */ { x, x, x, x, x },
1191+ };
1192+ // clang-format on
1193+ for (std::size_t i = 0 ; i < n; ++i) {
1194+ for (std::size_t j = i + 1 ; j < n; ++j) {
1195+ CAPTURE (i);
1196+ CAPTURE (vars[i]);
1197+ CAPTURE (j);
1198+ CAPTURE (vars[j]);
1199+ CAPTURE (expect_warning[i][j]);
1200+ const EnvGuard guard1{vars[i], " B3" };
1201+ const EnvGuard guard2{vars[j], " B3" };
1202+ const auto finalized_config = finalize_config (config);
1203+ REQUIRE (finalized_config);
1204+ if (expect_warning[i][j]) {
1205+ REQUIRE (logger->error_count () == 1 );
1206+ REQUIRE (logger->first_error ().code ==
1207+ Error::MULTIPLE_PROPAGATION_STYLE_ENVIRONMENT_VARIABLES);
1208+ } else {
1209+ REQUIRE (logger->error_count () == 0 );
1210+ }
1211+ logger->entries .clear ();
1212+ }
1213+ }
1214+ }
11071215}
0 commit comments