Skip to content

OTEP: Context-scoped Attributes - #4931

Merged
carlosalberto merged 39 commits into
open-telemetry:mainfrom
carlosalberto:otep-context-scoped-attrs
Jun 22, 2026
Merged

OTEP: Context-scoped Attributes#4931
carlosalberto merged 39 commits into
open-telemetry:mainfrom
carlosalberto:otep-context-scoped-attrs

Conversation

@carlosalberto

@carlosalberto carlosalberto commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

Add Context-scoped telemetry attributes which typically apply to all signals associated with a trace as it crosses a single service.

Resurrecting open-telemetry/oteps#207 while updating some changes that have happened since (e.g. changes in InstrumentationScope being a runtime concept rather than a compile-time one). Originally proposed by @Oberon00

Additionally:

  1. A Processor alternative being discarded as we would need to add an additional pre OnStart call in order to support Samplers.
  2. The open question whether Baggage should be included as part of stamping attributes to individual telemetry items (similar enough functionality).
  3. We disable this functionality by default. Users have to opt-in to use this.

Java prototype for traces/logs: https://github.com/open-telemetry/opentelemetry-java/compare/main...carlosalberto:context-scoped-attrs-proto?expand=1

Summary

This OTEP aims to address various related demands that have been brought up in the past, where the scope of Resource attributes is too broad, but the scope of Span attributes is too narrow. For example, this happens where there is a mismatch between the OpenTelemetry SDK’s (and thus TracerProvider’s, MeterProvider’s) process-wide initialization and the semantic scope of a (sub)service.

The context-scoped attributes allows you to attach attributes to all telemetry signals emitted within a Context. Context-scoped attributes are normal attributes, which means you can use strings, integers, floating point numbers, booleans or arrays thereof, just like for Span or Resource attributes. Context-scoped attributes are associated with all telemetry signals emitted while the Context containing the Context-scoped attributes is active and are available to telemetry exporters. For spans, the context within which the span is started applies. Like other telemetry APIs, Context-scoped attributes are write-only for applications. You cannot query the currently set Context-scoped attributes, they are only available on the SDK level (e.g. to Samplers and SpanProcessors and exporters).

Context-scoped attributes should be thought of equivalent to adding the attribute directly to each single telemetry item it applies to.

@carlosalberto
carlosalberto requested review from a team as code owners March 10, 2026 15:17
Comment thread oteps/4931-context-scoped-attributes.md Outdated
Comment thread oteps/4931-context-scoped-attributes.md Outdated
Comment thread oteps/4931-context-scoped-attributes.md Outdated
Comment thread oteps/4931-context-scoped-attributes.md Outdated
Comment thread oteps/4931-context-scoped-attributes.md Outdated
Comment thread oteps/4931-context-scoped-attributes.md Outdated
Comment thread oteps/4931-context-scoped-attributes.md Outdated
Comment thread oteps/4931-context-scoped-attributes.md Outdated
Comment thread oteps/4931-context-scoped-attributes.md Outdated
Comment thread oteps/4931-context-scoped-attributes.md
Comment thread oteps/4931-context-scoped-attributes.md Outdated
Comment thread oteps/4931-context-scoped-attributes.md Outdated
Comment thread oteps/4931-context-scoped-attributes.md
Comment thread oteps/4931-context-scoped-attributes.md Outdated
Comment thread oteps/4931-context-scoped-attributes.md Outdated
Comment thread oteps/4931-context-scoped-attributes.md Outdated
Comment thread oteps/4931-context-scoped-attributes.md
Comment thread oteps/4931-context-scoped-attributes.md Outdated
Comment thread oteps/4931-context-scoped-attributes.md Outdated

@dashpole dashpole 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.

Go has had a "labeler" concept specific to http that is similar to this proposal: https://pkg.go.dev/go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp#ContextWithLabeler. I would love to see a more cohesive and generic design for this!

Comment thread oteps/4931-context-scoped-attributes.md
Comment thread oteps/4931-context-scoped-attributes.md Outdated
@dashpole

Copy link
Copy Markdown
Contributor

FYI @open-telemetry/go-maintainers I think whatever comes from this proposal is what should replace our otelhttp.Labeler.

