NH-2313 Add basic TraceState handling and W3C trace context propagation#11
Merged
tammy-baylis-swi merged 78 commits intomainfrom May 9, 2022
Merged
NH-2313 Add basic TraceState handling and W3C trace context propagation#11tammy-baylis-swi merged 78 commits intomainfrom
tammy-baylis-swi merged 78 commits intomainfrom
Conversation
…tes creation (0000)
Contributor
Author
|
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) |
Contributor
Author
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
cheempz
approved these changes
May 9, 2022
Contributor
cheempz
left a comment
There was a problem hiding this comment.
Thanks for the revisit @tammy-baylis-swi! LGTM :)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_disabled1. Add custom Propagator
SolarWindsPropagatoris new. It must be used in composite after two existing OTel Python propagators,tracecontextandbaggage. Currently this is configured on the customer side (i.e. the testbed) asOTEL_PROPAGATORS: tracecontext,baggage,solarwinds.SolarWindsPropagatorperformsextractof 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-optionsandx-trace-options-signatureif provided. Note that the OTel Python propagator fortracecontextalready handles extraction and injection oftraceparentandtracestateheaders.extractis called by OTel Python after a request arrives at an instrumented service.SolarWindsPropagatorperformsinjectof our values into outgoing HTTP request headers. Specifically, we set uptracestatewith 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.injectis called by OTel Python when an instrumented service is preparing to make a request. Note that OTel Python is equipped with aTraceStateclass that has predefined methods to add/update KVs.2. Update custom Sampler
ParentBasedSwSamplerreplaces theParentBasedAoSamplerplaceholder 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
ParentBaseddefaults 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.
_SwSamplerreplaces the_AoSamplerplaceholder that Martin created and it used byParentBasedSwSamplerfor the 3 cases above. Whenshould_sampleis 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_decisionuses parent span information fromparent_span_contextand header values fromparent_contextas inputs for SWIG'd liboboeContext.getDecisions._SwSampler.calculate_trace_stateuses the liboboe decision outputs to create a new tracestate, or update the tracestate of theparent_span_contextif it exists, for propagation._SwSampler.calculate_attributescalculatessw.tracestate_parent_idandsw.w3c.tracestatethat are used for span creation and event export to the backend, without being propagated.3. Add custom ResponsePropagator
SolarWindsTraceResponsePropagatoris 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.SolarWindsTraceResponsePropagatorextends the OTel Python abstract classResponsePropagatorso we can customize thex-traceandx-trace-options-responseheaders that weinjectinto responses from instrumented services after incoming HTTP requests.Special note: Like the Java custom-distro,
x-trace-options-responsedepends on a tracestate piggyback mechanism where extracted headers are added to tracestate atshould_samplethen injected for context propagation. This is because by the timeResponsePropagator.injectis 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 propagatedtracestateto ensure that the correctx-trace-options-responseis 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
XTraceOptionsdigests incomingx-trace-optionsandx-trace-options-signaturerequest headers into values usable by SWIG'd liboboe for decision-making.W3CTransformerhas 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