diff --git a/lib/datadog/opentelemetry/sdk/span_processor.rb b/lib/datadog/opentelemetry/sdk/span_processor.rb index 48f6f2b7b55..d0477dca159 100644 --- a/lib/datadog/opentelemetry/sdk/span_processor.rb +++ b/lib/datadog/opentelemetry/sdk/span_processor.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require_relative 'trace/span' + module Datadog module OpenTelemetry module SDK @@ -103,6 +105,8 @@ def span_arguments(span, attributes) kwargs[:service] = attributes['service.name'] if attributes.key?('service.name') kwargs[:type] = attributes['span.type'] if attributes.key?('span.type') + attributes.reject! { |key, _| OpenTelemetry::Trace::Span::DATADOG_SPAN_ATTRIBUTE_OVERRIDES.include?(key) } + [name, kwargs] end diff --git a/lib/datadog/opentelemetry/sdk/trace/span.rb b/lib/datadog/opentelemetry/sdk/trace/span.rb index 06fe1ff241f..523ea69239f 100644 --- a/lib/datadog/opentelemetry/sdk/trace/span.rb +++ b/lib/datadog/opentelemetry/sdk/trace/span.rb @@ -47,9 +47,11 @@ def datadog_set_attribute(key) # DEV: clones the hash, causing unnecessary overhead. if @attributes.key?(key) value = @attributes[key] - span.set_tag(key, value) - override_datadog_values(span, key, value) + + # When an attribute is used to override a Datadog Span property, + # it should NOT be set as a Datadog Span tag. + span.set_tag(key, value) unless DATADOG_SPAN_ATTRIBUTE_OVERRIDES.include?(key) else span.clear_tag(key) @@ -62,6 +64,7 @@ def datadog_set_attribute(key) end # Some special attributes can override Datadog Span fields beyond tags and metrics. + # @return [Boolean] true if the key is a Datadog Span override attribute, false otherwise def override_datadog_values(span, key, value) span.name = value if key == 'operation.name' span.resource = value if key == 'resource.name' @@ -70,6 +73,8 @@ def override_datadog_values(span, key, value) Datadog::Tracing::Analytics.set_sample_rate(span, value == 'true' ? 1 : 0) if key == 'analytics.event' end + DATADOG_SPAN_ATTRIBUTE_OVERRIDES = ['analytics.event', 'operation.name', 'resource.name', 'service.name', 'span.type'].freeze + ::OpenTelemetry::SDK::Trace::Span.prepend(self) end end