open-telemetry / open-telemetry/opentelemetry-python

Callback on context change

Open
#3,915 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

feature-request
Dominant language
Python
Stars
2.6k
Forks
1k
Avg merge
4d 15h
Merged PRs (30d)
19

Description

Why you need this feature?

Elastic is proposing a donation of our continuous profiler (https://github.com/open-telemetry/community/issues/1918). In order to do correlation of profiling data with traces collected by language sdks we need to provide to the profiler current thread trace id, span id and root span id.

Describe the solution you'd like

Following java implementation I thought an hook on the context api may work, I've done a quick POC here:

https://gist.github.com/xrmx/fc81e710e7a860ca229839b10e780dfd

On the technical side I'm unsure if the optional hook callback should be configured via an environment variable or via an entrypoint.

Describe alternatives you've considered

An alternative if the context is the right place to hook would be to provide a custom context storage implementation but that would not be generic or upstreamable.

Additional context

In the java sdk they have https://javadoc.io/doc/io.opentelemetry/opentelemetry-context/latest/io/opentelemetry/context/ContextStorage.html#addWrapper(java.util.function.Function)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the context API and the linked Python proof of concept, then compare the proposed hook with Java's ContextStorage.addWrapper implementation. The issue needs a decision on the callback design and whether configuration uses an environment variable or an entrypoint; done means an agreed, generic upstreamable approach for exposing current trace context to the profiler.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, observability
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.