Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenTelemetry:Fix attribute merge with Datadog tags #3651

Merged
merged 1 commit into from
May 16, 2024
Merged

Conversation

marcotc
Copy link
Member

@marcotc marcotc commented May 15, 2024

What does this PR do?
This PR fixes an issue with the tracing OpenTelemetry integration where OpenTelemetry span attributes were processed and converted to Datadog span tags, but not correctly converted back into a Hash object; they were left as an Array of key/value pairs.
Because an Array of key/value pairs is not what Tracing.trace(tags:) expects, this should have failed much earlier. But it actually has a chance of successfully setting span tags in the scenario that:

  1. There are no global DD_TAGS. In this case, we don't need to merge the existing tag array with the provided Array of key/value pairs.
    tags || @tags.dup
  2. set_tags iterates over the provided tags in a way that works for both Hashes and Arrays of key/value pairs:
    hash.each { |k, v| set_tag(k, v) }

This means that unlessDD_TAGS (or the equivalent c.tags = ...) was set, everything worked as expected.

Motivation:
To fix this error:

lib/datadog/tracing/tracer.rb:429:in `merge': no implicit conversion of Array into Hash (TypeError)	
lib/datadog/tracing/tracer.rb:429:in `resolve_tags'	
lib/datadog/tracing/tracer.rb:404:in `start_span'	
lib/datadog/tracing/tracer.rb:176:in `trace'	
lib/datadog/tracing.rb:18:in `trace'	
lib/datadog/opentelemetry/sdk/span_processor.rb:85:in `start_datadog_span'

How to test the change?
We have unit tests for this change.

Unsure? Have a question? Request a review!

@marcotc marcotc self-assigned this May 15, 2024
@marcotc marcotc requested a review from a team as a code owner May 15, 2024 19:49
Signed-off-by: Marco Costa <marco.costa@datadoghq.com>
@TonyCTHsu TonyCTHsu added this to the 2.0.0 milestone May 16, 2024
@marcotc marcotc merged commit cfe3b44 into master May 16, 2024
166 checks passed
@marcotc marcotc deleted the fix-otel-tags branch May 16, 2024 17:56
@TonyCTHsu TonyCTHsu mentioned this pull request Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants