Skip to content

Commit b4a39c4

Browse files
committed
feat(core): Default span status to ok in transaction mode
1 parent fb0329c commit b4a39c4

5 files changed

Lines changed: 9 additions & 8 deletions

File tree

packages/core/src/types/span.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export interface SpanJSON {
8585
parent_span_id?: string;
8686
span_id: string;
8787
start_timestamp: number;
88-
status?: string;
88+
status: string;
8989
timestamp?: number;
9090
trace_id: string;
9191
origin?: SpanOrigin;

packages/core/src/utils/spanUtils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ export function spanToJSON(span: Span): SpanJSON {
204204
span_id,
205205
trace_id,
206206
start_timestamp: 0,
207+
status: 'ok',
207208
data: {},
208209
};
209210
}
@@ -317,9 +318,9 @@ export function spanIsSampled(span: Span): boolean {
317318
}
318319

319320
/** Get the status message to use for a JSON representation of a span. */
320-
export function getStatusMessage(status: SpanStatus | undefined): string | undefined {
321+
export function getStatusMessage(status: SpanStatus | undefined): string {
321322
if (!status || status.code === SPAN_STATUS_UNSET) {
322-
return undefined;
323+
return 'ok';
323324
}
324325

325326
if (status.code === SPAN_STATUS_OK) {

packages/core/src/utils/transactionEvent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function convertTransactionEventToSpanJson(event: TransactionEvent): Span
1515
parent_span_id,
1616
span_id: span_id ?? '',
1717
start_timestamp: event.start_timestamp ?? 0,
18-
status,
18+
status: status ?? 'ok',
1919
timestamp: event.timestamp,
2020
trace_id: trace_id ?? '',
2121
origin,

packages/node/src/integrations/tracing/graphql/vendored/instrumentation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ export class GraphQLInstrumentation extends InstrumentationBase<GraphQLInstrumen
245245
*/
246246
private _updateSpanFromResult(span: Span, result: ExecutionResult): void {
247247
// We want to ensure spans are marked as errored if there are errors in the result
248-
// We only do that if the span is not already marked with a status
249-
if (result.errors?.length && !spanToJSON(span).status) {
248+
// We only do that if the span is not already marked with another error status
249+
if (result.errors?.length && spanToJSON(span).status === 'ok') {
250250
span.setStatus({ code: SPAN_STATUS_ERROR });
251251
}
252252

packages/opentelemetry/src/trace.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function _startSpan<T>(options: OpenTelemetrySpanContext, callback: (span: Span)
7878
() => callback(span),
7979
() => {
8080
// Only set the span status to ERROR when there wasn't any status set before, in order to avoid stomping useful span statuses
81-
if (spanToJSON(span).status === undefined) {
81+
if (spanToJSON(span).status === 'ok') {
8282
span.setStatus({ code: SpanStatusCode.ERROR });
8383
}
8484
},
@@ -95,7 +95,7 @@ function _startSpan<T>(options: OpenTelemetrySpanContext, callback: (span: Span)
9595
() => callback(span),
9696
() => {
9797
// Only set the span status to ERROR when there wasn't any status set before, in order to avoid stomping useful span statuses
98-
if (spanToJSON(span).status === undefined) {
98+
if (spanToJSON(span).status === 'ok') {
9999
span.setStatus({ code: SpanStatusCode.ERROR });
100100
}
101101
},

0 commit comments

Comments
 (0)