-
Notifications
You must be signed in to change notification settings - Fork 408
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
WIP: otel baggage support initial PR #10389
base: main
Are you sure you want to change the base?
Conversation
|
Datadog ReportBranch report: ❌ 31 Failed (0 Known Flaky), 175899 Passed, 1677 Skipped, 9h 26m 4.02s Total duration (9m 24.94s time saved) ❌ Failed Tests (31)
|
log.error( | ||
"Programming ERROR: ddtrace does not support activiting spans with the type: %s. Please open a " | ||
"github issue at: https://github.com/Datadog/dd-trace-py and set DD_TRACE_OTEL_ENABLED=True.", | ||
type(otel_span), | ||
) | ||
|
||
# get current open telemetry baggage and store it on the datadog context object |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add test coverage for baggage to tests/opentelemetry/test_context.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bump on this, we need a test case. We should use this: https://github.com/open-telemetry/opentelemetry-python/blob/bd51fcb7a3afb08aec975e7302c9cc36060bcacc/opentelemetry-api/src/opentelemetry/baggage/propagation/__init__.py#L29
This test will look similar to: https://github.com/DataDog/dd-trace-py/blob/af9d095c8955e92a318ec78eeb8d9f3143e625c3/tests/opentelemetry/test_trace.py#L162-#L184
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use this to get the baggage set by the propagator: https://github.com/open-telemetry/opentelemetry-python/blob/bd51fcb7a3afb08aec975e7302c9cc36060bcacc/opentelemetry-api/src/opentelemetry/baggage/__init__.py#L53C5-L53C16
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also make sure the opentelemetry baggage api getters and setters work as expected and create/set/remove values on datadog context objects: https://github.com/open-telemetry/opentelemetry-python/blob/bd51fcb7a3afb08aec975e7302c9cc36060bcacc/opentelemetry-api/src/opentelemetry/baggage/__init__.py#L53-#L117
dd_baggage = {} | ||
|
||
# getting current active baggage | ||
for key, value in dd_baggage.items(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here we should add test coverage for this
ddtrace/propagation/http.py
Outdated
return | ||
|
||
header_value = ",".join( | ||
f"{_BaggageHeader._encode_key(str(key).strip())}={_BaggageHeader._encode_value(str(value).strip())}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we raise an unhandled exception if value can not be converted to a string? How should we handle dicts,arrays,booleans,etc. The format needs to be consistent across languages (ex: encoding True
vs true
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When "extracting baggage from propagation headers, they may encounter malformed header contents." When this occurs, we "should ignore the entire header." (RFC) So instead of an error, we could potentially just ignore it? As of now, I think it would just do something like a type error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we raise an unhandled exception if value can not be converted to a string?
I don't know who errors are handles in Python, but an invalid header should not break the service we are instrumenting. We could definitely log a warning or whatever you usually do in cases like this.
"should ignore the entire header." (RFC)
The main point here was that we should not try to extract individual values while ignore that bad ones. If something is wrong, don't try to extract anything. I clear this up in the RFC, thanks.
for key_value in baggages: | ||
key, value = key_value.split("=", 1) | ||
key = urllib.parse.unquote(key.strip()) | ||
value = urllib.parse.unquote(value.strip()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How should this deconding/unquoting handle errors?
if style_w_ctx[0] == _PROPAGATION_STYLE_BAGGAGE: | ||
baggage_context = contexts[0] | ||
contexts.append(baggage_context) | ||
del contexts[0] | ||
styles_w_ctx.append(_PROPAGATION_STYLE_BAGGAGE) | ||
del style_w_ctx[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we handle this outside of the for-loop? baggage should never be the primary_context
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the RFC it says that users can also disable other propagation styles (tracecontext or datadog) and enable only the baggage propagator which means baggage could be the primary_context
in certain cases. Considering this, I think we can leave the code inside the for-loop. Let me know your thoughts because I think there are may be better ways to go about this.
@@ -885,12 +887,55 @@ def _inject(span_context, headers): | |||
return headers | |||
|
|||
|
|||
class _BaggageHeader: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚪ Code Quality Violation
Class _BaggageHeader should have an init method (...read more)
Ensure that a class has an __init__
method. This check is bypassed when the class is a data class (annotated with @DataClass).
if style_w_ctx == _PROPAGATION_STYLE_BAGGAGE: | ||
primary_context._baggage.update(context._baggage) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Code Quality Violation
too many nesting levels (...read more)
Avoid to nest too many loops together. Having too many loops make your code harder to understand.
Prefer to organize your code in functions and unit of code you can clearly understand.
First PR introducing otel baggage support
Checklist
Reviewer Checklist