Skip to content

feat(core): [Global Attributes 2] Wire scope attributes into LoggerApi and MetricsApi#5120

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

feat(core): [Global Attributes 2] Wire scope attributes into LoggerApi and MetricsApi#5120
adinauer merged 3 commits intofeat/global-attributes-apifrom
feat/scope-attributes-logger-metrics

Conversation

@adinauer
Copy link
Member

Note

Stacked on #5118

📜 Description

Wire scope-level attributes into LoggerApi and MetricsApi so they are automatically included in log and metric events. Also extracts duplicated type-inference logic into reusable factory methods:

  • SentryAttributeType.inferFrom(Object) — infers the attribute type from a value
  • SentryLogEventAttributeValue.fromAttribute(SentryAttribute) — creates an attribute value from a SentryAttribute, inferring the type if not explicitly set

Both LoggerApi and MetricsApi now read scope attributes via getCombinedScopeView().getAttributes() and include them as the base set of attributes on every log/metric event (user-provided attributes take precedence).

💡 Motivation and Context

With scope-level attributes added in #5118, this PR completes the integration by ensuring those attributes flow through to logs and metrics automatically. The factory method extraction removes duplicated getType() methods that existed in both LoggerApi and MetricsApi.

💚 How did you test it?

📝 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

Extract factory methods SentryAttributeType.inferFrom and
SentryLogEventAttributeValue.fromAttribute to reduce duplication.
Apply scope attributes to log and metric events automatically.

Co-Authored-By: Claude Opus 4.6 <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 2] Wire scope attributes into LoggerApi and MetricsApi by adinauer in #5120
  • [Global Attributes 1] Add scope-level attributes API by adinauer in #5118
  • [Global Attributes 2] Wire scope attributes into LoggerApi and MetricsApi by adinauer in #5120

Other

  • (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

Fails
🚫 Please consider adding a changelog entry for the next release.
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

### Features

- [Global Attributes 2] Wire scope attributes into LoggerApi and MetricsApi ([#5120](https://github.com/getsentry/sentry-java/pull/5120))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description or adding a skip-changelog label.

Generated by 🚫 dangerJS against 4aaa380

@github-actions
Copy link
Contributor

github-actions bot commented Feb 26, 2026

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 326.41 ms 378.54 ms 52.13 ms
Size 1.58 MiB 2.29 MiB 722.94 KiB

Previous results on branch: feat/scope-attributes-logger-metrics

Startup times

Revision Plain With Sentry Diff
061649a 321.85 ms 379.12 ms 57.27 ms

App size

Revision Plain With Sentry Diff
061649a 1.58 MiB 2.29 MiB 719.89 KiB

@adinauer adinauer changed the title feat(core): Wire scope attributes into LoggerApi and MetricsApi feat(core): [Global Attributes 2]Wire scope attributes into LoggerApi and MetricsApi 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

@adinauer
Copy link
Member Author

@sentry review

@adinauer
Copy link
Member Author

cursor review

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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Base automatically changed from feat/scope-attributes to feat/global-attributes-api March 3, 2026 14:31
@adinauer adinauer merged commit d56444b into feat/global-attributes-api Mar 3, 2026
55 checks passed
@adinauer adinauer deleted the feat/scope-attributes-logger-metrics branch March 3, 2026 14:40
@adinauer adinauer changed the title feat(core): [Global Attributes 2]Wire scope attributes into LoggerApi and MetricsApi feat(core): [Global Attributes 2] Wire scope attributes into LoggerApi and MetricsApi Mar 3, 2026
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.

<meta-data android:name="io.sentry.screenshot.mask-all-text" android:value="true" />
<meta-data android:name="io.sentry.screenshot.mask-all-images" android:value="true" />
```
>>>>>>> feat/global-attributes-api
Copy link

Choose a reason for hiding this comment

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

Unresolved Git Merge Conflict in Changelog

Medium Severity

CHANGELOG.md contains unresolved git merge conflict markers (<<<<<<<, =======, >>>>>>>). These markers were accidentally committed and will appear verbatim in the published changelog, making it malformed and confusing to readers. Both conflict sides need to be manually reconciled and the markers removed before merging.

Fix in Cursor Fix in Web

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