Skip to content

Commit

Permalink
Move _dd.apm.enabled tag in Tracing Rack Middleware instead of AppS…
Browse files Browse the repository at this point in the history
…ec middleware
  • Loading branch information
vpellan committed Nov 21, 2024
1 parent 722f487 commit b14dd54
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 4 deletions.
2 changes: 0 additions & 2 deletions lib/datadog/appsec/contrib/rack/request_middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 0 additions & 1 deletion lib/datadog/appsec/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions lib/datadog/tracing/contrib/rack/middlewares.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions lib/datadog/tracing/metadata/ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion sig/datadog/appsec/ext.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module Datadog
SCOPE_KEY: String

TAG_APPSEC_ENABLED: String
TAG_APM_ENABLED: String
TAG_DISTRIBUTED_APPSEC_EVENT: String
end
end
Expand Down
2 changes: 2 additions & 0 deletions sig/datadog/tracing/metadata/ext.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b14dd54

Please sign in to comment.