Skip to content

Commit 9e77e9d

Browse files
nicohrubeccodex
andauthored
ref(core): Use user attribute constants from conventions (#24974)
Uses `USER_ID`, `USER_EMAIL`, `USER_IP_ADDRESS`, and `USER_NAME` from `@sentry/conventions/attributes`. Deprecates the existing core constants while preserving their public exports and identical attribute keys; emitted values and data-collection behavior remain unchanged. `USER_NAME` still maps the existing username to `user.name`. Part of #24961 / [JS-3868](https://linear.app/getsentry/issue/JS-3868). Co-authored-by: GPT-6 <codex@openai.com>
1 parent bd1012a commit 9e77e9d

4 files changed

Lines changed: 38 additions & 27 deletions

File tree

‎packages/core/src/integrations/requestdata.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { Client } from '../client';
22
import { getIsolationScope } from '../currentScopes';
33
import { defineIntegration } from '../integration';
4-
import { SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS } from '../semanticAttributes';
54
import type { SdkProcessingMetadata } from '../scope';
65
import type { CollectBehavior, ResolvedDataCollection } from '../types/datacollection';
76
import type { Event } from '../types/event';
@@ -19,7 +18,7 @@ import { getUrlQuery } from '../utils/url';
1918
import { getClientIPAddress } from '../utils/clientIPAddress';
2019
import { ipHeaderNames } from '../vendor/getIpAddress';
2120
import { safeSetSpanJSONAttributes } from '../tracing/spans/captureSpan';
22-
import { SENTRY_IS_LOCALHOST, URL_FULL, URL_QUERY } from '@sentry/conventions/attributes';
21+
import { SENTRY_IS_LOCALHOST, URL_FULL, URL_QUERY, USER_IP_ADDRESS } from '@sentry/conventions/attributes';
2322

2423
type RequestDataIncludeOptions = {
2524
cookies?: boolean;
@@ -262,7 +261,7 @@ function addNormalizedRequestDataToSpan(
262261
if (include.ip) {
263262
const ip = (normalizedRequest.headers && getClientIPAddress(normalizedRequest.headers)) || ipAddress || undefined;
264263
if (ip) {
265-
safeSetSpanJSONAttributes(span, { [SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS]: ip });
264+
safeSetSpanJSONAttributes(span, { [USER_IP_ADDRESS]: ip });
266265
}
267266
}
268267
}

‎packages/core/src/semanticAttributes.ts‎

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,25 @@ export const SEMANTIC_ATTRIBUTE_SENTRY_SDK_VERSION = 'sentry.sdk.version';
7474
/** The list of integrations enabled in the Sentry SDK (e.g., ["EventFilters", "BrowserTracing"]) */
7575
export const SEMANTIC_ATTRIBUTE_SENTRY_SDK_INTEGRATIONS = 'sentry.sdk.integrations';
7676

77-
/** The user ID */
77+
/**
78+
* The user ID
79+
* @deprecated Use `USER_ID` from `@sentry/conventions/attributes` instead.
80+
*/
7881
export const SEMANTIC_ATTRIBUTE_USER_ID = 'user.id';
79-
/** The user email */
82+
/**
83+
* The user email
84+
* @deprecated Use `USER_EMAIL` from `@sentry/conventions/attributes` instead.
85+
*/
8086
export const SEMANTIC_ATTRIBUTE_USER_EMAIL = 'user.email';
81-
/** The user IP address */
87+
/**
88+
* The user IP address
89+
* @deprecated Use `USER_IP_ADDRESS` from `@sentry/conventions/attributes` instead.
90+
*/
8291
export const SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS = 'user.ip_address';
83-
/** The user username */
92+
/**
93+
* The user username
94+
* @deprecated Use `USER_NAME` from `@sentry/conventions/attributes` instead.
95+
*/
8496
export const SEMANTIC_ATTRIBUTE_USER_USERNAME = 'user.name';
8597

8698
/**

‎packages/core/src/tracing/spans/captureSpan.ts‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ import {
55
SEMANTIC_ATTRIBUTE_SENTRY_ENVIRONMENT,
66
SEMANTIC_ATTRIBUTE_SENTRY_RELEASE,
77
SEMANTIC_ATTRIBUTE_SENTRY_SDK_INTEGRATIONS,
8-
SEMANTIC_ATTRIBUTE_USER_EMAIL,
9-
SEMANTIC_ATTRIBUTE_USER_ID,
10-
SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS,
11-
SEMANTIC_ATTRIBUTE_USER_USERNAME,
128
} from '../../semanticAttributes';
139
import type { SerializedStreamedSpan, Span, SpanAttributeValue, SpanJSON, StreamedSpanJSON } from '../../types/span';
1410
import { getCombinedScopeData } from '../../utils/scopeData';
@@ -29,6 +25,10 @@ import {
2925
SENTRY_SEGMENT_ID,
3026
SENTRY_SEGMENT_NAME,
3127
SENTRY_TRACE_LIFECYCLE,
28+
USER_EMAIL,
29+
USER_ID,
30+
USER_IP_ADDRESS,
31+
USER_NAME,
3232
} from '@sentry/conventions/attributes';
3333

3434
export type SerializedStreamedSpanWithSegmentSpan = SerializedStreamedSpan & {
@@ -138,10 +138,10 @@ function commonSpanAttributes(
138138
[SENTRY_SDK_VERSION]: sdk?.sdk?.version,
139139
[SEMANTIC_ATTRIBUTE_SENTRY_RELEASE]: release,
140140
[SEMANTIC_ATTRIBUTE_SENTRY_ENVIRONMENT]: environment || DEFAULT_ENVIRONMENT,
141-
[SEMANTIC_ATTRIBUTE_USER_ID]: scopeData.user?.id,
142-
[SEMANTIC_ATTRIBUTE_USER_EMAIL]: scopeData.user?.email,
143-
[SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS]: scopeData.user?.ip_address,
144-
[SEMANTIC_ATTRIBUTE_USER_USERNAME]: scopeData.user?.username,
141+
[USER_ID]: scopeData.user?.id,
142+
[USER_EMAIL]: scopeData.user?.email,
143+
[USER_IP_ADDRESS]: scopeData.user?.ip_address,
144+
[USER_NAME]: scopeData.user?.username,
145145
...(includeScopeAttributes ? scopeData.attributes : undefined),
146146
};
147147
}

‎packages/core/test/lib/tracing/spans/captureSpan.test.ts‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ import {
99
SEMANTIC_ATTRIBUTE_SENTRY_RELEASE,
1010
SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE,
1111
SEMANTIC_ATTRIBUTE_SENTRY_SDK_INTEGRATIONS,
12-
SEMANTIC_ATTRIBUTE_USER_EMAIL,
13-
SEMANTIC_ATTRIBUTE_USER_ID,
14-
SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS,
15-
SEMANTIC_ATTRIBUTE_USER_USERNAME,
1612
spanStreamingIntegration,
1713
startInactiveSpan,
1814
startSpan,
@@ -33,6 +29,10 @@ import {
3329
SENTRY_SEGMENT_NAME,
3430
SENTRY_SEGMENT_NAME_SOURCE,
3531
SENTRY_TRACE_LIFECYCLE,
32+
USER_EMAIL,
33+
USER_ID,
34+
USER_IP_ADDRESS,
35+
USER_NAME,
3636
} from '@sentry/conventions/attributes';
3737

3838
describe('captureSpan', () => {
@@ -109,19 +109,19 @@ describe('captureSpan', () => {
109109
value: 'staging',
110110
type: 'string',
111111
},
112-
[SEMANTIC_ATTRIBUTE_USER_ID]: {
112+
[USER_ID]: {
113113
value: '123',
114114
type: 'string',
115115
},
116-
[SEMANTIC_ATTRIBUTE_USER_EMAIL]: {
116+
[USER_EMAIL]: {
117117
value: 'user@example.com',
118118
type: 'string',
119119
},
120-
[SEMANTIC_ATTRIBUTE_USER_USERNAME]: {
120+
[USER_NAME]: {
121121
value: 'testuser',
122122
type: 'string',
123123
},
124-
[SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS]: {
124+
[USER_IP_ADDRESS]: {
125125
value: '127.0.0.1',
126126
type: 'string',
127127
},
@@ -217,19 +217,19 @@ describe('captureSpan', () => {
217217
value: '1.0.0',
218218
type: 'string',
219219
},
220-
[SEMANTIC_ATTRIBUTE_USER_ID]: {
220+
[USER_ID]: {
221221
value: '123',
222222
type: 'string',
223223
},
224-
[SEMANTIC_ATTRIBUTE_USER_EMAIL]: {
224+
[USER_EMAIL]: {
225225
value: 'user@example.com',
226226
type: 'string',
227227
},
228-
[SEMANTIC_ATTRIBUTE_USER_USERNAME]: {
228+
[USER_NAME]: {
229229
value: 'testuser',
230230
type: 'string',
231231
},
232-
[SEMANTIC_ATTRIBUTE_USER_IP_ADDRESS]: {
232+
[USER_IP_ADDRESS]: {
233233
value: '127.0.0.1',
234234
type: 'string',
235235
},

0 commit comments

Comments
 (0)