From 0a2a869de617821e84b5d94d30915f9e2ab9254b Mon Sep 17 00:00:00 2001 From: Antonis Lilis Date: Thu, 25 Jun 2026 16:48:20 +0200 Subject: [PATCH] feat(core): Expose top-level Sentry.setAttribute / setAttributes Re-export `setAttribute` and `setAttributes` from `@sentry/core` (added in 10.61.0) so RN users can call them directly instead of via `getCurrentScope().setAttribute(...)`. The top-level core functions delegate to the isolation scope, which the RN SDK already patches via `enableSyncToNative`, so primitive attributes sync to native for free. Co-Authored-By: Claude Opus 4.8 --- CHANGELOG.md | 1 + packages/core/etc/sentry-react-native.api.md | 6 ++++++ packages/core/src/js/index.ts | 2 ++ packages/core/test/scopeSync.test.ts | 4 ++-- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b0149b5ce3..00487b5f55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ ### Features +- Expose top-level `Sentry.setAttribute` and `Sentry.setAttributes` APIs ([#6354](https://github.com/getsentry/sentry-react-native/pull/6354)). - Use the runtime's native `btoa` for envelope base64 encoding when available, to improve `captureEnvelope` performance. Falls back to the bundled JS encoder if `btoa` is missing ([#6351](https://github.com/getsentry/sentry-react-native/pull/6351)). ## 8.16.0 diff --git a/packages/core/etc/sentry-react-native.api.md b/packages/core/etc/sentry-react-native.api.md index 8dedd50404..bcf86cf2e7 100644 --- a/packages/core/etc/sentry-react-native.api.md +++ b/packages/core/etc/sentry-react-native.api.md @@ -83,6 +83,8 @@ import { rewriteFramesIntegration } from '@sentry/react'; import { Scope } from '@sentry/core'; import { SdkInfo } from '@sentry/core'; import { SendFeedbackParams } from '@sentry/core'; +import { setAttribute } from '@sentry/core'; +import { setAttributes } from '@sentry/core'; import { setContext } from '@sentry/core'; import { setCurrentClient } from '@sentry/core'; import { setExtra } from '@sentry/core'; @@ -711,6 +713,10 @@ export interface SentryNavigationContainerProps { export function sentryTraceGesture( label: string, gesture: GestureT): GestureT; +export { setAttribute } + +export { setAttributes } + export { setContext } export { setCurrentClient } diff --git a/packages/core/src/js/index.ts b/packages/core/src/js/index.ts index 0aad8fb360..3b609bde18 100644 --- a/packages/core/src/js/index.ts +++ b/packages/core/src/js/index.ts @@ -24,6 +24,8 @@ export { captureFeedback, captureMessage, Scope, + setAttribute, + setAttributes, setContext, setExtra, setExtras, diff --git a/packages/core/test/scopeSync.test.ts b/packages/core/test/scopeSync.test.ts index 331f51a47d..a7bd54ac4c 100644 --- a/packages/core/test/scopeSync.test.ts +++ b/packages/core/test/scopeSync.test.ts @@ -226,7 +226,7 @@ describe('ScopeSync', () => { it('setAttribute', () => { expect(SentryCore.getIsolationScope().setAttribute).not.toBe(setAttributeScopeSpy); - SentryCore.getIsolationScope().setAttribute('session_id', 'abc123'); + SentryCore.setAttribute('session_id', 'abc123'); expect(NATIVE.setAttribute).toHaveBeenCalledExactlyOnceWith('session_id', 'abc123'); expect(setAttributeScopeSpy).toHaveBeenCalledExactlyOnceWith('session_id', 'abc123'); }); @@ -249,7 +249,7 @@ describe('ScopeSync', () => { it('setAttributes', () => { expect(SentryCore.getIsolationScope().setAttributes).not.toBe(setAttributesScopeSpy); - SentryCore.getIsolationScope().setAttributes({ + SentryCore.setAttributes({ session_type: 'test', request_count: 42, is_admin: true,