dd-trace-py icon indicating copy to clipboard operation
dd-trace-py copied to clipboard

Added distributed header context extraction+activation to tracer

Open Yun-Kim opened this issue 4 years ago • 3 comments

Description

Currently, users have to create their own Propagator classes and/or use the HTTPPropagator along with extra steps of extracting the context from request headers and activating them with the ContextProvider class to achieve distributed tracing, described by our documentation as such:

context = HTTPPropagator.extract(headers)
    if context.trace_id:
        tracer.context_provider.activate(context)

This is made easier by making it so that the Tracer class has access to a Propagator property (HTTPPropagator by default) and provides a function activate_distributed_headers() that accomplishes the aforementioned steps in extracting and activating a distributed request.

Additionally, an abstract Propagator class was introduced to base our HTTPPropagator and users' custom Propagator classes from, and to provide the base methods of injecting and extracting contexts into/from request headers.

Yun-Kim avatar May 04 '21 19:05 Yun-Kim

Next steps and things to consider:

We need to account for updating trace and parent IDs in the trace when the trace has already started when dealing with distributed tracing (reference issue #1759). From preliminary investigation, it looks like this requires going through the entire trace after checking if there's an active context and change the parenting to maintain distributed tracing. This is currently not possible since we only have parent references in a span and no references to its children.

Second, partial flushing may cause problems since some spans in a trace may already be flushing and therefore can't update those spans.

Third, what if there are multiple requests/services in a trace? Then, we don't want to change every span in the trace, but this leads to the question of which spans do we update retroactively?

Yun-Kim avatar May 04 '21 19:05 Yun-Kim

@Yun-Kim this pull request is now in conflict 😩

mergify[bot] avatar Nov 10 '21 15:11 mergify[bot]

@Yun-Kim this pull request is now in conflict 😩

mergify[bot] avatar Sep 26 '22 07:09 mergify[bot]