diff --git a/dev-packages/browser-integration-tests/suites/public-api/startSpan/streamed/test.ts b/dev-packages/browser-integration-tests/suites/public-api/startSpan/streamed/test.ts index 62d8bd9c6366..31cc5c7d3853 100644 --- a/dev-packages/browser-integration-tests/suites/public-api/startSpan/streamed/test.ts +++ b/dev-packages/browser-integration-tests/suites/public-api/startSpan/streamed/test.ts @@ -6,7 +6,6 @@ import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SDK_INTEGRATIONS, - SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE, } from '@sentry/core'; import { sentryTest } from '../../../../utils/fixtures'; import { shouldSkipTracingTest } from '../../../../utils/helpers'; @@ -19,6 +18,7 @@ import { SENTRY_SDK_VERSION, SENTRY_TRACE_LIFECYCLE, USER_AGENT_ORIGINAL, + SENTRY_STATUS_MESSAGE, } from '@sentry/conventions/attributes'; sentryTest( @@ -195,7 +195,7 @@ sentryTest( type: 'string', value: 'production', }, - [SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]: { + [SENTRY_STATUS_MESSAGE]: { type: 'string', value: 'Connection Refused', }, diff --git a/packages/core/src/semanticAttributes.ts b/packages/core/src/semanticAttributes.ts index 4c1ce43c42cd..198f2515018b 100644 --- a/packages/core/src/semanticAttributes.ts +++ b/packages/core/src/semanticAttributes.ts @@ -31,6 +31,7 @@ export const SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN = 'sentry.origin'; * Streamed (v2) span statuses are reduced to `ok`/`error`, so we preserve the * message as an attribute instead of dropping it. This mirrors the attribute * Sentry's OTLP ingestion uses for the same purpose. + * @deprecated Use `SENTRY_STATUS_MESSAGE` from `@sentry/conventions/attributes` instead. */ export const SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE = 'sentry.status.message'; diff --git a/packages/core/src/utils/spanUtils.ts b/packages/core/src/utils/spanUtils.ts index 9fe769198f45..2bf38cdb5864 100644 --- a/packages/core/src/utils/spanUtils.ts +++ b/packages/core/src/utils/spanUtils.ts @@ -5,12 +5,11 @@ import { serializeAttributes } from '../attributes'; import { getMainCarrier } from '../carrier'; import { getCurrentScope } from '../currentScopes'; import type { Scope } from '../scope'; -import { SENTRY_SEGMENT_NAME_SOURCE } from '@sentry/conventions/attributes'; +import { SENTRY_SEGMENT_NAME_SOURCE, SENTRY_STATUS_MESSAGE } from '@sentry/conventions/attributes'; import { SEMANTIC_ATTRIBUTE_SENTRY_CUSTOM_SPAN_NAME, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, - SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE, } from '../semanticAttributes'; import type { SentrySpan } from '../tracing/sentrySpan'; import { isStatusErrorMessageValid, SPAN_STATUS_OK, SPAN_STATUS_UNSET } from '../tracing/spanstatus'; @@ -346,7 +345,7 @@ export function getSimpleStatus(status: SpanStatus | undefined): 'ok' | 'error' } /** - * Returns the span's attributes with the SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE attribute added + * Returns the span's attributes with the SENTRY_STATUS_MESSAGE attribute added * if the span has an error status message worth preserving. * * An explicitly set attribute is never overwritten. @@ -357,7 +356,7 @@ export function addStatusMessageAttribute( ): RawAttributes> { const statusMessage = getSimpleStatus(status) === 'error' ? status?.message : undefined; return { - ...(statusMessage && { [SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]: statusMessage }), + ...(statusMessage && { [SENTRY_STATUS_MESSAGE]: statusMessage }), ...attributes, }; } diff --git a/packages/core/test/lib/tracing/errors.test.ts b/packages/core/test/lib/tracing/errors.test.ts index 97afa005410d..b09bb3132732 100644 --- a/packages/core/test/lib/tracing/errors.test.ts +++ b/packages/core/test/lib/tracing/errors.test.ts @@ -1,11 +1,6 @@ +import { SENTRY_STATUS_MESSAGE } from '@sentry/conventions/attributes'; import { beforeEach, describe, expect, it, vi } from 'vitest'; -import { - SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE, - setCurrentClient, - spanToJSON, - startInactiveSpan, - startSpan, -} from '../../../src'; +import { setCurrentClient, spanToJSON, startInactiveSpan, startSpan } from '../../../src'; import * as globalErrorModule from '../../../src/instrument/globalError'; import * as globalUnhandledRejectionModule from '../../../src/instrument/globalUnhandledRejection'; import { _resetErrorsInstrumented, registerSpanErrorInstrumentation } from '../../../src/tracing/errors'; @@ -67,7 +62,7 @@ describe('registerErrorHandlers()', () => { mockErrorCallback({} as HandlerDataError); const { status, attributes } = spanToJSON(span); expect(status).toBe('error'); - expect(attributes[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).toBe('internal_error'); + expect(attributes[SENTRY_STATUS_MESSAGE]).toBe('internal_error'); }); }); @@ -78,7 +73,7 @@ describe('registerErrorHandlers()', () => { mockUnhandledRejectionCallback({}); const { status, attributes } = spanToJSON(span); expect(status).toBe('error'); - expect(attributes[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).toBe('internal_error'); + expect(attributes[SENTRY_STATUS_MESSAGE]).toBe('internal_error'); }); }); }); diff --git a/packages/core/test/lib/tracing/idleSpan.test.ts b/packages/core/test/lib/tracing/idleSpan.test.ts index 83f72e45c42f..d6c49bfb097b 100644 --- a/packages/core/test/lib/tracing/idleSpan.test.ts +++ b/packages/core/test/lib/tracing/idleSpan.test.ts @@ -8,7 +8,6 @@ import { getIsolationScope, getTraceData, SEMANTIC_ATTRIBUTE_SENTRY_IDLE_SPAN_FINISH_REASON, - SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE, SentryNonRecordingSpan, SentrySpan, setCurrentClient, @@ -23,7 +22,7 @@ import type { Event } from '../../../src/types/event'; import type { Span } from '../../../src/types/span'; import { getDefaultTestClientOptions, TestClient } from '../../mocks/client'; import { resetGlobals } from '../../testutils'; -import { SENTRY_SEGMENT_NAME_SOURCE } from '@sentry/conventions/attributes'; +import { SENTRY_SEGMENT_NAME_SOURCE, SENTRY_STATUS_MESSAGE } from '@sentry/conventions/attributes'; const dsn = 'https://123@sentry.io/42'; @@ -677,23 +676,17 @@ describe('startIdleSpan', () => { // Start any span to cancel idle timeout startInactiveSpan({ name: 'span' }); - expect(spanToJSON(idleSpan).attributes[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).not.toEqual( - 'deadline_exceeded', - ); + expect(spanToJSON(idleSpan).attributes[SENTRY_STATUS_MESSAGE]).not.toEqual('deadline_exceeded'); expect(spanToJSON(idleSpan).end_timestamp).toBeUndefined(); // Wait some time vi.advanceTimersByTime(TRACING_DEFAULTS.childSpanTimeout - 1000); - expect(spanToJSON(idleSpan).attributes[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).not.toEqual( - 'deadline_exceeded', - ); + expect(spanToJSON(idleSpan).attributes[SENTRY_STATUS_MESSAGE]).not.toEqual('deadline_exceeded'); expect(spanToJSON(idleSpan).end_timestamp).toBeUndefined(); // Wait for timeout to exceed vi.advanceTimersByTime(1000); - expect(spanToJSON(idleSpan).attributes[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).not.toEqual( - 'deadline_exceeded', - ); + expect(spanToJSON(idleSpan).attributes[SENTRY_STATUS_MESSAGE]).not.toEqual('deadline_exceeded'); expect(spanToJSON(idleSpan).end_timestamp).toBeDefined(); }); @@ -704,41 +697,31 @@ describe('startIdleSpan', () => { // Start any span to cancel idle timeout startInactiveSpan({ name: 'span' }); - expect(spanToJSON(idleSpan).attributes[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).not.toEqual( - 'deadline_exceeded', - ); + expect(spanToJSON(idleSpan).attributes[SENTRY_STATUS_MESSAGE]).not.toEqual('deadline_exceeded'); expect(spanToJSON(idleSpan).end_timestamp).toBeUndefined(); // Wait some time vi.advanceTimersByTime(TRACING_DEFAULTS.childSpanTimeout - 1000); - expect(spanToJSON(idleSpan).attributes[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).not.toEqual( - 'deadline_exceeded', - ); + expect(spanToJSON(idleSpan).attributes[SENTRY_STATUS_MESSAGE]).not.toEqual('deadline_exceeded'); expect(spanToJSON(idleSpan).end_timestamp).toBeUndefined(); // New span resets the timeout startInactiveSpan({ name: 'span' }); vi.advanceTimersByTime(TRACING_DEFAULTS.childSpanTimeout - 1000); - expect(spanToJSON(idleSpan).attributes[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).not.toEqual( - 'deadline_exceeded', - ); + expect(spanToJSON(idleSpan).attributes[SENTRY_STATUS_MESSAGE]).not.toEqual('deadline_exceeded'); expect(spanToJSON(idleSpan).end_timestamp).toBeUndefined(); // New span resets the timeout startInactiveSpan({ name: 'span' }); vi.advanceTimersByTime(TRACING_DEFAULTS.childSpanTimeout - 1000); - expect(spanToJSON(idleSpan).attributes[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).not.toEqual( - 'deadline_exceeded', - ); + expect(spanToJSON(idleSpan).attributes[SENTRY_STATUS_MESSAGE]).not.toEqual('deadline_exceeded'); expect(spanToJSON(idleSpan).end_timestamp).toBeUndefined(); // Wait for timeout to exceed vi.advanceTimersByTime(1000); - expect(spanToJSON(idleSpan).attributes[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).not.toEqual( - 'deadline_exceeded', - ); + expect(spanToJSON(idleSpan).attributes[SENTRY_STATUS_MESSAGE]).not.toEqual('deadline_exceeded'); expect(spanToJSON(idleSpan).end_timestamp).toBeDefined(); }); @@ -751,9 +734,7 @@ describe('startIdleSpan', () => { // Wait some time vi.advanceTimersByTime(TRACING_DEFAULTS.childSpanTimeout - 1000); - expect(spanToJSON(idleSpan).attributes[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).not.toEqual( - 'deadline_exceeded', - ); + expect(spanToJSON(idleSpan).attributes[SENTRY_STATUS_MESSAGE]).not.toEqual('deadline_exceeded'); expect(spanToJSON(idleSpan).end_timestamp).toBeUndefined(); // new standalone span should not reset the timeout @@ -762,9 +743,7 @@ describe('startIdleSpan', () => { // Wait for timeout to exceed vi.advanceTimersByTime(1001); - expect(spanToJSON(idleSpan).attributes[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).not.toEqual( - 'deadline_exceeded', - ); + expect(spanToJSON(idleSpan).attributes[SENTRY_STATUS_MESSAGE]).not.toEqual('deadline_exceeded'); expect(spanToJSON(idleSpan).end_timestamp).toBeDefined(); }); }); diff --git a/packages/core/test/lib/tracing/spanstatus.test.ts b/packages/core/test/lib/tracing/spanstatus.test.ts index 9d37b033a654..3abb6ee84619 100644 --- a/packages/core/test/lib/tracing/spanstatus.test.ts +++ b/packages/core/test/lib/tracing/spanstatus.test.ts @@ -1,5 +1,6 @@ +import { SENTRY_STATUS_MESSAGE } from '@sentry/conventions/attributes'; import { describe, expect, it } from 'vitest'; -import { SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE, SentrySpan, setHttpStatus, spanToJSON } from '../../../src/index'; +import { SentrySpan, setHttpStatus, spanToJSON } from '../../../src/index'; describe('setHttpStatus', () => { it.each([ @@ -24,7 +25,7 @@ describe('setHttpStatus', () => { const { status: spanStatus, attributes } = spanToJSON(span); expect(spanStatus).toBe(status); - expect(attributes[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).toBe(statusMessage); + expect(attributes[SENTRY_STATUS_MESSAGE]).toBe(statusMessage); expect(attributes).toMatchObject({ 'http.response.status_code': code }); }); @@ -36,7 +37,7 @@ describe('setHttpStatus', () => { const { status: spanStatus, attributes } = spanToJSON(span); expect(spanStatus).toBe('error'); - expect(attributes[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).toBe('internal_error'); + expect(attributes[SENTRY_STATUS_MESSAGE]).toBe('internal_error'); expect(attributes).toMatchObject({ 'http.response.status_code': 600 }); }); }); diff --git a/packages/core/test/lib/utils/spanUtils.test.ts b/packages/core/test/lib/utils/spanUtils.test.ts index a71b8732f866..e8ae4379b86f 100644 --- a/packages/core/test/lib/utils/spanUtils.test.ts +++ b/packages/core/test/lib/utils/spanUtils.test.ts @@ -1,4 +1,4 @@ -import { SENTRY_LINK_TYPE } from '@sentry/conventions/attributes'; +import { SENTRY_LINK_TYPE, SENTRY_STATUS_MESSAGE } from '@sentry/conventions/attributes'; import { beforeEach, describe, expect, it, test } from 'vitest'; import { convertSpanLinksForEnvelope, @@ -6,7 +6,6 @@ import { Scope, SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN, - SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE, SentryNonRecordingSpan, SentrySpan, setCurrentClient, @@ -510,7 +509,7 @@ describe('spanToStaticSpanJSON', () => { const json = spanToJSON(span); expect(json.status).toBe('error'); - expect(json.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).toBe('Connection Refused'); + expect(json.attributes?.[SENTRY_STATUS_MESSAGE]).toBe('Connection Refused'); }); it('does not set a status message for ok spans', () => { @@ -519,7 +518,7 @@ describe('spanToStaticSpanJSON', () => { const json = spanToJSON(span); expect(json.status).toBe('ok'); - expect(json.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).toBeUndefined(); + expect(json.attributes?.[SENTRY_STATUS_MESSAGE]).toBeUndefined(); }); it('does not set a status message for error spans without a message', () => { @@ -528,7 +527,7 @@ describe('spanToStaticSpanJSON', () => { const json = spanToJSON(span); expect(json.status).toBe('error'); - expect(json.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).toBeUndefined(); + expect(json.attributes?.[SENTRY_STATUS_MESSAGE]).toBeUndefined(); }); it('treats a cancelled status as ok and does not set a status message', () => { @@ -537,18 +536,18 @@ describe('spanToStaticSpanJSON', () => { const json = spanToJSON(span); expect(json.status).toBe('ok'); - expect(json.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).toBeUndefined(); + expect(json.attributes?.[SENTRY_STATUS_MESSAGE]).toBeUndefined(); }); it('does not overwrite an explicitly set sentry.status.message attribute', () => { const span = new SentrySpan({ name: 'test name', - attributes: { [SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]: 'explicit message' }, + attributes: { [SENTRY_STATUS_MESSAGE]: 'explicit message' }, }); span.setStatus({ code: SPAN_STATUS_ERROR, message: 'Connection Refused' }); const json = spanToJSON(span); - expect(json.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).toBe('explicit message'); + expect(json.attributes?.[SENTRY_STATUS_MESSAGE]).toBe('explicit message'); }); }); describe('OpenTelemetry Span', () => { @@ -619,7 +618,7 @@ describe('spanToStaticSpanJSON', () => { attr2: 2, [SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'test op', [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto', - [SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]: 'unknown_error', + [SENTRY_STATUS_MESSAGE]: 'unknown_error', }, links: [ { @@ -647,7 +646,7 @@ describe('spanToStaticSpanJSON', () => { const json = spanToJSON(span); expect(json.status).toBe('error'); - expect(json.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).toBe('Connection Refused'); + expect(json.attributes?.[SENTRY_STATUS_MESSAGE]).toBe('Connection Refused'); }); it('does not set a status message for ok/unset spans', () => { @@ -663,7 +662,7 @@ describe('spanToStaticSpanJSON', () => { const json = spanToJSON(span); expect(json.status).toBe('ok'); - expect(json.attributes?.[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]).toBeUndefined(); + expect(json.attributes?.[SENTRY_STATUS_MESSAGE]).toBeUndefined(); }); }); });