-
Notifications
You must be signed in to change notification settings - Fork 1
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-2313 Add basic TraceState handling and W3C trace context propagation #11
Conversation
…tes creation (0000)
Update: I've responded to all comments from the second wave, except for this one about environment variables. I'm working on it now. #11 (comment) |
This has now been addressed: #11 (comment) |
…-timestamp NH-9150 Use oboe_api functions for no default timestamp
…-kvs NH-11236 sampler creates Service Entry Internal KVs
…g-by-customer NH-2313 adjust CompositePropagator config with OTEL_PROPAGATORS
…ate-from-carrier NH-2313 Bugfixes: propagator gets tracestate from carrier; from_header usage fix
…r-setup NH-12018 Separate Distro vs Configurator
…gurator NH-12018 oboe Reporter init moved to Configurator
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.
Thanks for the revisit @tammy-baylis-swi! LGTM :)
Add basic TraceState handling and W3C trace context propagation
Summary of changes, with details described in below sections:
Out of scope / What I'd much prefer put in a future PR:
tracing_mode
,sample_rate
,trigger_tracing_mode_disabled
1. Add custom Propagator
SolarWindsPropagator
is new. It must be used in composite after two existing OTel Python propagators,tracecontext
andbaggage
. Currently this is configured on the customer side (i.e. the testbed) asOTEL_PROPAGATORS: tracecontext,baggage,solarwinds
.SolarWindsPropagator
performsextract
of incoming HTTP request headers into the OTel context so that they're available to the Sampler. This is how sampling decision can be made usingx-trace-options
andx-trace-options-signature
if provided. Note that the OTel Python propagator fortracecontext
already handles extraction and injection oftraceparent
andtracestate
headers.extract
is called by OTel Python after a request arrives at an instrumented service.SolarWindsPropagator
performsinject
of our values into outgoing HTTP request headers. Specifically, we set uptracestate
with the KVsw=<span_id>_<trace_flags>
. This is how we propagate a SolarWinds sampling decision that was made by the Sampler for the last span in a service to the next service in a distributed trace.inject
is called by OTel Python when an instrumented service is preparing to make a request. Note that OTel Python is equipped with aTraceState
class that has predefined methods to add/update KVs.2. Update custom Sampler
ParentBasedSwSampler
replaces theParentBasedAoSampler
placeholder that Martin created. It extends OTel Python's ParentBased sampler to let OTel Python delegate decision-making depending on whether the future span***:Copied from TraceState Handling:
For future spans with local parent spans (e.g. ServiceB, span2), we use the OTel Python
ParentBased
defaults forALWAYS_ON
/ALWAYS_OFF
.***"Future spans?" OTel Python calls should_sample before creating a new span in an instrumented service. Note that unlike the Propagator that can be set up as a composite of many, there is only one Sampler for the custom-distro.
_SwSampler
replaces the_AoSampler
placeholder that Martin created and it used byParentBasedSwSampler
for the 3 cases above. Whenshould_sample
is called it makes a decision using SWIG'd liboboe. It also calculates tracestate and attributes based on that decision for custom SW behaviour:_SwSampler.calculate_liboboe_decision
uses parent span information fromparent_span_context
and header values fromparent_context
as inputs for SWIG'd liboboeContext.getDecisions
._SwSampler.calculate_trace_state
uses the liboboe decision outputs to create a new tracestate, or update the tracestate of theparent_span_context
if it exists, for propagation._SwSampler.calculate_attributes
calculatessw.tracestate_parent_id
andsw.w3c.tracestate
that are used for span creation and event export to the backend, without being propagated.3. Add custom ResponsePropagator
SolarWindsTraceResponsePropagator
is new. It relies on what Cloud Native is currently calling an "experimental propagator that injects tracecontext into HTTP responses". Hopefully it becomes official and better-documented this year; then we won't have to customize entrypoints for individual OTel Python instrumentations of Flask, Django, ASGI, etc.SolarWindsTraceResponsePropagator
extends the OTel Python abstract classResponsePropagator
so we can customize thex-trace
andx-trace-options-response
headers that weinject
into responses from instrumented services after incoming HTTP requests.Special note: Like the Java custom-distro,
x-trace-options-response
depends on a tracestate piggyback mechanism where extracted headers are added to tracestate atshould_sample
then injected for context propagation. This is because by the timeResponsePropagator.inject
is called, the span(s) for that instrumented service has already been created and the initial options header and liboboe decision output are no longer in the OTel context. Also like Java, switching delimiters between W3C-unfriendly [,
,=
] and the unlikely-to-be-used-meaningfully [....
,####
] lets us store options in propagatedtracestate
to ensure that the correctx-trace-options-response
is calculated for each trace and without adding a complex storage of these values to the distro. Thank you Eric for coming up with this.4. Add helper classes
XTraceOptions
digests incomingx-trace-options
andx-trace-options-signature
request headers into values usable by SWIG'd liboboe for decision-making.W3CTransformer
has commonly-used methods to convert integers from various sources to hex strings for decision-making and propagation.5. Meets some Acceptance Criteria
Please see this page for test methods and results: https://swicloud.atlassian.net/wiki/spaces/NIT/pages/2886959329/2022-04-06+testing