Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -19,6 +18,7 @@ import {
SENTRY_SDK_VERSION,
SENTRY_TRACE_LIFECYCLE,
USER_AGENT_ORIGINAL,
SENTRY_STATUS_MESSAGE,
} from '@sentry/conventions/attributes';

sentryTest(
Expand Down Expand Up @@ -195,7 +195,7 @@ sentryTest(
type: 'string',
value: 'production',
},
[SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]: {
[SENTRY_STATUS_MESSAGE]: {
type: 'string',
value: 'Connection Refused',
},
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/semanticAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
7 changes: 3 additions & 4 deletions packages/core/src/utils/spanUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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.
Expand All @@ -357,7 +356,7 @@ export function addStatusMessageAttribute(
): RawAttributes<Record<string, unknown>> {
const statusMessage = getSimpleStatus(status) === 'error' ? status?.message : undefined;
return {
...(statusMessage && { [SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE]: statusMessage }),
...(statusMessage && { [SENTRY_STATUS_MESSAGE]: statusMessage }),
...attributes,
};
}
Expand Down
13 changes: 4 additions & 9 deletions packages/core/test/lib/tracing/errors.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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');
});
});

Expand All @@ -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');
});
});
});
43 changes: 11 additions & 32 deletions packages/core/test/lib/tracing/idleSpan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
getIsolationScope,
getTraceData,
SEMANTIC_ATTRIBUTE_SENTRY_IDLE_SPAN_FINISH_REASON,
SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE,
SentryNonRecordingSpan,
SentrySpan,
setCurrentClient,
Expand All @@ -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';

Expand Down Expand Up @@ -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();
});

Expand All @@ -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();
});

Expand All @@ -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
Expand All @@ -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();
});
});
Expand Down
7 changes: 4 additions & 3 deletions packages/core/test/lib/tracing/spanstatus.test.ts
Original file line number Diff line number Diff line change
@@ -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([
Expand All @@ -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 });
});

Expand All @@ -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 });
});
});
21 changes: 10 additions & 11 deletions packages/core/test/lib/utils/spanUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
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,
getCurrentScope,
Scope,
SEMANTIC_ATTRIBUTE_SENTRY_OP,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE,
SentryNonRecordingSpan,
SentrySpan,
setCurrentClient,
Expand Down Expand Up @@ -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', () => {
Expand All @@ -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', () => {
Expand All @@ -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', () => {
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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: [
{
Expand Down Expand Up @@ -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', () => {
Expand All @@ -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();
});
});
});
Expand Down
Loading