Skip to content

Commit b4d6469

Browse files
authored
feat(otel): Export & use spanTimeInputToSeconds for otel span exporter (#12699)
Adds support for cases where the time from OTEL is just a number in milliseconds instead of tuples.
1 parent 41d946e commit b4d6469

File tree

5 files changed

+8
-20
lines changed

5 files changed

+8
-20
lines changed

packages/core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export {
7878
getRootSpan,
7979
getActiveSpan,
8080
addChildSpanToSpan,
81+
spanTimeInputToSeconds,
8182
} from './utils/spanUtils';
8283
export { parseSampleRate } from './utils/parseSampleRate';
8384
export { applySdkMetadata } from './utils/sdkMetadata';

packages/core/src/utils/spanUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export function spanToTraceHeader(span: Span): string {
6969
}
7070

7171
/**
72-
* Convert a span time input intp a timestamp in seconds.
72+
* Convert a span time input into a timestamp in seconds.
7373
*/
7474
export function spanTimeInputToSeconds(input: SpanTimeInput | undefined): number {
7575
if (typeof input === 'number') {

packages/opentelemetry/src/spanExporter.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ import {
1515
SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE,
1616
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
1717
getStatusMessage,
18+
spanTimeInputToSeconds,
1819
} from '@sentry/core';
1920
import type { SpanJSON, SpanOrigin, TraceContext, TransactionEvent, TransactionSource } from '@sentry/types';
2021
import { dropUndefinedKeys, logger } from '@sentry/utils';
2122
import { SENTRY_TRACE_STATE_PARENT_SPAN_ID } from './constants';
2223

2324
import { DEBUG_BUILD } from './debug-build';
2425
import { SEMANTIC_ATTRIBUTE_SENTRY_PARENT_IS_REMOTE } from './semanticAttributes';
25-
import { convertOtelTimeToSeconds } from './utils/convertOtelTimeToSeconds';
2626
import { getRequestSpanData } from './utils/getRequestSpanData';
2727
import type { SpanNode } from './utils/groupSpansWithParents';
2828
import { getLocalParentId } from './utils/groupSpansWithParents';
@@ -176,7 +176,7 @@ function getCompletedRootNodes(nodes: SpanNode[]): SpanNodeCompleted[] {
176176

177177
function shouldCleanupSpan(span: ReadableSpan, maxStartTimeOffsetSeconds: number): boolean {
178178
const cutoff = Date.now() / 1000 - maxStartTimeOffsetSeconds;
179-
return convertOtelTimeToSeconds(span.startTime) < cutoff;
179+
return spanTimeInputToSeconds(span.startTime) < cutoff;
180180
}
181181

182182
function parseSpan(span: ReadableSpan): { op?: string; origin?: SpanOrigin; source?: TransactionSource } {
@@ -236,8 +236,8 @@ function createTransactionForOtelSpan(span: ReadableSpan): TransactionEvent {
236236
},
237237
},
238238
spans: [],
239-
start_timestamp: convertOtelTimeToSeconds(span.startTime),
240-
timestamp: convertOtelTimeToSeconds(span.endTime),
239+
start_timestamp: spanTimeInputToSeconds(span.startTime),
240+
timestamp: spanTimeInputToSeconds(span.endTime),
241241
transaction: description,
242242
type: 'transaction',
243243
sdkProcessingMetadata: {
@@ -294,9 +294,9 @@ function createAndFinishSpanForOtelSpan(node: SpanNode, spans: SpanJSON[], remai
294294
data: allData,
295295
description,
296296
parent_span_id: parentSpanId,
297-
start_timestamp: convertOtelTimeToSeconds(startTime),
297+
start_timestamp: spanTimeInputToSeconds(startTime),
298298
// This is [0,0] by default in OTEL, in which case we want to interpret this as no end time
299-
timestamp: convertOtelTimeToSeconds(endTime) || undefined,
299+
timestamp: spanTimeInputToSeconds(endTime) || undefined,
300300
status: getStatusMessage(status), // As per protocol, span status is allowed to be undefined
301301
op,
302302
origin,

packages/opentelemetry/src/utils/convertOtelTimeToSeconds.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

packages/opentelemetry/test/utils/convertOtelTimeToSeconds.test.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)