Skip to content

Commit c88a958

Browse files
msonnbcodex
andauthored
ref(browser): Use convention constants for attribute keys (#25895)
**Why:** Use shared constants for culture, profiling thread, and background-tab attributes so these keys come from conventions. **How to review:** Compare each imported constant with the literal it replaces; emitted attribute names stay unchanged. Co-authored-by: GPT-6 <codex@openai.com>
1 parent 1cd91ed commit c88a958

3 files changed

Lines changed: 9 additions & 7 deletions

File tree

‎packages/browser/src/integrations/culturecontext.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { CULTURE_CALENDAR, CULTURE_LOCALE, CULTURE_TIMEZONE } from '@sentry/conventions/attributes';
12
import type { CultureContext, IntegrationFn } from '@sentry/core';
23
import { defineIntegration, safeSetSpanJSONAttributes } from '@sentry/core';
34
import { WINDOW } from '../helpers';
@@ -22,9 +23,9 @@ const _cultureContextIntegration = (() => {
2223

2324
if (culture) {
2425
safeSetSpanJSONAttributes(span, {
25-
'culture.locale': culture.locale,
26-
'culture.timezone': culture.timezone,
27-
'culture.calendar': culture.calendar,
26+
[CULTURE_LOCALE]: culture.locale,
27+
[CULTURE_TIMEZONE]: culture.timezone,
28+
[CULTURE_CALENDAR]: culture.calendar,
2829
});
2930
}
3031
},

‎packages/browser/src/profiling/utils.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { THREAD_ID, THREAD_NAME } from '@sentry/conventions/attributes';
12
/* eslint-disable max-lines */
23
import type { Client, ContinuousThreadCpuProfile, DebugImage, ProfileChunk, Span } from '@sentry/core';
34
import {
@@ -306,6 +307,6 @@ export function shouldProfileSession(options: BrowserOptions): boolean {
306307
}
307308

308309
export function setThreadAttributes(span: Span): void {
309-
span.setAttribute('thread.id', PROFILER_THREAD_ID_STRING);
310-
span.setAttribute('thread.name', PROFILER_THREAD_NAME);
310+
span.setAttribute(THREAD_ID, PROFILER_THREAD_ID_STRING);
311+
span.setAttribute(THREAD_NAME, PROFILER_THREAD_NAME);
311312
}

‎packages/browser/src/tracing/backgroundtab.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { debug, getActiveSpan, getRootSpan, SPAN_STATUS_ERROR, spanToJSON } from '@sentry/core';
22
import { DEBUG_BUILD } from '../debug-build';
33
import { WINDOW } from '../helpers';
4-
import { SENTRY_OP } from '@sentry/conventions/attributes';
4+
import { SENTRY_OP, SENTRY_CANCELLATION_REASON } from '@sentry/conventions/attributes';
55

66
/**
77
* Add a listener that cancels and finishes a transaction when the global
@@ -35,7 +35,7 @@ export function registerBackgroundTabDetection(): void {
3535
rootSpan.setStatus({ code: SPAN_STATUS_ERROR, message: cancelledStatus });
3636
}
3737

38-
rootSpan.setAttribute('sentry.cancellation_reason', 'document.hidden');
38+
rootSpan.setAttribute(SENTRY_CANCELLATION_REASON, 'document.hidden');
3939
rootSpan.end();
4040
}
4141
});

0 commit comments

Comments
 (0)