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

HTTP propagator: Better handling of invalid data #3730

Merged
merged 2 commits into from
Jun 26, 2024

Conversation

marcotc
Copy link
Member

@marcotc marcotc commented Jun 21, 2024

This PR improve the handling of trace propagation when the parent span_id is not present. In such case, the trace is still propagated without a span_id, which is a valid trace propagation payload.
The distributed tracing will have the correct correlation between the current service with the downstream service, but the downstream service parenting will likely be incorrect. This is still more desirable than completely losing trace correlation.

Also in this PR, there is the better handling of the scenario when a TraceDigest is not populated with a trace_id, which cannot happen in a digest created by the tracer, but can happen with users are manually testing the public method Datadog::Tracing::Contrib::HTTP.inject(digest, env).
In such cases, we were printing an error message, as this was an unhandled case that raised a legitimate Ruby exception:

[2024-06-06T10:47:09.334345 #42] ERROR -- ddtrace: [ddtrace] (/usr/src/app/vendor/bundle/ruby/3.3.0/gems/ddtrace-1.19.0/lib/datadog/tracing/distributed/propagation.rb:65:in `rescue in block in inject!') Error injecting distributed trace data. Cause: can't convert nil into Integer Location: /usr/src/app/vendor/bundle/ruby/3.3.0/gems/ddtrace-1.19.0/lib/datadog/tracing/distributed/trace_context.rb:124:in `format'

This is now handled early in code, and logged as a debug message.

@marcotc marcotc self-assigned this Jun 21, 2024
@marcotc marcotc requested a review from a team as a code owner June 21, 2024 21:20
Signed-off-by: Marco Costa <marco.costa@datadoghq.com>
@marcotc marcotc enabled auto-merge June 26, 2024 18:52
@marcotc marcotc merged commit 5c779a0 into master Jun 26, 2024
164 of 165 checks passed
@marcotc marcotc deleted the trace_inject_resilient branch June 26, 2024 19:11
@github-actions github-actions bot added this to the 2.2.0 milestone Jun 26, 2024
@TonyCTHsu TonyCTHsu mentioned this pull request Jul 11, 2024
Copy link

@bernardobarreto bernardobarreto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants