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

Propagation:Ensure W3C tracestate is always propagated #3255

Merged
merged 3 commits into from
Nov 15, 2023

Conversation

marcotc
Copy link
Member

@marcotc marcotc commented Nov 10, 2023

What does this PR do?

This PR ensures that the tracestate header received, even if not part of the first valid propagation style, is still propagated downstream. This respects the spec for tracestate, which states:

Vendors receiving a tracestate request header MUST send it to outgoing requests.

This is only an issue when W3C extraction style is proceeded by another style. And this is currently the default (Datadog,tracecontext).
Now with this change, when Datadog headers match, we will now continue searching for tracecontext headers to enrich the downstream propagation context.

Additional Notes:

This PR also introduces the DD_TRACE_PROPAGATION_EXTRACT_FIRST configuration, to allow users to restore the prior behavior of not inspecting any headers after the first one was extracted.

How to test the change?

All changes are covered by unit tests and system-tests (DataDog/system-tests#1795).

For Datadog employees:

  • If this PR touches code that signs or publishes builds or packages, or handles
    credentials of any kind, I've requested a review from @DataDog/security-design-and-guidance.
  • This PR doesn't touch any of that.

Unsure? Have a question? Request a review!

@marcotc marcotc requested review from a team as code owners November 10, 2023 20:06
Base automatically changed from default-propgator-change to master November 10, 2023 20:08
Copy link

@aliciascott aliciascott left a comment

Choose a reason for hiding this comment

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

Looks good

@codecov-commenter
Copy link

Codecov Report

Merging #3255 (8b6432a) into master (8fe9497) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master    #3255   +/-   ##
=======================================
  Coverage   98.21%   98.22%           
=======================================
  Files        1253     1253           
  Lines       72110    72198   +88     
  Branches     3346     3350    +4     
=======================================
+ Hits        70823    70916   +93     
+ Misses       1287     1282    -5     
Files Coverage Δ
lib/datadog/tracing/configuration/ext.rb 100.00% <100.00%> (ø)
lib/datadog/tracing/configuration/settings.rb 95.20% <100.00%> (+0.13%) ⬆️
lib/datadog/tracing/distributed/propagation.rb 93.47% <100.00%> (+1.37%) ⬆️
lib/datadog/tracing/trace_digest.rb 100.00% <100.00%> (ø)
...pec/datadog/tracing/configuration/settings_spec.rb 100.00% <100.00%> (ø)
...ec/datadog/tracing/distributed/propagation_spec.rb 100.00% <100.00%> (ø)
spec/datadog/tracing/trace_digest_spec.rb 100.00% <100.00%> (ø)

... and 4 files with indirect coverage changes

📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today!

# @param field_value_pairs [Hash<String>] the fields to be overwritten
# @return [TraceDigest] returns a copy of this object with the `field_value_pairs` modified
def merge(field_value_pairs)
# DEV: Because we want to sometimes freeze the values provided to `TraceDigest`, it's best
Copy link
Contributor

Choose a reason for hiding this comment

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

non-blocking: Is there any reason to be concerned about performance here?

Copy link
Member Author

@marcotc marcotc Nov 15, 2023

Choose a reason for hiding this comment

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

It's not really performance, but more about maintainability.
This code section would have to be duplicated here:

@span_id = span_id
@span_name = span_name && span_name.dup.freeze
@span_resource = span_resource && span_resource.dup.freeze
@span_service = span_service && span_service.dup.freeze
@span_type = span_type && span_type.dup.freeze
@trace_distributed_tags = trace_distributed_tags && trace_distributed_tags.dup.freeze
@trace_hostname = trace_hostname && trace_hostname.dup.freeze
@trace_id = trace_id
@trace_name = trace_name && trace_name.dup.freeze
@trace_origin = trace_origin && trace_origin.dup.freeze
@trace_process_id = trace_process_id
@trace_resource = trace_resource && trace_resource.dup.freeze
@trace_runtime_id = trace_runtime_id && trace_runtime_id.dup.freeze
@trace_sampling_priority = trace_sampling_priority
@trace_service = trace_service && trace_service.dup.freeze
@trace_distributed_id = trace_distributed_id
@trace_flags = trace_flags
@trace_state = trace_state && trace_state.dup.freeze
@trace_state_unknown_fields = trace_state_unknown_fields && trace_state_unknown_fields.dup.freeze

But it has to decide which fields can be used as is, or which ones need to be dup.freeze.

This is just to make sure we don't duplicate the logic and forget to copy some values but not others.

@marcotc marcotc merged commit 3ef068c into master Nov 15, 2023
218 checks passed
@marcotc marcotc deleted the extract-tracestate-always branch November 15, 2023 18:35
@github-actions github-actions bot added this to the 1.17.0 milestone Nov 15, 2023
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.

4 participants