Skip to content

OTEP: Thread Context: Sharing Thread-Level Information with external readers#4947

Open
scottgerring wants to merge 52 commits into
open-telemetry:mainfrom
scottgerring:profiling-tls-context
Open

OTEP: Thread Context: Sharing Thread-Level Information with external readers#4947
scottgerring wants to merge 52 commits into
open-telemetry:mainfrom
scottgerring:profiling-tls-context

Conversation

@scottgerring

@scottgerring scottgerring commented Mar 16, 2026

Copy link
Copy Markdown
Member

Changes

External readers like the OpenTelemetry eBPF Profiler operate outside the instrumented process and cannot collect information about active OpenTelemetry traces running within the process they are sampling. We (@ivoanjo and @scottgerring) propose a mechanism for OpenTelemetry SDKs to publish thread-level attributes — including trace ID, span ID, and configurable custom attributes — through a standard format based on the ELF Thread Local Storage (TLSDESC) dialect.

Because this mechanism relies on having a native component and knowing when a runtime switches contexts, we consider it optional for SDKs to support, as some runtimes (or even runtime versions) may not be able to feasibly/efficiently (or undesirable, maintenance-wise) to implement it.

When a request context is attached or detached from a thread, the SDK publishes select information to a thread-local variable that external readers such as the eBPF profiler can discover and read. This enables correlation of profiling samples with request context, even when the active span was not sampled by the SDK.

This builds on and extends OTEP 4719: Process Context, using its process context mechanism to store the static, process-scoped reference data (schema version and attribute key map) that the thread-local records reference.

Why open as draft: OTEP 4719 is a dependency for this OTEP, and thus we'll need to wait for that OTEP to land to ensure we have a solid underpinning to build on.

This OTEP is based and heavily inspired on the custom-labels work by [Polar Signals](https://www.polarsignals.com/) and the universal profiling integration by Elastic — big thanks to them for the prior art and inspiration.and everyone that collaborated with us on the draft google doc this is based on.

@scottgerring scottgerring force-pushed the profiling-tls-context branch from 3cf6426 to 047db5a Compare March 26, 2026 09:47
@scottgerring

Copy link
Copy Markdown
Member Author

Now that #4719 has been accepted, this one is ready for review!

@scottgerring scottgerring marked this pull request as ready for review April 8, 2026 07:49
Comment thread oteps/profiles/4947-thread-ctx.md Outdated
Comment thread oteps/profiles/4947-thread-ctx.md Outdated
Comment thread oteps/profiles/4947-thread-ctx.md Outdated
@scottgerring scottgerring changed the title OTEP: Thread Context: Sharing Thread-Level Information with the OpenTelemetry eBPF Profiler OTEP: Thread Context: Sharing Thread-Level Information with external readers Apr 9, 2026
Co-authored-by: Attila Szegedi <szegedi@users.noreply.github.com>
@linux-foundation-easycla

linux-foundation-easycla Bot commented Apr 13, 2026

Copy link
Copy Markdown

CLA Signed

The committers listed above are authorized under a signed CLA.

Comment thread oteps/profiles/4947-thread-ctx.md
Comment thread oteps/profiles/4947-thread-ctx.md
Comment thread oteps/profiles/4947-thread-ctx.md

@jsuereth jsuereth left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Overall - this answers my one major question.

I am worried about picking the right amount of information to pass back/forth between contexts. Given how we do logging today - I suspect we want the entire w3c traceparent dataset here, with a notion of w3c baggage. I think you've captured most of this, but I'm curious about the omission of some pieces and the impact of that.

For context -

Logs does include trace flag - https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/logs/v1/logs.proto#L181

Profiling does not include trace flag - https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/profiles/v1development/profiles.proto#L362

So if this is a general protocol that would, e.g. allow eBPF collection of stdout logs and attaching trace information for OTLP export - We'd need flags. If this is only for profiling, today we do not need it.

Given this is an OTEP - this doesn't block my approval. However - I think you should figure this out before formalizing this protocol - as I suspect it'll be sticky. I'd prefer to see the flags added now as I think it may be harder to add later (I'd still like to keep a reserved set of bits for things in case we missed anything else)

Comment thread oteps/profiles/4947-thread-ctx.md
Comment thread oteps/profiles/4947-thread-ctx.md Outdated
Comment thread oteps/profiles/4947-thread-ctx.md Outdated
Comment thread oteps/profiles/4947-thread-ctx.md Outdated
@reyang

reyang commented Jul 14, 2026

Copy link
Copy Markdown
Member

For folks who haven't got a chance to review this PR yet, we plan to merge it by the end of Jul. 17th unless there are blocking/outstanding comments.

@ivoanjo

ivoanjo commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Update: I've pushed a small commit to refresh the "prototypes" section with more implementations that we're involved with/aware of.

@szegedi szegedi left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Few tiny changes (a typo and a better URL.)

Unrelated to these, does it make sense to express somewhere that when attributes are appended to an existing record in-place (because it has a sufficiently large allocation slack to hold them), then flipping the valid flag to 0 and back to 1 is not necessary as long as attrs_size is updated with a signal fence that ensures its new, incremented value is only written after the attributes themselves were written? Or is that too much of an implementation detail for a specification? This spec has gone into rather detailed prescriptions for fencing (which I think is good!) so that's why I wonder if this has its place in it.

My "Request changes" status on this review pertains only to the two tiny changes, not to the question above.

Comment thread oteps/profiles/4947-thread-ctx.md Outdated
Comment thread oteps/profiles/4947-thread-ctx.md Outdated
ivoanjo and others added 3 commits July 16, 2026 11:26
(Minor text fixes, thanks Attila!)

Co-authored-by: Attila Szegedi <szegedi@users.noreply.github.com>
@ivoanjo

ivoanjo commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Unrelated to these, does it make sense to express somewhere that when attributes are appended to an existing record in-place (because it has a sufficiently large allocation slack to hold them), then flipping the valid flag to 0 and back to 1 is not necessary as long as attrs_size is updated with a signal fence that ensures its new, incremented value is only written after the attributes themselves were written? Or is that too much of an implementation detail for a specification? This spec has gone into rather detailed prescriptions for fencing (which I think is good!) so that's why I wonder if this has its place in it.

I like it. Added in 65937b3, let me know your thoughts!

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.