diff --git a/src/datadog/trace_segment.cpp b/src/datadog/trace_segment.cpp index c2eb639b..15745edf 100644 --- a/src/datadog/trace_segment.cpp +++ b/src/datadog/trace_segment.cpp @@ -328,16 +328,17 @@ void TraceSegment::span_finished() { } } - // RFC seems to only mandate that this be set if the trace is kept. - // However, system-tests expect this to always be set. - // Add it all the time; can't hurt - if (!tracing_enabled_) { - local_root.numeric_tags[tags::internal::apm_enabled] = 0; - } - // Some tags are repeated on all spans. for (const auto& span_ptr : spans_) { SpanData& span = *span_ptr; + if (!tracing_enabled_) { + // RFC seems to only mandate that this be set if the trace is kept. + // However, system-tests expect this to always be set. + // Add it all the time; can't hurt + // Following incident-57980, go beyond the RFC and add it to every span so + // that every trace chunk is marked. + span.numeric_tags[tags::internal::apm_enabled] = 0; + } if (origin_) { span.tags[tags::internal::origin] = *origin_; } diff --git a/test/test_tracer.cpp b/test/test_tracer.cpp index d41d51b7..60a2b9a3 100644 --- a/test/test_tracer.cpp +++ b/test/test_tracer.cpp @@ -2130,6 +2130,30 @@ TEST_TRACER("APM tracing disabled") { TimePoint current_time = default_clock(); auto clock = [¤t_time]() { return current_time; }; + SECTION("_dd.apm.enabled is added to every span") { + auto finalized_config = finalize_config(config, clock); + REQUIRE(finalized_config); + Tracer tracer{*finalized_config}; + + SpanConfig service_entry_config; + service_entry_config.service = "child-service"; + + { + auto root = tracer.create_span(); + auto child = root.create_child(); + auto service_entry = root.create_child(service_entry_config); + (void)child; + (void)service_entry; + } + + REQUIRE(collector->chunks.size() == 1); + const auto& chunk = collector->chunks.front(); + REQUIRE(chunk.size() == 3); + for (const auto& span : chunk) { + CHECK(span->numeric_tags.at(tags::internal::apm_enabled) == 0); + } + } + SECTION("sampling behaviour") { SECTION("span with _dd.p.ts is kept") { auto finalized_config = finalize_config(config, clock);