Skip to content

Conversation

beniwohli
Copy link
Contributor

@beniwohli beniwohli commented Dec 1, 2019

  • support traceparent header
  • support tracestate header propagation

What 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, 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.

Why is it important?

TraceContext is now a recommendation candidate, time to support it
fully.

Related issues

closes #628
refs elastic/apm#71

… 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
@beniwohli beniwohli marked this pull request as ready for review December 2, 2019 16:54
Copy link
Contributor

@basepi basepi left a comment

Choose a reason for hiding this comment

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

Great work! Love the thorough testing. As far as I can tell we've hit the spec exactly.

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

@beniwohli beniwohli merged commit 962ee8c into elastic:master Dec 6, 2019
@beniwohli beniwohli deleted the tracecontext branch December 6, 2019 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support tracecontext W3C header
2 participants