From b14dd542a8e220070e218f9b86ece291c6f8df5a Mon Sep 17 00:00:00 2001 From: Victor Pellan Date: Thu, 21 Nov 2024 16:16:22 +0100 Subject: [PATCH] Move `_dd.apm.enabled` tag in Tracing Rack Middleware instead of AppSec middleware --- lib/datadog/appsec/contrib/rack/request_middleware.rb | 2 -- lib/datadog/appsec/ext.rb | 1 - lib/datadog/tracing/contrib/rack/middlewares.rb | 5 +++++ lib/datadog/tracing/metadata/ext.rb | 4 ++++ sig/datadog/appsec/ext.rbs | 1 - sig/datadog/tracing/metadata/ext.rbs | 2 ++ 6 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/datadog/appsec/contrib/rack/request_middleware.rb b/lib/datadog/appsec/contrib/rack/request_middleware.rb index cbb232c00e3..bd27505c4da 100644 --- a/lib/datadog/appsec/contrib/rack/request_middleware.rb +++ b/lib/datadog/appsec/contrib/rack/request_middleware.rb @@ -151,8 +151,6 @@ def add_appsec_tags(processor, scope) return unless trace && span span.set_metric(Datadog::AppSec::Ext::TAG_APPSEC_ENABLED, 1) - # We add this tag when ASM standalone is enabled to make sure we don't bill APM - span.set_metric(Datadog::AppSec::Ext::TAG_APM_ENABLED, 0) if Datadog.configuration.appsec.standalone.enabled span.set_tag('_dd.runtime_family', 'ruby') span.set_tag('_dd.appsec.waf.version', Datadog::AppSec::WAF::VERSION::BASE_STRING) diff --git a/lib/datadog/appsec/ext.rb b/lib/datadog/appsec/ext.rb index 30c21b7d240..0f8dddd446f 100644 --- a/lib/datadog/appsec/ext.rb +++ b/lib/datadog/appsec/ext.rb @@ -7,7 +7,6 @@ module Ext SCOPE_KEY = 'datadog.appsec.scope' TAG_APPSEC_ENABLED = '_dd.appsec.enabled' - TAG_APM_ENABLED = '_dd.apm.enabled' TAG_DISTRIBUTED_APPSEC_EVENT = '_dd.p.appsec' end end diff --git a/lib/datadog/tracing/contrib/rack/middlewares.rb b/lib/datadog/tracing/contrib/rack/middlewares.rb index fc2662c95ca..e4357dbc0e4 100644 --- a/lib/datadog/tracing/contrib/rack/middlewares.rb +++ b/lib/datadog/tracing/contrib/rack/middlewares.rb @@ -134,6 +134,11 @@ def set_request_tags!(trace, request_span, env, status, headers, response, origi # Otherwise, the getter method would delegate to its root span trace.resource = request_span.resource unless trace.resource_override? + # We add this metric when ASM standalone is enabled to make sure we don't bill APM + if Datadog.configuration.appsec.standalone.enabled + request_span.set_metric(Tracing::Metadata::Ext::TAG_APM_ENABLED, 0) + end + request_span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT) request_span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_REQUEST) request_span.set_tag(Tracing::Metadata::Ext::TAG_KIND, Tracing::Metadata::Ext::SpanKind::TAG_SERVER) diff --git a/lib/datadog/tracing/metadata/ext.rb b/lib/datadog/tracing/metadata/ext.rb index 95cf3d4e7f0..a1cffa4f725 100644 --- a/lib/datadog/tracing/metadata/ext.rb +++ b/lib/datadog/tracing/metadata/ext.rb @@ -31,6 +31,10 @@ module Ext # See Datadog-internal "RFC: Identifying which spans have profiling enabled " for details TAG_PROFILING_ENABLED = '_dd.profiling.enabled' + # Set to '0' if Standalone AppSec is enabled, not present otherwise. + # Although this tag is only used by Standalone AppSec for now, it acts on APM and belongs in this file + TAG_APM_ENABLED = '_dd.apm.enabled' + # Defines constants for trace analytics # @public_api module Analytics diff --git a/sig/datadog/appsec/ext.rbs b/sig/datadog/appsec/ext.rbs index 2ac545ba1d3..94021af2f29 100644 --- a/sig/datadog/appsec/ext.rbs +++ b/sig/datadog/appsec/ext.rbs @@ -5,7 +5,6 @@ module Datadog SCOPE_KEY: String TAG_APPSEC_ENABLED: String - TAG_APM_ENABLED: String TAG_DISTRIBUTED_APPSEC_EVENT: String end end diff --git a/sig/datadog/tracing/metadata/ext.rbs b/sig/datadog/tracing/metadata/ext.rbs index 9820be2b123..d347c7abb48 100644 --- a/sig/datadog/tracing/metadata/ext.rbs +++ b/sig/datadog/tracing/metadata/ext.rbs @@ -8,6 +8,8 @@ module Datadog TAG_PEER_SERVICE: ::String TAG_KIND: ::String TAG_TOP_LEVEL: ::String + TAG_PROFILING_ENABLED: ::String + TAG_APM_ENABLED: ::String module Analytics DEFAULT_SAMPLE_RATE: ::Float