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
@@ -1,11 +1,10 @@
import { SENTRY_SEGMENT_NAME_SOURCE } from '@sentry/conventions/attributes';
import { SENTRY_IDLE_SPAN_FINISH_REASON, SENTRY_SEGMENT_NAME_SOURCE } from '@sentry/conventions/attributes';
import { expect } from '@playwright/test';
import {
SEMANTIC_ATTRIBUTE_SENTRY_OP,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE,
} from '@sentry/browser';
import { SEMANTIC_ATTRIBUTE_SENTRY_IDLE_SPAN_FINISH_REASON } from '@sentry/core';
import { sentryTest } from '../../../../../utils/fixtures';
import { shouldSkipTracingTest } from '../../../../../utils/helpers';
import { getSpanOp, waitForStreamedSpan } from '../../../../../utils/spanUtils';
Expand All @@ -30,7 +29,7 @@ sentryTest(
[SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: expect.objectContaining({ value: 1 }),
[SENTRY_SEGMENT_NAME_SOURCE]: { type: 'string', value: 'url' },
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: { type: 'string', value: 'pageload' },
[SEMANTIC_ATTRIBUTE_SENTRY_IDLE_SPAN_FINISH_REASON]: { type: 'string', value: 'reportPageLoaded' },
[SENTRY_IDLE_SPAN_FINISH_REASON]: { type: 'string', value: 'reportPageLoaded' },
});

