feat(core): [Global Attributes 1] Add scope-level attributes API#5118
Open
feat(core): [Global Attributes 1] Add scope-level attributes API#5118
Conversation
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>
Contributor
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛
Internal Changes 🔧Deps
🤖 This preview updates automatically when you update the PR. |
Contributor
|
Contributor
Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| b6cfb57 | 372.92 ms | 507.77 ms | 134.85 ms |
| ce0a49e | 532.00 ms | 609.96 ms | 77.96 ms |
| e59e22a | 374.68 ms | 442.14 ms | 67.46 ms |
| fc5ccaf | 256.80 ms | 322.36 ms | 65.56 ms |
| d15471f | 294.13 ms | 399.49 ms | 105.36 ms |
| d15471f | 303.49 ms | 439.08 ms | 135.59 ms |
| abfcc92 | 337.38 ms | 427.39 ms | 90.00 ms |
| ee35ac3 | 346.83 ms | 435.48 ms | 88.65 ms |
| d15471f | 322.58 ms | 396.08 ms | 73.50 ms |
| f634d01 | 359.58 ms | 433.88 ms | 74.30 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| b6cfb57 | 1.58 MiB | 2.28 MiB | 718.80 KiB |
| ce0a49e | 1.58 MiB | 2.10 MiB | 532.94 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 |
| abfcc92 | 1.58 MiB | 2.13 MiB | 557.31 KiB |
| ee35ac3 | 1.58 MiB | 2.13 MiB | 558.77 KiB |
| d15471f | 1.58 MiB | 2.13 MiB | 559.54 KiB |
| f634d01 | 1.58 MiB | 2.10 MiB | 533.40 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>
8 tasks
Member
Author
|
PR Stack (Global Attributes):
|
This was referenced Feb 26, 2026
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📜 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. TheCombinedScopeViewmerges 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
SentryAttributetype. A follow-up stacked PR will wire these attributes intoLoggerApiandMetricsApi.💚 How did you test it?
Scopeattribute operations (set, remove, getAttributes, setAttributes)CombinedScopeViewattribute merging across scope layers📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
LoggerApiandMetricsApi, including extracted factory methods (SentryAttributeType.inferFrom,SentryLogEventAttributeValue.fromAttribute)