Repository navigation
Open
Labels
.NETPull requests that update .net codeFeatureNew feature or requestLogsMetricspublic APIAdditions/modifications to, or removals from, the public API surface area.
Description
Problem
Attributes can only be set on one log or metric at a time. There is no way to set an attribute once and have it apply to every log and metric captured in a scope, which the Attributes spec requires.
// Proposed
SentrySdk.ConfigureScope(scope => scope.SetAttribute("tenant.id", "acme"));
SentrySdk.Logger.LogInfo("Order placed"); // has tenant.id
SentrySdk.Metrics.EmitCounter("orders.placed", 1); // has tenant.idCurrent state and target
| Area | Today | Target |
|---|---|---|
| Attributes on a single log | Done: SentryLog.SetAttribute, configureLog, SetBeforeSendLog |
No change |
| Attributes on a single metric | Done: Emit* attributes parameter, SentryMetric.SetAttribute, SetBeforeSendMetric |
No change |
| Attributes on a scope | Not available | SetAttribute, SetAttributes and RemoveAttribute on Scope |
| Scope attributes on logs and metrics | Not applied | Applied at capture |
| Per-call vs default attributes on logs | Defaults win (bug) | Per-call wins |
| Per-call vs default attributes on metrics | Per-call wins | No change |
| Units on attributes | No unit field | None yet, but the API must allow adding them without a breaking change (per spec) |
Target precedence
Later entries overwrite earlier ones, for both logs and metrics:
- Default attributes
- Scope attributes
- Per-call attributes
SetBeforeSendLog/SetBeforeSendMetric
Work
- Store attributes on
Scopeand add the public methods. Include them inClone,Apply(Scope)andClear. - Apply scope attributes to logs and metrics at capture. Name the internal method
SetScopeAttributesrather thanApply*(discussion). - Fix the log ordering: The SetDefaultAttributes call in CaptureLog overwrites user-set attributes from the configureLog callback #5351
- Add tests covering the full precedence order for logs and metrics.
Decisions needed
- Top-level API. The spec's
Sentry.setAttributeswrites to the isolation scope, but .NET has a single scope stack and no isolation scope. Proposal:SentrySdk.SetAttribute(s)targets the current scope, asSetTagdoes. - Log ordering fix. Is The SetDefaultAttributes call in CaptureLog overwrites user-set attributes from the configureLog callback #5351 a patch, or a behaviour change for v7?
- Array values. They are currently converted with
ToString. The spec accepts homogeneous primitive arrays, but they aren't visible in the Sentry UI yet. Proposal: defer. - Default attributes on metrics. Logs get
server.addressanduser.*; metrics only get environment, release and SDK. Is closing that gap part of this issue?
Out of scope
ILogger.BeginScopeattributes: feat: supportBeginScopeofMicrosoft.Extensions.Loggingfor Structured Logs #5222 (logger-scope attributes will sit above Sentry scope attributes)- Attributes on spans, which wait for streaming spans
- Attributes on error events, and replacing Tags and Extras: Remove Obsolete Extra members #4640
- Moving
Enricherdata onto the root scope: ref: move static data from Enricher onto the root Scope #5892 - Simplifying
IEventLike: ref: simplify the IEventLike interface hierarchy #5893
Metadata
Metadata
Assignees
Labels
.NETPull requests that update .net codeFeatureNew feature or requestLogsMetricspublic APIAdditions/modifications to, or removals from, the public API surface area.
Activity
linear commentedon Jan 29, 2026
NET-573
Flash0ver commentedon Feb 2, 2026
Naming hint: see #4834 (comment)
Flash0ver commentedon Mar 19, 2026
While at it, we may want to remove the
Enricher, and instead push the information onto the "Root-Scope" at init-time, which is then applied to Events and such. TheScopemight have various internal (extension) methods ("base" ApplyTo, "ApplyToFeedback", ...).Another layer of complexity we could simplify is the
IEventLike-hierarchy of interfaces.Thanks @bitsandfoxes for the input ... I'll come back to that once we "Scope-ify" our infrastructure.
jamescrosswell commentedon Mar 22, 2026
@Flash0ver this might help with that (introduces a way to init properties on the root scope)...
[-]feat: add Attributes APIs[/-][+]feat: add Attributes to Scope and apply them to Logs and Metrics[/+]jamescrosswell commentedon Nov 26, 2026
Folding in what's left of #4783, which is now closed:
SetDefaultAttributes(options, scope)(fix: populate Default attributes on structured logs from current scope #5216). Release, environment and SDK are resolved once at init intoScopeDefaults(feat!: resolve release, environment and SDK name once at init for all telemetry #5671), which events, check-ins, logs and metrics all use.Scope.EnvironmentorScope.Sdkset by the app, but takesentry.releasefromScopeDefaultsand ignoreScope.Release(SentryAttributes.SetDefaultAttributes). Draft PR fix: fetch default attributes fromScopefirst #5376 makes the scope win.Also, #5892 (moving the
Enricherdata onto the root scope), listed under Out of scope above, was closed as superseded byScopeDefaults(#5671).