Skip to content

Commit

Permalink
fix opentelemetry file name and constant names
Browse files Browse the repository at this point in the history
  • Loading branch information
GustavoCaso committed Oct 5, 2023
1 parent f34efe7 commit 1048d8f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 52 deletions.
1 change: 0 additions & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ Naming/FileName:
- 'bin/**/*'
- 'lib/datadog/appsec/autoload.rb'
- 'lib/datadog/core/backport.rb'
- 'lib/datadog/opentelemetry/api/trace/span.rb'
- 'lib/datadog/opentracer.rb'
- 'lib/datadog/profiling/load_native_extension.rb'
- 'lib/datadog/profiling/preload.rb'
Expand Down
12 changes: 7 additions & 5 deletions lib/datadog/opentelemetry/api/trace/span.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

module Datadog
module OpenTelemetry
module Trace
# Stores associated Datadog entities to the OpenTelemetry Span.
module Span
attr_accessor :datadog_trace, :datadog_span
module API
module Trace
# Stores associated Datadog entities to the OpenTelemetry Span.
module Span
attr_accessor :datadog_trace, :datadog_span

::OpenTelemetry::Trace::Span.prepend(self)
::OpenTelemetry::Trace::Span.prepend(self)
end
end
end
end
Expand Down
95 changes: 49 additions & 46 deletions lib/datadog/opentelemetry/sdk/trace/span.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,68 @@

module Datadog
module OpenTelemetry
module Trace
# Stores associated Datadog entities to the OpenTelemetry Span.
module Span
# Attributes are equivalent to span tags and metrics.
def set_attribute(key, value)
res = super
# Attributes can get dropped or their values truncated by `super`
datadog_set_attribute(key)
res
end
module SDK
module Trace
# Stores associated Datadog entities to the OpenTelemetry Span.
module Span
# Attributes are equivalent to span tags and metrics.
def set_attribute(key, value)
res = super
# Attributes can get dropped or their values truncated by `super`
datadog_set_attribute(key)
res
end

# `alias` performed to match {OpenTelemetry::SDK::Trace::Span} aliasing upstream
alias []= set_attribute
# `alias` performed to match {OpenTelemetry::SDK::Trace::Span} aliasing upstream
alias []= set_attribute

# Attributes are equivalent to span tags and metrics.
def add_attributes(attributes)
res = super
# Attributes can get dropped or their values truncated by `super`
attributes.each { |key, _| datadog_set_attribute(key) }
res
end
# Attributes are equivalent to span tags and metrics.
def add_attributes(attributes)
res = super
# Attributes can get dropped or their values truncated by `super`
attributes.each { |key, _| datadog_set_attribute(key) }
res
end

# Captures changes to span error state.
def status=(s)
super
# Captures changes to span error state.
def status=(s)
super

return unless status # Return if status are currently disabled by OpenTelemetry.
return unless (span = datadog_span)
return unless status # Return if status are currently disabled by OpenTelemetry.
return unless (span = datadog_span)

# Status code can only change into an error state.
# Other change operations should be ignored.
span.set_error(status.description) if status && status.code == ::OpenTelemetry::Trace::Status::ERROR
end
# Status code can only change into an error state.
# Other change operations should be ignored.
span.set_error(status.description) if status && status.code == ::OpenTelemetry::Trace::Status::ERROR
end

private
private

def datadog_set_attribute(key)
return unless defined?(@attributes) && @attributes # Return if attributes are currently disabled by OpenTelemetry.
return unless (span = datadog_span)
def datadog_set_attribute(key)
# Return if attributes are currently disabled by OpenTelemetry.
return unless defined?(@attributes) && @attributes
return unless (span = datadog_span)

# DEV: Accesses `@attributes` directly, since using `#attributes`
# DEV: clones the hash, causing unnecessary overhead.
if @attributes.key?(key)
value = @attributes[key]
span.set_tag(key, value)
# DEV: Accesses `@attributes` directly, since using `#attributes`
# DEV: clones the hash, causing unnecessary overhead.
if @attributes.key?(key)
value = @attributes[key]
span.set_tag(key, value)

span.service = value if key == 'service.name'
else
span.clear_tag(key)
span.service = value if key == 'service.name'
else
span.clear_tag(key)

if key == 'service.name'
# By removing the service name, we set it to the fallback default,
# effectively removing the `service` attribute from OpenTelemetry's perspective.
span.service = Datadog.send(:components).tracer.default_service
if key == 'service.name'
# By removing the service name, we set it to the fallback default,
# effectively removing the `service` attribute from OpenTelemetry's perspective.
span.service = Datadog.send(:components).tracer.default_service
end
end
end
end

::OpenTelemetry::SDK::Trace::Span.prepend(self)
::OpenTelemetry::SDK::Trace::Span.prepend(self)
end
end
end
end
Expand Down

0 comments on commit 1048d8f

Please sign in to comment.