Skip to content

feat: add Attributes to Scope and apply them to Logs and Metrics #4882

Open

Description

@Flash0ver

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.id

Current 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:

  1. Default attributes
  2. Scope attributes
  3. Per-call attributes
  4. SetBeforeSendLog / SetBeforeSendMetric

Work

Decisions needed

  1. Top-level API. The spec's Sentry.setAttributes writes to the isolation scope, but .NET has a single scope stack and no isolation scope. Proposal: SentrySdk.SetAttribute(s) targets the current scope, as SetTag does.
  2. 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?
  3. 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.
  4. Default attributes on metrics. Logs get server.address and user.*; metrics only get environment, release and SDK. Is closing that gap part of this issue?

Out of scope

Activity

  1. added
    .NET
    public API
    on Jan 29, 2026
  2. linear commented on Jan 29, 2026

    @linear
  3. Flash0ver commented on Feb 2, 2026

    @Flash0ver
    ContributorAuthor

    Naming hint: see #4834 (comment)

  4. self-assigned this
    on Feb 13, 2026
  5. Flash0ver commented on Mar 19, 2026

    @Flash0ver
    ContributorAuthor

    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. The Scope might 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.

  6. added
    Feature
    on Mar 20, 2026
  7. jamescrosswell commented on Mar 22, 2026

    @jamescrosswell
    Collaborator

    While at it, we may want to remove the Enricher, and instead push the information onto the "Root-Scope" at init-time

    @Flash0ver this might help with that (introduces a way to init properties on the root scope)...

  8. added
    Next Major
    and removed
    Next Major
    on May 27, 2026
  9. changed the title [-]feat: add Attributes APIs[/-] [+]feat: add Attributes to Scope and apply them to Logs and Metrics[/+] on Nov 9, 2026
  10. jamescrosswell commented on Nov 26, 2026

    @jamescrosswell
    Collaborator

    Folding in what's left of #4783, which is now closed:

    Also, #5892 (moving the Enricher data onto the root scope), listed under Out of scope above, was closed as superseded by ScopeDefaults (#5671).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETFeatureLogsMetricspublic API

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions