SIGN IN SIGN UP

feat(core): Global Attributes API (#5148)

* feat(core): Add scope-level attributes API

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>

* changelog

* ref: Split out LoggerApi/MetricsApi changes for stacked PR

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>

* feat(core): Wire scope attributes into LoggerApi and MetricsApi

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>

* changelog

* feat(samples): Showcase scope attributes in Spring Boot 4 samples

Add Sentry.setAttribute() calls to PersonController and
MetricController across all Spring Boot 4 sample variants to
demonstrate scope attributes being auto-attached to logs and metrics.

Add e2e test assertions and TestHelper methods to verify scope
attributes appear on captured log and metric events.

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

* changelog

* Revert "changelog"

This reverts commit 7189bdca1a211085608f16bf3443c9e6675b6680.

* ref: Remove redundant comments from variant controllers

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

* ref: Limit scope attributes sample to base Spring Boot 4 variant

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

* fix: Detect integer attribute type correctly for all integer Number subtypes

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

* changelog

* feat: Support collections and arrays in log attribute type inference

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

* changelog

* use ConcurrentHashMap instead of HashMap when merging attributes

* add enabled check similar to tags

* make setAttribute and setAttributes params nullable

* test: Add coverage for arrayAttribute factory method

Add arrayAttribute and named array attribute usage to the four
attribute tests in ScopesTest (log, count metric, distribution metric,
gauge metric) to verify the factory method works end-to-end.

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

* feat: Add Object[] overload to arrayAttribute factory

The arrayAttribute() factory only accepted Collection<?>, but
inferFrom() also handles native Java arrays. Add an Object[] overload
so users can pass object arrays like String[] directly without
falling back to the untyped named() method.

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

* shape changelog

---------

Co-authored-by: Claude <noreply@anthropic.com>
A
Alexander Dinauer committed
4b1510b40662a2a659349416da2eae5caa61a8c2
Parent: 815e034
Committed by GitHub <noreply@github.com> on 3/4/2026, 8:56:18 AM