Skip to content

Commit 4ceab6c

Browse files
nicohrubeccodex
andauthored
ref(core): Use status message constant from conventions (#24967)
Uses `SENTRY_STATUS_MESSAGE` from `@sentry/conventions/attributes` in span serialization and existing constant-based tests. Deprecates the existing core constant while preserving its public export and the identical `sentry.status.message` key. Part of #24961 / [JS-3868](https://linear.app/getsentry/issue/JS-3868). Co-authored-by: GPT-6 <codex@openai.com>
1 parent 4ff3673 commit 4ceab6c

7 files changed

Lines changed: 35 additions & 61 deletions

File tree

‎dev-packages/browser-integration-tests/suites/public-api/startSpan/streamed/test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
77
SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE,
88
SEMANTIC_ATTRIBUTE_SENTRY_SDK_INTEGRATIONS,
9-
SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE,
109
} from '@sentry/core';
1110
import { sentryTest } from '../../../../utils/fixtures';
1211
import { shouldSkipTracingTest } from '../../../../utils/helpers';
@@ -19,6 +18,7 @@ import {
1918
SENTRY_SDK_VERSION,
2019
SENTRY_TRACE_LIFECYCLE,
2120
USER_AGENT_ORIGINAL,
21+
SENTRY_STATUS_MESSAGE,
2222
} from '@sentry/conventions/attributes';
2323

