Skip to content

feat(core): [Global Attributes 1] Add scope-level attributes API#5118

Merged
adinauer merged 7 commits intofeat/global-attributes-apifrom
feat/scope-attributes
Mar 3, 2026
Merged

feat(core): [Global Attributes 1] Add scope-level attributes API#5118
adinauer merged 7 commits intofeat/global-attributes-apifrom
feat/scope-attributes

Conversation

@adinauer
Copy link
Member

@adinauer adinauer commented Feb 26, 2026

📜 Description

Add a new API to set attributes on scopes (IScope, IScopes, Sentry). Attributes are key-value pairs (SentryAttribute) that can be set, removed, and queried from scopes. The CombinedScopeView merges attributes across scope layers (global, isolation, current) with the current scope taking precedence.

This lays the foundation for scope-level attributes that can be automatically attached to logs, metrics, and other events.

💡 Motivation and Context

Scope-level attributes allow users to set contextual key-value pairs that are automatically propagated to logs and metrics, similar to how tags work but using the structured SentryAttribute type. A follow-up stacked PR will wire these attributes into LoggerApi and MetricsApi.

💚 How did you test it?

  • Unit tests for Scope attribute operations (set, remove, getAttributes, setAttributes)
  • Unit tests for CombinedScopeView attribute merging across scope layers

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

  • Stacked PR to wire scope attributes into LoggerApi and MetricsApi, including extracted factory methods (SentryAttributeType.inferFrom, SentryLogEventAttributeValue.fromAttribute)

Add setAttribute, setAttributes, removeAttribute, and getAttributes
to IScope/IScopes/Sentry so users can set attributes on the scope
that are automatically included in logs and metrics events.

Also refactor type inference logic into SentryAttributeType.inferFrom
and add SentryLogEventAttributeValue.fromAttribute factory method,
removing duplicate getType helpers from LoggerApi and MetricsApi.

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions
Copy link
Contributor

github-actions bot commented Feb 26, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • (core) [Global Attributes 1] Add scope-level attributes API by adinauer in #5118
  • (otel) Create sentry-opentelemetry-otlp module for combining OpenTelemetry SDK OTLP export with Sentry SDK by adinauer in #5100
  • (screenshot) Add screenshot masking using view hierarchy by romtsn in #5077

Bug Fixes 🐛

  • (android) Remove AndroidRuntimeManager to prevent ANRs during SDK init by romtsn in #5127
  • (gestures) Use peekDecorView to not force view hierarchy construction by romtsn in #5134
  • (init) Reduce allocations and bytecode instructions during Sentry.init by romtsn in #5135
  • (transport) Handle HTTP 413 with actionable log and use send_error for HTTP errors by adinauer in #5115
  • Trim DSN string before URI parsing by adinauer in #5113
  • Safe unregister SystemEventsBroadcastReceiver by kollesnica1337 in #5106

Internal Changes 🔧

Deps

  • Bump getsentry/craft from 2.21.7 to 2.23.1 by dependabot in #5129
  • Update Native SDK to v0.13.1 by github-actions in #5104
  • Bump actions/upload-artifact from 6 to 7 by dependabot in #5130
  • Bump actions/download-artifact from 7 to 8 by dependabot in #5132
  • Bump gradle/actions from 5.0.1 to 5.0.2 by dependabot in #5131
  • Bump github/codeql-action from 4.32.2 to 4.32.4 by dependabot in #5109
  • Bump getsentry/craft from 2.21.2 to 2.21.7 by dependabot in #5110

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 26, 2026

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 1e7bcf5

@github-actions
Copy link
Contributor

github-actions bot commented Feb 26, 2026

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 287.45 ms 359.57 ms 72.12 ms
Size 1.58 MiB 2.29 MiB 722.93 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
91bb874 310.68 ms 359.24 ms 48.56 ms
e59e22a 368.02 ms 432.00 ms 63.98 ms
fc5ccaf 279.11 ms 353.34 ms 74.23 ms
d15471f 315.20 ms 370.22 ms 55.02 ms
d15471f 286.65 ms 314.68 ms 28.03 ms
d15471f 342.08 ms 415.44 ms 73.35 ms
ad8da22 314.38 ms 352.29 ms 37.91 ms
cf708bd 434.73 ms 502.96 ms 68.22 ms
abfcc92 309.54 ms 380.32 ms 70.78 ms
91bb874 314.47 ms 440.00 ms 125.53 ms

App size

Revision Plain With Sentry Diff
91bb874 1.58 MiB 2.13 MiB 559.07 KiB
e59e22a 1.58 MiB 2.20 MiB 635.34 KiB
fc5ccaf 1.58 MiB 2.13 MiB 557.54 KiB
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
ad8da22 1.58 MiB 2.29 MiB 719.83 KiB
cf708bd 1.58 MiB 2.11 MiB 539.71 KiB
abfcc92 1.58 MiB 2.13 MiB 557.31 KiB
91bb874 1.58 MiB 2.13 MiB 559.07 KiB

Previous results on branch: feat/scope-attributes

Startup times

Revision Plain With Sentry Diff
a1f07e7 405.02 ms 512.88 ms 107.86 ms
18e7c7e 306.83 ms 365.31 ms 58.47 ms

App size

Revision Plain With Sentry Diff
a1f07e7 1.58 MiB 2.29 MiB 719.88 KiB
18e7c7e 1.58 MiB 2.29 MiB 719.89 KiB

Move factory method extractions (SentryAttributeType.inferFrom,
SentryLogEventAttributeValue.fromAttribute) and LoggerApi/MetricsApi
scope attribute integration to a separate stacked PR.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@adinauer adinauer changed the title feat(core): Add scope-level attributes API feat(core): [Global Attributes #1] Add scope-level attributes API Feb 26, 2026
@adinauer adinauer changed the title feat(core): [Global Attributes #1] Add scope-level attributes API feat(core): [Global Attributes 1] Add scope-level attributes API Feb 26, 2026
@adinauer
Copy link
Member Author

PR Stack (Global Attributes):

  1. #5118 — Add scope-level attributes API
  2. #5120 — Wire scope attributes into LoggerApi and MetricsApi
  3. #5121 — Showcase scope attributes in Spring Boot 4 samples
  4. #5122 — Detect integer attribute type correctly for all integer Number subtypes
  5. #5124 — Support collections and arrays in log attribute type inference

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable autofix in the Cursor dashboard.

@adinauer adinauer changed the base branch from main to feat/global-attributes-api March 3, 2026 13:38
@adinauer adinauer merged commit 534ff79 into feat/global-attributes-api Mar 3, 2026
67 checks passed
@adinauer adinauer deleted the feat/scope-attributes branch March 3, 2026 14:31
@adinauer adinauer mentioned this pull request Mar 4, 2026
8 tasks
adinauer added a commit to getsentry/sentry-docs that referenced this pull request Mar 4, 2026
Add scope attributes sections to Java and Android logs/metrics usage
docs, showing how to set attributes on the scope that are automatically
included in all logs/metrics.

Covers `setAttribute` (with auto type inference), `SentryAttribute`
factory methods (for explicit typing), `setAttributes` (for multiple at
once), and `removeAttribute`. Examples are consistent across all four
platform-includes files (logs/metrics x java/android).

Also adds scope attributes references in the default-attributes docs for
Java logs and Android/Java metrics.

Co-Authored-By: Claude <noreply@anthropic.com>

PR Stack in SDK repo:
getsentry/sentry-java#5118 (comment)

Co-authored-by: Claude <noreply@anthropic.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.

2 participants