// We wait for 2.5 seconds before calling Sentry.reportPageLoaded(). The span starts at navigation start,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { expect } from '@playwright/test';
import {
SDK_VERSION,
SEMANTIC_ATTRIBUTE_SENTRY_ENVIRONMENT,
SEMANTIC_ATTRIBUTE_SENTRY_IDLE_SPAN_FINISH_REASON,
SEMANTIC_ATTRIBUTE_SENTRY_OP,
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
SEMANTIC_ATTRIBUTE_SENTRY_SDK_INTEGRATIONS,
} from '@sentry/core';
import {
SENTRY_IDLE_SPAN_FINISH_REASON,
SENTRY_SEGMENT_ID,
SENTRY_SEGMENT_NAME,
SENTRY_SEGMENT_NAME_SOURCE,
Expand Down Expand Up @@ -76,7 +76,7 @@ sentryTest('captures streamed interaction span tree. @firefox', async ({ browser
type: 'string',
value: '/index.html',
},
[SEMANTIC_ATTRIBUTE_SENTRY_IDLE_SPAN_FINISH_REASON]: {
[SENTRY_IDLE_SPAN_FINISH_REASON]: {
type: 'string',
value: 'idleTimeout',
},
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/semanticAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export const SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN = 'sentry.origin';
*/
export const SEMANTIC_ATTRIBUTE_SENTRY_STATUS_MESSAGE = 'sentry.status.message';

/** The reason why an idle span finished. */
/**
* The reason why an idle span finished.
* @deprecated Use `SENTRY_IDLE_SPAN_FINISH_REASON` from `@sentry/conventions/attributes` instead.
*/
export const SEMANTIC_ATTRIBUTE_SENTRY_IDLE_SPAN_FINISH_REASON = 'sentry.idle_span_finish_reason';

/** The unit of a measurement, which may be stored as a TimedEvent. */
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/tracing/idleSpan.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SENTRY_IDLE_SPAN_FINISH_REASON } from '@sentry/conventions/attributes';
import { getClient, getCurrentScope, getIsolationScope } from '../currentScopes';
import { DEBUG_BUILD } from '../debug-build';
import { SEMANTIC_ATTRIBUTE_SENTRY_IDLE_SPAN_FINISH_REASON } from '../semanticAttributes';
import type { Span } from '../types/span';
import type { StartSpanOptions } from '../types/startSpanOptions';
import { debug } from '../utils/debug-logger';
Expand Down Expand Up @@ -303,8 +303,8 @@ export function startIdleSpan(startSpanOptions: StartSpanOptions, options: Parti
}

const attributes = spanJSON.data;
if (!attributes[SEMANTIC_ATTRIBUTE_SENTRY_IDLE_SPAN_FINISH_REASON]) {
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_IDLE_SPAN_FINISH_REASON, _finishReason);
if (!attributes[SENTRY_IDLE_SPAN_FINISH_REASON]) {
span.setAttribute(SENTRY_IDLE_SPAN_FINISH_REASON, _finishReason);
}

// Set span status to 'ok' if it hasn't been explicitly set to an error status
Expand Down
29 changes: 11 additions & 18 deletions packages/core/test/lib/tracing/idleSpan.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
getDynamicSamplingContextFromSpan,
getIsolationScope,
getTraceData,
SEMANTIC_ATTRIBUTE_SENTRY_IDLE_SPAN_FINISH_REASON,
SentryNonRecordingSpan,
SentrySpan,
setCurrentClient,
Expand All @@ -22,7 +21,11 @@ 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, SENTRY_STATUS_MESSAGE } from '@sentry/conventions/attributes';
import {
SENTRY_IDLE_SPAN_FINISH_REASON,
SENTRY_SEGMENT_NAME_SOURCE,
SENTRY_STATUS_MESSAGE,
} from '@sentry/conventions/attributes';

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

Expand Down Expand Up @@ -517,9 +520,7 @@ describe('startIdleSpan', () => {
vi.runOnlyPendingTimers();

expect(beforeSendTransaction).toHaveBeenCalledTimes(1);
expect(transaction?.contexts?.trace?.data?.[SEMANTIC_ATTRIBUTE_SENTRY_IDLE_SPAN_FINISH_REASON]).toEqual(
'externalFinish',
);
expect(transaction?.contexts?.trace?.data?.[SENTRY_IDLE_SPAN_FINISH_REASON]).toEqual('externalFinish');
});

it('sets finish reason when span ends', () => {
Expand All @@ -538,9 +539,7 @@ describe('startIdleSpan', () => {
vi.runOnlyPendingTimers();

expect(beforeSendTransaction).toHaveBeenCalledTimes(1);
expect(transaction?.contexts?.trace?.data?.[SEMANTIC_ATTRIBUTE_SENTRY_IDLE_SPAN_FINISH_REASON]).toEqual(
'idleTimeout',
);
expect(transaction?.contexts?.trace?.data?.[SENTRY_IDLE_SPAN_FINISH_REASON]).toEqual('idleTimeout');
});

it('sets finish reason when span ends via expired heartbeat timeout', () => {
Expand All @@ -559,9 +558,7 @@ describe('startIdleSpan', () => {
vi.runOnlyPendingTimers();

expect(beforeSendTransaction).toHaveBeenCalledTimes(1);
expect(transaction?.contexts?.trace?.data?.[SEMANTIC_ATTRIBUTE_SENTRY_IDLE_SPAN_FINISH_REASON]).toEqual(
'heartbeatFailed',
);
expect(transaction?.contexts?.trace?.data?.[SENTRY_IDLE_SPAN_FINISH_REASON]).toEqual('heartbeatFailed');
});

it('sets finish reason when span ends via final timeout', () => {
Expand Down Expand Up @@ -589,9 +586,7 @@ describe('startIdleSpan', () => {
vi.runOnlyPendingTimers();

expect(beforeSendTransaction).toHaveBeenCalledTimes(1);
expect(transaction?.contexts?.trace?.data?.[SEMANTIC_ATTRIBUTE_SENTRY_IDLE_SPAN_FINISH_REASON]).toEqual(
'finalTimeout',
);
expect(transaction?.contexts?.trace?.data?.[SENTRY_IDLE_SPAN_FINISH_REASON]).toEqual('finalTimeout');
});

it('uses finish reason set outside when span ends', () => {
Expand All @@ -606,14 +601,12 @@ describe('startIdleSpan', () => {
client.init();

const span = startIdleSpan({ name: 'foo' });
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_IDLE_SPAN_FINISH_REASON, 'custom reason');
span.setAttribute(SENTRY_IDLE_SPAN_FINISH_REASON, 'custom reason');
startSpan({ name: 'inner' }, () => {});
vi.runOnlyPendingTimers();

expect(beforeSendTransaction).toHaveBeenCalledTimes(1);
expect(transaction?.contexts?.trace?.data?.[SEMANTIC_ATTRIBUTE_SENTRY_IDLE_SPAN_FINISH_REASON]).toEqual(
'custom reason',
);
expect(transaction?.contexts?.trace?.data?.[SENTRY_IDLE_SPAN_FINISH_REASON]).toEqual('custom reason');
});

describe('idleTimeout', () => {
Expand Down
Loading