2424
sentryTest(
@@ -195,7 +195,7 @@ sentryTest(
195195
type: 'string',
196196
value: 'production',
197197
},
198-
[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]: {
198+
[SENTRY_STATUS_MESSAGE]: {
199199
type: 'string',
200200
value: 'Connection Refused',
201201
},

‎packages/core/src/semanticAttributes.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN = 'sentry.origin';
3131
* Streamed (v2) span statuses are reduced to `ok`/`error`, so we preserve the
3232
* message as an attribute instead of dropping it. This mirrors the attribute
3333
* Sentry's OTLP ingestion uses for the same purpose.
34+
* @deprecated Use `SENTRY_STATUS_MESSAGE` from `@sentry/conventions/attributes` instead.
3435
*/
3536
export const SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE = 'sentry.status.message';
3637

‎packages/core/src/utils/spanUtils.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@ import { serializeAttributes } from '../attributes';
55
import { getMainCarrier } from '../carrier';
66
import { getCurrentScope } from '../currentScopes';
77
import type { Scope } from '../scope';
8-
import { SENTRY_SEGMENT_NAME_SOURCE } from '@sentry/conventions/attributes';
8+
import { SENTRY_SEGMENT_NAME_SOURCE, SENTRY_STATUS_MESSAGE } from '@sentry/conventions/attributes';
99
import {
1010
SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME,
1111
SEMANTIC_ATTRIBUTE_SENTRY_OP,
1212
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
13-
SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE,
1413
} from '../semanticAttributes';
1514
import type { SentrySpan } from '../tracing/sentrySpan';
1615
import { isStatusErrorMessageValid, SPAN_STATUS_OK, SPAN_STATUS_UNSET } from '../tracing/spanstatus';
@@ -346,7 +345,7 @@ export function getSimpleStatus(status: SpanStatus | undefined): 'ok' | 'error'
346345
}
347346

348347
/**
349-
* Returns the span's attributes with the SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE attribute added
348+
* Returns the span's attributes with the SENTRY_STATUS_MESSAGE attribute added
350349
* if the span has an error status message worth preserving.
351350
*
352351
* An explicitly set attribute is never overwritten.
@@ -357,7 +356,7 @@ export function addStatusMessageAttribute(
357356
): RawAttributes<Record<string, unknown>> {
358357
const statusMessage = getSimpleStatus(status) === 'error' ? status?.message : undefined;
359358
return {
360-
...(statusMessage && { [SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]: statusMessage }),
359+
...(statusMessage && { [SENTRY_STATUS_MESSAGE]: statusMessage }),
361360
...attributes,
362361
};
363362
}

‎packages/core/test/lib/tracing/errors.test.ts‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
1+
import { SENTRY_STATUS_MESSAGE } from '@sentry/conventions/attributes';
12
import { beforeEach, describe, expect, it, vi } from 'vitest';
2-
import {
3-
SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE,
4-
setCurrentClient,
5-
spanToJSON,
6-
startInactiveSpan,
7-
startSpan,
8-
} from '../../../src';
3+
import { setCurrentClient, spanToJSON, startInactiveSpan, startSpan } from '../../../src';
94
import * as globalErrorModule from '../../../src/instrument/globalError';
105
import * as globalUnhandledRejectionModule from '../../../src/instrument/globalUnhandledRejection';
116
import { _resetErrorsInstrumented, registerSpanErrorInstrumentation } from '../../../src/tracing/errors';
@@ -67,7 +62,7 @@ describe('registerErrorHandlers()', () => {
6762
mockErrorCallback({} as HandlerDataError);
6863
const { status, attributes } = spanToJSON(span);
6964
expect(status).toBe('error');
70-
expect(attributes[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).toBe('internal_error');
65+
expect(attributes[SENTRY_STATUS_MESSAGE]).toBe('internal_error');
7166
});
7267
});
7368

@@ -78,7 +73,7 @@ describe('registerErrorHandlers()', () => {
7873
mockUnhandledRejectionCallback({});
7974
const { status, attributes } = spanToJSON(span);
8075
expect(status).toBe('error');
81-
expect(attributes[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).toBe('internal_error');
76+
expect(attributes[SENTRY_STATUS_MESSAGE]).toBe('internal_error');
8277
});
8378
});
8479
});

‎packages/core/test/lib/tracing/idleSpan.test.ts‎

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
getIsolationScope,
99
getTraceData,
1010
SEMANTIC_ATTRIBUTE_SENTRY_IDLE_SPAN_FINISH_REASON,
11-
SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE,
1211
SentryNonRecordingSpan,
1312
SentrySpan,
1413
setCurrentClient,
@@ -23,7 +22,7 @@ import type { Event } from '../../../src/types/event';
2322
import type { Span } from '../../../src/types/span';
2423
import { getDefaultTestClientOptions, TestClient } from '../../mocks/client';
2524
import { resetGlobals } from '../../testutils';
26-
import { SENTRY_SEGMENT_NAME_SOURCE } from '@sentry/conventions/attributes';
25+
import { SENTRY_SEGMENT_NAME_SOURCE, SENTRY_STATUS_MESSAGE } from '@sentry/conventions/attributes';
2726

2827
const dsn = 'https://123@sentry.io/42';
2928

@@ -677,23 +676,17 @@ describe('startIdleSpan', () => {
677676
// Start any span to cancel idle timeout
678677
startInactiveSpan({ name: 'span' });
679678

680-
expect(spanToJSON(idleSpan).attributes[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).not.toEqual(
681-
'deadline_exceeded',
682-
);
679+
expect(spanToJSON(idleSpan).attributes[SENTRY_STATUS_MESSAGE]).not.toEqual('deadline_exceeded');
683680
expect(spanToJSON(idleSpan).end_timestamp).toBeUndefined();
684681

685682
// Wait some time
686683
vi.advanceTimersByTime(TRACING_DEFAULTS.childSpanTimeout - 1000);
687-
expect(spanToJSON(idleSpan).attributes[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).not.toEqual(
688-
'deadline_exceeded',
689-
);
684+
expect(spanToJSON(idleSpan).attributes[SENTRY_STATUS_MESSAGE]).not.toEqual('deadline_exceeded');
690685
expect(spanToJSON(idleSpan).end_timestamp).toBeUndefined();
691686

692687
// Wait for timeout to exceed
693688
vi.advanceTimersByTime(1000);
694-
expect(spanToJSON(idleSpan).attributes[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).not.toEqual(
695-
'deadline_exceeded',
696-
);
689+
expect(spanToJSON(idleSpan).attributes[SENTRY_STATUS_MESSAGE]).not.toEqual('deadline_exceeded');
697690
expect(spanToJSON(idleSpan).end_timestamp).toBeDefined();
698691
});
699692

@@ -704,41 +697,31 @@ describe('startIdleSpan', () => {
704697
// Start any span to cancel idle timeout
705698
startInactiveSpan({ name: 'span' });
706699

707-
expect(spanToJSON(idleSpan).attributes[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).not.toEqual(
708-
'deadline_exceeded',
709-
);
700+
expect(spanToJSON(idleSpan).attributes[SENTRY_STATUS_MESSAGE]).not.toEqual('deadline_exceeded');
710701
expect(spanToJSON(idleSpan).end_timestamp).toBeUndefined();
711702

712703
// Wait some time
713704
vi.advanceTimersByTime(TRACING_DEFAULTS.childSpanTimeout - 1000);
714-
expect(spanToJSON(idleSpan).attributes[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).not.toEqual(
715-
'deadline_exceeded',
716-
);
705+
expect(spanToJSON(idleSpan).attributes[SENTRY_STATUS_MESSAGE]).not.toEqual('deadline_exceeded');
717706
expect(spanToJSON(idleSpan).end_timestamp).toBeUndefined();
718707

719708
// New span resets the timeout
720709
startInactiveSpan({ name: 'span' });
721710

722711
vi.advanceTimersByTime(TRACING_DEFAULTS.childSpanTimeout - 1000);
723-
expect(spanToJSON(idleSpan).attributes[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).not.toEqual(
724-
'deadline_exceeded',
725-
);
712+
expect(spanToJSON(idleSpan).attributes[SENTRY_STATUS_MESSAGE]).not.toEqual('deadline_exceeded');
726713
expect(spanToJSON(idleSpan).end_timestamp).toBeUndefined();
727714

728715
// New span resets the timeout
729716
startInactiveSpan({ name: 'span' });
730717

731718
vi.advanceTimersByTime(TRACING_DEFAULTS.childSpanTimeout - 1000);
732-
expect(spanToJSON(idleSpan).attributes[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).not.toEqual(
733-
'deadline_exceeded',
734-
);
719+
expect(spanToJSON(idleSpan).attributes[SENTRY_STATUS_MESSAGE]).not.toEqual('deadline_exceeded');
735720
expect(spanToJSON(idleSpan).end_timestamp).toBeUndefined();
736721

737722
// Wait for timeout to exceed
738723
vi.advanceTimersByTime(1000);
739-
expect(spanToJSON(idleSpan).attributes[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).not.toEqual(
740-
'deadline_exceeded',
741-
);
724+
expect(spanToJSON(idleSpan).attributes[SENTRY_STATUS_MESSAGE]).not.toEqual('deadline_exceeded');
742725
expect(spanToJSON(idleSpan).end_timestamp).toBeDefined();
743726
});
744727

@@ -751,9 +734,7 @@ describe('startIdleSpan', () => {
751734

752735
// Wait some time
753736
vi.advanceTimersByTime(TRACING_DEFAULTS.childSpanTimeout - 1000);
754-
expect(spanToJSON(idleSpan).attributes[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).not.toEqual(
755-
'deadline_exceeded',
756-
);
737+
expect(spanToJSON(idleSpan).attributes[SENTRY_STATUS_MESSAGE]).not.toEqual('deadline_exceeded');
757738
expect(spanToJSON(idleSpan).end_timestamp).toBeUndefined();
758739

759740
// new standalone span should not reset the timeout
@@ -762,9 +743,7 @@ describe('startIdleSpan', () => {
762743

763744
// Wait for timeout to exceed
764745
vi.advanceTimersByTime(1001);
765-
expect(spanToJSON(idleSpan).attributes[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).not.toEqual(
766-
'deadline_exceeded',
767-
);
746+
expect(spanToJSON(idleSpan).attributes[SENTRY_STATUS_MESSAGE]).not.toEqual('deadline_exceeded');
768747
expect(spanToJSON(idleSpan).end_timestamp).toBeDefined();
769748
});
770749
});

‎packages/core/test/lib/tracing/spanstatus.test.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { SENTRY_STATUS_MESSAGE } from '@sentry/conventions/attributes';
12
import { describe, expect, it } from 'vitest';
2-
import { SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE, SentrySpan, setHttpStatus, spanToJSON } from '../../../src/index';
3+
import { SentrySpan, setHttpStatus, spanToJSON } from '../../../src/index';
34

45
describe('setHttpStatus', () => {
56
it.each([
@@ -24,7 +25,7 @@ describe('setHttpStatus', () => {
2425
const { status: spanStatus, attributes } = spanToJSON(span);
2526

2627
expect(spanStatus).toBe(status);
27-
expect(attributes[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).toBe(statusMessage);
28+
expect(attributes[SENTRY_STATUS_MESSAGE]).toBe(statusMessage);
2829
expect(attributes).toMatchObject({ 'http.response.status_code': code });
2930
});
3031

@@ -36,7 +37,7 @@ describe('setHttpStatus', () => {
3637
const { status: spanStatus, attributes } = spanToJSON(span);
3738

3839
expect(spanStatus).toBe('error');
39-
expect(attributes[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).toBe('internal_error');
40+
expect(attributes[SENTRY_STATUS_MESSAGE]).toBe('internal_error');
4041
expect(attributes).toMatchObject({ 'http.response.status_code': 600 });
4142
});
4243
});

‎packages/core/test/lib/utils/spanUtils.test.ts‎

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { SENTRY_LINK_TYPE } from '@sentry/conventions/attributes';
1+
import { SENTRY_LINK_TYPE, SENTRY_STATUS_MESSAGE } from '@sentry/conventions/attributes';
22
import { beforeEach, describe, expect, it, test } from 'vitest';
33
import {
44
convertSpanLinksForEnvelope,
55
getCurrentScope,
66
Scope,
77
SEMANTIC_ATTRIBUTE_SENTRY_OP,
88
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
9-
SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE,
109
SentryNonRecordingSpan,
1110
SentrySpan,
1211
setCurrentClient,
@@ -510,7 +509,7 @@ describe('spanToStaticSpanJSON', () => {
510509

511510
const json = spanToJSON(span);
512511
expect(json.status).toBe('error');
513-
expect(json.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).toBe('Connection Refused');
512+
expect(json.attributes?.[SENTRY_STATUS_MESSAGE]).toBe('Connection Refused');
514513
});
515514

516515
it('does not set a status message for ok spans', () => {
@@ -519,7 +518,7 @@ describe('spanToStaticSpanJSON', () => {
519518

520519
const json = spanToJSON(span);
521520
expect(json.status).toBe('ok');
522-
expect(json.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).toBeUndefined();
521+
expect(json.attributes?.[SENTRY_STATUS_MESSAGE]).toBeUndefined();
523522
});
524523

525524
it('does not set a status message for error spans without a message', () => {
@@ -528,7 +527,7 @@ describe('spanToStaticSpanJSON', () => {
528527

529528
const json = spanToJSON(span);
530529
expect(json.status).toBe('error');
531-
expect(json.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).toBeUndefined();
530+
expect(json.attributes?.[SENTRY_STATUS_MESSAGE]).toBeUndefined();
532531
});
533532

534533
it('treats a cancelled status as ok and does not set a status message', () => {
@@ -537,18 +536,18 @@ describe('spanToStaticSpanJSON', () => {
537536

538537
const json = spanToJSON(span);
539538
expect(json.status).toBe('ok');
540-
expect(json.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).toBeUndefined();
539+
expect(json.attributes?.[SENTRY_STATUS_MESSAGE]).toBeUndefined();
541540
});
542541

543542
it('does not overwrite an explicitly set sentry.status.message attribute', () => {
544543
const span = new SentrySpan({
545544
name: 'test name',
546-
attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]: 'explicit message' },
545+
attributes: { [SENTRY_STATUS_MESSAGE]: 'explicit message' },
547546
});
548547
span.setStatus({ code: SPAN_STATUS_ERROR, message: 'Connection Refused' });
549548

550549
const json = spanToJSON(span);
551-
expect(json.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).toBe('explicit message');
550+
expect(json.attributes?.[SENTRY_STATUS_MESSAGE]).toBe('explicit message');
552551
});
553552
});
554553
describe('OpenTelemetry Span', () => {
@@ -619,7 +618,7 @@ describe('spanToStaticSpanJSON', () => {
619618
attr2: 2,
620619
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'test op',
621620
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto',
622-
[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]: 'unknown_error',
621+
[SENTRY_STATUS_MESSAGE]: 'unknown_error',
623622
},
624623
links: [
625624
{
@@ -647,7 +646,7 @@ describe('spanToStaticSpanJSON', () => {
647646

648647
const json = spanToJSON(span);
649648
expect(json.status).toBe('error');
650-
expect(json.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).toBe('Connection Refused');
649+
expect(json.attributes?.[SENTRY_STATUS_MESSAGE]).toBe('Connection Refused');
651650
});
652651

653652
it('does not set a status message for ok/unset spans', () => {
@@ -663,7 +662,7 @@ describe('spanToStaticSpanJSON', () => {
663662

664663
const json = spanToJSON(span);
665664
expect(json.status).toBe('ok');
666-
expect(json.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).toBeUndefined();
665+
expect(json.attributes?.[SENTRY_STATUS_MESSAGE]).toBeUndefined();
667666
});
668667
});
669668
});

0 commit comments

Comments
 (0)