Implement Trace Context standard#660
Merged
Merged
Conversation
… header On incoming requests, we first check for the presence of `traceparent`, and fall back to `elastic-apm-traceparent`. For outgoing requests, `traceparent` is always set. `elastic-apm-traceparent` is set if the config option `use_elastic_traceparent_header` is set to True. For now, this option defaults to True, but will be changed to False after a grace period.
Initially, we only forward the header, and don't try to parse its content. This will only be necessary once we start adding our own data to tracestate
c704bff to
feacdbf
Compare
basepi
approved these changes
Dec 2, 2019
Comment on lines
+104
to
+121
| @classmethod | ||
| def merge_duplicate_headers(cls, headers, key): | ||
| """ | ||
| HTTP allows multiple values for the same header name. Most WSGI implementations | ||
| merge these values using a comma as separator (this has been confirmed for wsgiref, | ||
| werkzeug, gunicorn and uwsgi). Other implementations may use containers like | ||
| multidict to store headers and have APIs to iterate over all values for a given key. | ||
|
|
||
| This method is provided as a hook for framework integrations to provide their own | ||
| TraceParent implementation. The implementation should return a single string. Multiple | ||
| values for the same key should be merged using a comma as separator. | ||
|
|
||
| :param headers: a dict-like header object | ||
| :param key: header name | ||
| :return: a single string value | ||
| """ | ||
| # this works for all known WSGI implementations | ||
| return headers.get(key) |
Contributor
There was a problem hiding this comment.
Good work being so thorough with your investigation here. And for providing something to override if Murphy's Law gives us a WSGI implementation with different behavior.
7c30e18 to
c6eaa57
Compare
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.
traceparentheadertracestateheader propagationWhat does this pull request do?
On incoming requests, we first check for the presence of
traceparent,and fall back to
elastic-apm-traceparent.For outgoing requests,
traceparentis always set.elastic-apm-traceparentis set if the config option
use_elastic_traceparent_headeris set toTrue. For now, this option defaults to True, but will be changed to False
after a grace period.
Why is it important?
TraceContext is now a recommendation candidate, time to support it
fully.
Related issues
closes #628
refs elastic/apm#71