File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44#include < datadog/tags.h>
55#include < datadog/tracer.h>
66
7+ #include < algorithm>
78#include < cstddef>
89#include < ostream>
910#include < string>
@@ -271,6 +272,24 @@ TEST_CASE("span rule sample rate") {
271272 config.trace_sampler .sample_rate = 0.0 ; // drop the trace
272273 auto finalized = finalize_config (config);
273274 REQUIRE (finalized);
275+
276+ // metadata should be populated right - check the full JSON representation
277+ auto expected_rules = " [{\" name\" :\" *\" ,\" resource\" :\" *\" ,\" sample_rate\" :" +
278+ to_string (test_case.span_rule_rate , 1 ) +
279+ " ,\" service\" :\" testsvc\" ,\" tags\" :{}}]" ;
280+ REQUIRE (finalized->metadata [ConfigName::SPAN_SAMPLING_RULES ].value ==
281+ expected_rules);
282+
283+ auto tracing_product = finalized->telemetry .products [0 ];
284+
285+ // Verify the tracing product has the span sampling rules in telemetry configs
286+ const auto & span_rules_configs =
287+ tracing_product.configurations .at (ConfigName::SPAN_SAMPLING_RULES );
288+ REQUIRE (span_rules_configs.size () ==
289+ 1 ); // Only CODE origin since rules were set in code
290+ REQUIRE (span_rules_configs[0 ].value == expected_rules);
291+ REQUIRE (span_rules_configs[0 ].origin == ConfigMetadata::Origin::CODE );
292+
274293 Tracer tracer{*finalized};
275294 {
276295 auto span = tracer.create_span ();
Original file line number Diff line number Diff line change 55#include < datadog/tracer.h>
66#include < datadog/tracer_config.h>
77
8+ #include < algorithm>
89#include < chrono>
910#include < limits>
1011#include < map>
1112#include < ostream>
1213
14+ #include " catch.hpp"
1315#include " mocks/collectors.h"
1416#include " null_logger.h"
1517#include " test.h"
@@ -73,6 +75,21 @@ TEST_CASE("trace sampling rule sample rate") {
7375
7476 auto finalized = finalize_config (config);
7577 REQUIRE (finalized);
78+
79+ // metadata should be populated right
80+ REQUIRE (finalized->metadata [ConfigName::TRACE_SAMPLING_RATE ].value ==
81+ to_string (test_case.sample_rate , 1 ));
82+
83+ auto tracing_product = finalized->telemetry .products [0 ];
84+ // Verify the tracing product has the telemetry configs
85+ const auto & rate_configs =
86+ tracing_product.configurations .at (ConfigName::TRACE_SAMPLING_RATE );
87+ REQUIRE (rate_configs.size () == 2 );
88+ REQUIRE (rate_configs[0 ].value == to_string (1 , 1 ));
89+ REQUIRE (rate_configs[0 ].origin == ConfigMetadata::Origin::DEFAULT );
90+ REQUIRE (rate_configs[1 ].value == to_string (test_case.sample_rate , 1 ));
91+ REQUIRE (rate_configs[1 ].origin == ConfigMetadata::Origin::CODE );
92+
7693 Tracer tracer{*finalized};
7794
7895 for (std::size_t i = 0 ; i < num_iterations; ++i) {
You can’t perform that action at this time.
0 commit comments