Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
marcotc committed Nov 17, 2023
1 parent d2bccd9 commit ab5bb98
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/datadog/opentelemetry/sdk/span_processor.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require_relative 'trace/span'

module Datadog
module OpenTelemetry
module SDK
Expand Down Expand Up @@ -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

Expand Down
9 changes: 7 additions & 2 deletions lib/datadog/opentelemetry/sdk/trace/span.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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'
Expand All @@ -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
Expand Down

0 comments on commit ab5bb98

Please sign in to comment.