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

NH-51264 Remove custom naming baggage at propagator.inject #184

Merged
merged 3 commits into from
Aug 1, 2023

Conversation

tammy-baylis-swi
Copy link
Contributor

@tammy-baylis-swi tammy-baylis-swi commented Jul 31, 2023

APM Python's custom propagator now removes any sw-current-trace-id or sw-current-entry-span-id KVs from context baggage at injection, if present. These may or may not have been set when set_transaction_name was previously called.

This relies on Otel Python W3CBaggagePropagator being used first in the composite. This is to leverage extraction of incoming baggage headers and check that they're correctly formatted, then to pre-set the baggage header for injection. Custom propagator removes the two sw KVs from the baggage header already set by W3CBaggagePropagator. Therefore, there is an added rule here for specifying OTEL_PROPAGATORS and customer docs will have to be updated.

Here's what happens now when testbed Django A receives a request curl -v http://0.0.0.0:8002/home_a/ -H "baggage:my-foo=some-baggage" resulting in a request to Django B:

OTEL_PROPAGATORS agent_enabled Baggage request header to Django B
none (defaults to tracecontext,baggage,solarwinds_propagator) True 'Baggage': 'my-foo=some-baggage'
tracecontext,solarwinds_propagator True, because baggage is optional not set
tracecontext,baggage,solarwinds_propagator True 'Baggage': 'my-foo=some-baggage'
tracecontext,solarwinds_propagator,baggage False, because baggage is after solarwinds_propagator not set

Before this PR for the first scenario, the request header would have been, for example: 'Baggage': 'my-foo=some-baggage,sw-current-trace-id=211437738876350461983321418219135041650,sw-current-entry-span-id=14984741770333256707'

Please let me know if any questions or suggestions! 😺

) -> str:
"""Removes values used for custom naming from baggage header created
by upstream W3CBaggagePropagator propagator, if present"""
baggage_entries: list[str] = split(_DELIMITER_PATTERN, baggage_header)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This and the other split don't have to be this way of course. Open to suggestions if any.

baggage_kvs = {}
for entry in baggage_entries:
try:
e_name, e_value = entry.split("=", 1)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tammy-baylis-swi tammy-baylis-swi marked this pull request as ready for review July 31, 2023 22:43
@tammy-baylis-swi tammy-baylis-swi requested a review from a team July 31, 2023 22:43
Copy link
Contributor

@swi-jared swi-jared left a comment

Choose a reason for hiding this comment

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

LGTM

Though I wonder if it'd be simpler if we used a single baggage key?

@tammy-baylis-swi
Copy link
Contributor Author

Though I wonder if it'd be simpler if we used a single baggage key?

Could do! I'll do it in a separate PR.

@tammy-baylis-swi tammy-baylis-swi merged commit 021c586 into main Aug 1, 2023
@tammy-baylis-swi tammy-baylis-swi deleted the NH-51264-rm-custom-naming-baggage branch August 1, 2023 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants