From e9174ade6373e32a0d4c9849371392845df24a7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Andr=C3=A9=20dos=20Santos=20Lopes?= Date: Thu, 23 Jul 2026 12:57:13 +0100 Subject: [PATCH 1/2] Place _dd.apm.enabled:0 in every span --- src/datadog/trace_segment.cpp | 15 ++++++++------- test/test_tracer.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 7 deletions(-) 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); From 02c4a48356eff11a754ba05e78c50f6b98aded10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Andr=C3=A9=20dos=20Santos=20Lopes?= Date: Wed, 5 Aug 2026 15:46:38 +0100 Subject: [PATCH 2/2] address review comments --- src/datadog/trace_segment.cpp | 5 ----- test/test_tracer.cpp | 34 ++++++++++++++++++++++++++++------ 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/datadog/trace_segment.cpp b/src/datadog/trace_segment.cpp index 15745edf..555f648c 100644 --- a/src/datadog/trace_segment.cpp +++ b/src/datadog/trace_segment.cpp @@ -332,11 +332,6 @@ void TraceSegment::span_finished() { 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_) { diff --git a/test/test_tracer.cpp b/test/test_tracer.cpp index 60a2b9a3..94c14b6f 100644 --- a/test/test_tracer.cpp +++ b/test/test_tracer.cpp @@ -2118,6 +2118,29 @@ TEST_TRACER("move semantics") { (void)tracer2; } +TEST_TRACER("APM tracing enabled") { + TracerConfig config; + config.service = "testsvc"; + config.name = "test.op"; + const std::shared_ptr collector = + std::make_shared(); + config.collector = collector; + config.logger = std::make_shared(); + config.tracing_enabled = true; + + Expected finalized_config = finalize_config(config); + REQUIRE(finalized_config); + Tracer tracer{*finalized_config}; + + tracer.create_span(); + + REQUIRE(collector->chunks.size() == 1); + REQUIRE(collector->chunks.front().size() == 1); + const SpanData& span = *collector->chunks.front().front(); + // tracing needs to be disabled for this tag to be set + CHECK(span.numeric_tags.count(tags::internal::apm_enabled) == 0); +} + TEST_TRACER("APM tracing disabled") { TracerConfig config; config.service = "testsvc"; @@ -2131,7 +2154,8 @@ TEST_TRACER("APM tracing disabled") { auto clock = [¤t_time]() { return current_time; }; SECTION("_dd.apm.enabled is added to every span") { - auto finalized_config = finalize_config(config, clock); + Expected finalized_config = + finalize_config(config, clock); REQUIRE(finalized_config); Tracer tracer{*finalized_config}; @@ -2139,11 +2163,9 @@ TEST_TRACER("APM tracing disabled") { 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; + Span root = tracer.create_span(); + root.create_child(); + root.create_child(service_entry_config); } REQUIRE(collector->chunks.size() == 1);