Skip to content

ref(core): Remove status field from Span #10856

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 29, 2024
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
4 changes: 2 additions & 2 deletions packages/bun/test/integrations/bunserver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('Bun Serve Integration', () => {

test('generates a transaction around a request', async () => {
client.on('finishTransaction', transaction => {
expect(transaction.status).toBe('ok');
expect(spanToJSON(transaction).status).toBe('ok');
expect(spanToJSON(transaction).data?.['http.response.status_code']).toEqual(200);
expect(spanToJSON(transaction).op).toEqual('http.server');
expect(spanToJSON(transaction).description).toEqual('GET /');
Expand All @@ -44,7 +44,7 @@ describe('Bun Serve Integration', () => {

test('generates a post transaction', async () => {
client.on('finishTransaction', transaction => {
expect(transaction.status).toBe('ok');
expect(spanToJSON(transaction).status).toBe('ok');
expect(spanToJSON(transaction).data?.['http.response.status_code']).toEqual(200);
expect(spanToJSON(transaction).op).toEqual('http.server');
expect(spanToJSON(transaction).description).toEqual('POST /');
Expand Down
21 changes: 0 additions & 21 deletions packages/core/src/tracing/sentrySpan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ export class SentrySpan implements SpanInterface {
if ('sampled' in spanContext) {
this._sampled = spanContext.sampled;
}
if (spanContext.status) {
this._status = spanContext.status;
}
if (spanContext.endTimestamp) {
this._endTime = spanContext.endTimestamp;
}
Expand Down Expand Up @@ -260,24 +257,6 @@ export class SentrySpan implements SpanInterface {
this._endTime = endTime;
}

/**
* The status of the span.
*
* @deprecated Use `spanToJSON().status` instead to get the status.
*/
public get status(): SpanStatusType | string | undefined {
return this._status;
}

/**
* The status of the span.
*
* @deprecated Use `.setStatus()` instead to set or update the status.
*/
public set status(status: SpanStatusType | string | undefined) {
this._status = status;
}

/* eslint-enable @typescript-eslint/member-ordering */

/** @inheritdoc */
Expand Down
10 changes: 0 additions & 10 deletions packages/core/test/lib/tracing/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,12 @@ describe('registerErrorHandlers()', () => {
registerErrorInstrumentation();

const transaction = startInactiveSpan({ name: 'test' })!;
// eslint-disable-next-line deprecation/deprecation
expect(transaction.status).toBe(undefined);
expect(spanToJSON(transaction).status).toBe(undefined);

mockErrorCallback({} as HandlerDataError);
// eslint-disable-next-line deprecation/deprecation
expect(transaction.status).toBe(undefined);
expect(spanToJSON(transaction).status).toBe(undefined);

mockUnhandledRejectionCallback({});
// eslint-disable-next-line deprecation/deprecation
expect(transaction.status).toBe(undefined);
expect(spanToJSON(transaction).status).toBe(undefined);

transaction.end();
Expand All @@ -72,8 +66,6 @@ describe('registerErrorHandlers()', () => {

startSpan({ name: 'test' }, span => {
mockErrorCallback({} as HandlerDataError);
// eslint-disable-next-line deprecation/deprecation
expect(span!.status).toBe('internal_error');
expect(spanToJSON(span!).status).toBe('internal_error');
});
});
Expand All @@ -83,8 +75,6 @@ describe('registerErrorHandlers()', () => {

startSpan({ name: 'test' }, span => {
mockUnhandledRejectionCallback({});
// eslint-disable-next-line deprecation/deprecation
expect(span!.status).toBe('internal_error');
expect(spanToJSON(span!).status).toBe('internal_error');
});
});
Expand Down
14 changes: 7 additions & 7 deletions packages/core/test/lib/tracing/idletransaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,12 @@ describe('IdleTransaction', () => {

// Regular SentrySpan - should not modified
expect(spans[1].spanContext().spanId).toBe(regularSpan.spanContext().spanId);
expect(spans[1]['_endTime']).not.toBe(spanToJSON(transaction).timestamp);
expect(spanToJSON(spans[1]).timestamp).not.toBe(spanToJSON(transaction).timestamp);

// Cancelled SentrySpan - has endtimestamp of transaction
expect(spans[2].spanContext().spanId).toBe(cancelledSpan.spanContext().spanId);
expect(spans[2].status).toBe('cancelled');
expect(spans[2]['_endTime']).toBe(spanToJSON(transaction).timestamp);
expect(spanToJSON(spans[2]).status).toBe('cancelled');
expect(spanToJSON(spans[2]).timestamp).toBe(spanToJSON(transaction).timestamp);
}
});

Expand Down Expand Up @@ -415,22 +415,22 @@ describe('IdleTransaction', () => {
const transaction = new IdleTransaction({ name: 'foo' }, getCurrentHub(), 20000);
const mockFinish = jest.spyOn(transaction, 'end');

expect(transaction.status).not.toEqual('deadline_exceeded');
expect(spanToJSON(transaction).status).not.toEqual('deadline_exceeded');
expect(mockFinish).toHaveBeenCalledTimes(0);

// Beat 1
jest.advanceTimersByTime(TRACING_DEFAULTS.heartbeatInterval);
expect(transaction.status).not.toEqual('deadline_exceeded');
expect(spanToJSON(transaction).status).not.toEqual('deadline_exceeded');
expect(mockFinish).toHaveBeenCalledTimes(0);

// Beat 2
jest.advanceTimersByTime(TRACING_DEFAULTS.heartbeatInterval);
expect(transaction.status).not.toEqual('deadline_exceeded');
expect(spanToJSON(transaction).status).not.toEqual('deadline_exceeded');
expect(mockFinish).toHaveBeenCalledTimes(0);

// Beat 3
jest.advanceTimersByTime(TRACING_DEFAULTS.heartbeatInterval);
expect(transaction.status).not.toEqual('deadline_exceeded');
expect(spanToJSON(transaction).status).not.toEqual('deadline_exceeded');
expect(mockFinish).toHaveBeenCalledTimes(0);
});

Expand Down
67 changes: 38 additions & 29 deletions packages/core/test/lib/tracing/trace.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Event, Span as SpanType } from '@sentry/types';
import type { Event, Span } from '@sentry/types';
import {
SEMANTIC_ATTRIBUTE_SENTRY_OP,
addTracingExtensions,
Expand All @@ -7,6 +7,7 @@ import {
getGlobalScope,
getIsolationScope,
setCurrentClient,
spanIsSampled,
spanToJSON,
withScope,
} from '../../../src';
Expand All @@ -18,6 +19,7 @@ import {
startSpan,
startSpanManual,
} from '../../../src/tracing';
import { getSpanTree } from '../../../src/tracing/utils';
import { TestClient, getDefaultTestClientOptions } from '../../mocks/client';

beforeAll(() => {
Expand Down Expand Up @@ -92,9 +94,9 @@ describe('startSpan', () => {
});

it('creates a transaction', async () => {
let ref: any = undefined;
let _span: Span | undefined = undefined;
client.on('finishTransaction', transaction => {
ref = transaction;
_span = transaction;
});
try {
await startSpan({ name: 'GET users/[id]' }, () => {
Expand All @@ -103,16 +105,16 @@ describe('startSpan', () => {
} catch (e) {
//
}
expect(ref).toBeDefined();
expect(_span).toBeDefined();

expect(spanToJSON(ref).description).toEqual('GET users/[id]');
expect(ref.status).toEqual(isError ? 'internal_error' : undefined);
expect(spanToJSON(_span!).description).toEqual('GET users/[id]');
expect(spanToJSON(_span!).status).toEqual(isError ? 'internal_error' : undefined);
});

it('allows traceparent information to be overriden', async () => {
let ref: any = undefined;
let _span: Span | undefined = undefined;
client.on('finishTransaction', transaction => {
ref = transaction;
_span = transaction;
});
try {
await startSpan(
Expand All @@ -129,17 +131,17 @@ describe('startSpan', () => {
} catch (e) {
//
}
expect(ref).toBeDefined();
expect(_span).toBeDefined();

expect(ref.sampled).toEqual(true);
expect(ref.traceId).toEqual('12345678901234567890123456789012');
expect(ref.parentSpanId).toEqual('1234567890123456');
expect(spanIsSampled(_span!)).toEqual(true);
expect(spanToJSON(_span!).trace_id).toEqual('12345678901234567890123456789012');
expect(spanToJSON(_span!).parent_span_id).toEqual('1234567890123456');
});

it('allows for transaction to be mutated', async () => {
let ref: any = undefined;
let _span: Span | undefined = undefined;
client.on('finishTransaction', transaction => {
ref = transaction;
_span = transaction;
});
try {
await startSpan({ name: 'GET users/[id]' }, span => {
Expand All @@ -152,13 +154,13 @@ describe('startSpan', () => {
//
}

expect(spanToJSON(ref).op).toEqual('http.server');
expect(spanToJSON(_span!).op).toEqual('http.server');
});

it('creates a span with correct description', async () => {
let ref: any = undefined;
let _span: Span | undefined = undefined;
client.on('finishTransaction', transaction => {
ref = transaction;
_span = transaction;
});
try {
await startSpan({ name: 'GET users/[id]', parentSampled: true }, () => {
Expand All @@ -170,16 +172,19 @@ describe('startSpan', () => {
//
}

expect(ref.spanRecorder.spans).toHaveLength(2);
expect(spanToJSON(ref.spanRecorder.spans[1]).description).toEqual('SELECT * from users');
expect(ref.spanRecorder.spans[1].parentSpanId).toEqual(ref.spanId);
expect(ref.spanRecorder.spans[1].status).toEqual(isError ? 'internal_error' : undefined);
expect(_span).toBeDefined();
const spans = getSpanTree(_span!);

expect(spans).toHaveLength(2);
expect(spanToJSON(spans[1]).description).toEqual('SELECT * from users');
expect(spanToJSON(spans[1]).parent_span_id).toEqual(_span!.spanContext().spanId);
expect(spanToJSON(spans[1]).status).toEqual(isError ? 'internal_error' : undefined);
});

it('allows for span to be mutated', async () => {
let ref: any = undefined;
let _span: Span | undefined = undefined;
client.on('finishTransaction', transaction => {
ref = transaction;
_span = transaction;
});
try {
await startSpan({ name: 'GET users/[id]', parentSampled: true }, () => {
Expand All @@ -194,8 +199,11 @@ describe('startSpan', () => {
//
}

expect(ref.spanRecorder.spans).toHaveLength(2);
expect(spanToJSON(ref.spanRecorder.spans[1]).op).toEqual('db.query');
expect(_span).toBeDefined();
const spans = getSpanTree(_span!);

expect(spans).toHaveLength(2);
expect(spanToJSON(spans[1]).op).toEqual('db.query');
});

it.each([
Expand All @@ -204,9 +212,9 @@ describe('startSpan', () => {
// attribute should take precedence over top level origin
{ origin: 'manual', attributes: { 'sentry.origin': 'auto.http.browser' } },
])('correctly sets the span origin', async () => {
let ref: any = undefined;
let _span: Span | undefined = undefined;
client.on('finishTransaction', transaction => {
ref = transaction;
_span = transaction;
});
try {
await startSpan({ name: 'GET users/[id]', origin: 'auto.http.browser' }, () => {
Expand All @@ -216,7 +224,8 @@ describe('startSpan', () => {
//
}

const jsonSpan = spanToJSON(ref);
expect(_span).toBeDefined();
const jsonSpan = spanToJSON(_span!);
expect(jsonSpan).toEqual({
data: {
'sentry.origin': 'auto.http.browser',
Expand Down Expand Up @@ -944,7 +953,7 @@ describe('startInactiveSpan', () => {
setCurrentClient(client);
client.init();

let span: SpanType | undefined;
let span: Span | undefined;

withScope(scope => {
scope.setTag('scope', 1);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/lib/utils/spanUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ describe('spanToJSON', () => {
op: 'test op',
parentSpanId: '1234',
spanId: '5678',
status: 'ok',
traceId: 'abcd',
origin: 'auto',
startTimestamp: 123,
endTimestamp: 456,
});
span.setStatus('ok');

expect(spanToJSON(span)).toEqual({
description: 'test name',
Expand Down
2 changes: 0 additions & 2 deletions packages/node/test/handlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,6 @@ describe('tracingHandler', () => {

setImmediate(() => {
expect(finishTransaction).toHaveBeenCalled();
// eslint-disable-next-line deprecation/deprecation
expect(transaction.status).toBe('ok');
expect(spanToJSON(transaction).status).toBe('ok');
expect(spanToJSON(transaction).data).toEqual(expect.objectContaining({ 'http.response.status_code': 200 }));
done();
Expand Down
2 changes: 1 addition & 1 deletion packages/node/test/integrations/undici.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ conditionalTest({ min: 16 })('Undici integration', () => {
expect(spans.length).toBe(2);

const span = spans[1];
expect(span).toEqual(expect.objectContaining({ status: 'internal_error' }));
expect(spanToJSON(span).status).toEqual('internal_error');
});
});

Expand Down
10 changes: 0 additions & 10 deletions packages/opentelemetry-node/test/spanprocessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -361,14 +361,10 @@ describe('SentrySpanProcessor', () => {
const transaction = getSpanForOtelSpan(otelSpan) as Transaction;

// status is only set after end
// eslint-disable-next-line deprecation/deprecation
expect(transaction?.status).toBe(undefined);
expect(spanToJSON(transaction!).status).toBe(undefined);

otelSpan.end();

// eslint-disable-next-line deprecation/deprecation
expect(transaction?.status).toBe('ok');
expect(spanToJSON(transaction!).status).toBe('ok');
});

Expand All @@ -379,14 +375,10 @@ describe('SentrySpanProcessor', () => {
tracer.startActiveSpan('SELECT * FROM users;', child => {
const sentrySpan = getSpanForOtelSpan(child);

// eslint-disable-next-line deprecation/deprecation
expect(sentrySpan?.status).toBe(undefined);
expect(spanToJSON(sentrySpan!).status).toBe(undefined);

child.end();

// eslint-disable-next-line deprecation/deprecation
expect(sentrySpan?.status).toBe('ok');
expect(spanToJSON(sentrySpan!).status).toBe('ok');

parentOtelSpan.end();
Expand Down Expand Up @@ -469,8 +461,6 @@ describe('SentrySpanProcessor', () => {
}

otelSpan.end();
// eslint-disable-next-line deprecation/deprecation
expect(transaction?.status).toBe(expected);
expect(spanToJSON(transaction!).status).toBe(expected);
},
);
Expand Down
Loading