@carlosalberto
carlosalberto force-pushed the otep-context-scoped-attrs branch from aa5770a to fb85ea6 Compare June 10, 2026 13:50
@dashpole
dashpole requested a review from MrAlias June 16, 2026 15:44

@MrAlias MrAlias 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.

Thanks for continuing to tighten this. I think the repeated context-write semantics and measurement-time merge point are in much better shape now. I left one metrics edge case that should be clarified, plus a couple of wording/configuration cleanups.

Comment thread oteps/4931-context-scoped-attributes.md Outdated
Comment thread oteps/4931-context-scoped-attributes.md
Comment thread oteps/4931-context-scoped-attributes.md Outdated
@carlosalberto

Copy link
Copy Markdown
Contributor Author

@MrAlias Thanks for the last pieces of feedback. This is ready for another review cycle.

@MrAlias MrAlias 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.

Awesome work! 🚀

@carlosalberto

Copy link
Copy Markdown
Contributor Author

@open-telemetry/technical-committee I plan to merge this as part of the #5164 - let me know if you'd rather have me put this PR on hold ;)

@carlosalberto
carlosalberto added this pull request to the merge queue Jun 22, 2026
Merged via the queue into open-telemetry:main with commit 57f655c Jun 22, 2026
9 checks passed
@carlosalberto
carlosalberto deleted the otep-context-scoped-attrs branch June 22, 2026 11:56
@carlosalberto carlosalberto mentioned this pull request Jun 22, 2026
jack-berg pushed a commit to cijothomas/opentelemetry-specification that referenced this pull request Jun 22, 2026
### Context

- Clarify that environment variable propagation carriers normalize
requested
  keys, carrier keys, and returned keys.

([open-telemetry#5102](open-telemetry#5102))
- Specify that environment variable propagation carriers only read and
return
  normalized environment variable names.

([open-telemetry#5144](open-telemetry#5144))
- Specify that an empty environment variable propagation name is
non-normalized
  and normalizes to `_`.

([open-telemetry#5163](open-telemetry#5163))

### Profiles

- Remove duplicate information from and extend Profiles documentation
(README.md, pprof.md).

([open-telemetry#4932](open-telemetry#4932))

### Entities

- Add specification for communicating entity information as structured
log events.

([open-telemetry#4836](open-telemetry#4836))

### Common

- Add an in-development [SDK
self-observability](specification/self-observability.md)
  section, referenced from the Tracing, Metrics, and Logs SDK specs.

([open-telemetry#5087](open-telemetry#5087))
- Clarify non-OTLP representation guidance for nested `AnyValue` values
in
  arrays and maps.

([open-telemetry#5053](open-telemetry#5053))
- Add in-development guidance recommending a JSON object as the string
  representation for an attribute in non-OTLP protocols.

([open-telemetry#5028](open-telemetry#5028))
- Add in-development guidance recommending a JSON object as the string
  representation for an attribute collection in non-OTLP protocols.

([open-telemetry#5110](open-telemetry#5110))

### Compatibility

- Deprecate OpenCensus compatibility requirements in the specification.

([open-telemetry#5138](open-telemetry#5138))
- Stabilize sections of Prometheus Metrics Exporter.
  - Clarify resource attributes configuration.

([open-telemetry#5084](open-telemetry#5084))
- Stabilize the conversion of OTLP Summaries into Prometheus Summaries.

([open-telemetry#5107](open-telemetry#5107))
  - Stabilize client libs section.

([open-telemetry#5106](open-telemetry#5106))
- Stabilize Prometheus Metrics Exporter default aggregation
configuration.

([open-telemetry#5113](open-telemetry#5113))
- Stabilize sections of Prometheus and OpenMetrics Compatibility.
- Stabilize OpenTelemetry Histogram to Prometheus Histogram
transformation.

([open-telemetry#5091](open-telemetry#5091))
- Add optional OpenTelemetry Histogram to Prometheus Native Histogram
with Custom Buckets transformation.

([open-telemetry#5091](open-telemetry#5091))

### SDK Configuration

- Add link to declarative config IdGenerator type

([open-telemetry#5133](open-telemetry#5133))

### OTEPs

- Context-scoped Attributes.

([open-telemetry#4931](open-telemetry#4931))

---------

Co-authored-by: Reiley Yang <reyang@microsoft.com>
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.