-
Notifications
You must be signed in to change notification settings - Fork 906
Description
Today server instrumentations such as Django always extract the parent span from the incoming request headers. This may not always be ideal. For example, there may be other instrumented components that wrap an instrumented web framework such as WSGI. In such cases WSGI would already have generated a server span and used the remote span as parent. If Django did the same, traces would not make a lot of sense. Depending on whether a remote span is present in the incoming request's carrier, Django and WSGI spans would be completely different traces or be siblings instead of parent and child.
To avoid situations like this, all server instrumentations should first check if an active span is present in the current context by calling opentelemetry.api.trace.get_current_span() and use it as the parent when present. When no active span is found in the current context, the instrumentation should try to extract remote span context from the incoming request and use that as the parent.
This needs to be done for all instrumentations that generate server spans.
Changes that need to be made:
- If a span is found in the current context, then:
- create a new span with kind set to INTERNAL
- use the span found in current context as parent
- If no span is in the current context, then:
- create a new span with kind set to SERVER
- extract remote span context from incoming request and use it as parent