diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 8ea4b032d44c..1971bb8c94bd 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -78,6 +78,7 @@ export { getRootSpan, getActiveSpan, addChildSpanToSpan, + spanTimeInputToSeconds, } from './utils/spanUtils'; export { parseSampleRate } from './utils/parseSampleRate'; export { applySdkMetadata } from './utils/sdkMetadata'; diff --git a/packages/core/src/utils/spanUtils.ts b/packages/core/src/utils/spanUtils.ts index 0878f0b383b3..266a0035b382 100644 --- a/packages/core/src/utils/spanUtils.ts +++ b/packages/core/src/utils/spanUtils.ts @@ -69,7 +69,7 @@ export function spanToTraceHeader(span: Span): string { } /** - * Convert a span time input intp a timestamp in seconds. + * Convert a span time input into a timestamp in seconds. */ export function spanTimeInputToSeconds(input: SpanTimeInput | undefined): number { if (typeof input === 'number') { diff --git a/packages/opentelemetry/src/spanExporter.ts b/packages/opentelemetry/src/spanExporter.ts index d139044a713f..3064de5818aa 100644 --- a/packages/opentelemetry/src/spanExporter.ts +++ b/packages/opentelemetry/src/spanExporter.ts @@ -15,6 +15,7 @@ import { SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE, SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, getStatusMessage, + spanTimeInputToSeconds, } from '@sentry/core'; import type { SpanJSON, SpanOrigin, TraceContext, TransactionEvent, TransactionSource } from '@sentry/types'; import { dropUndefinedKeys, logger } from '@sentry/utils'; @@ -22,7 +23,6 @@ import { SENTRY_TRACE_STATE_PARENT_SPAN_ID } from './constants'; import { DEBUG_BUILD } from './debug-build'; import { SEMANTIC_ATTRIBUTE_SENTRY_PARENT_IS_REMOTE } from './semanticAttributes'; -import { convertOtelTimeToSeconds } from './utils/convertOtelTimeToSeconds'; import { getRequestSpanData } from './utils/getRequestSpanData'; import type { SpanNode } from './utils/groupSpansWithParents'; import { getLocalParentId } from './utils/groupSpansWithParents'; @@ -176,7 +176,7 @@ function getCompletedRootNodes(nodes: SpanNode[]): SpanNodeCompleted[] { function shouldCleanupSpan(span: ReadableSpan, maxStartTimeOffsetSeconds: number): boolean { const cutoff = Date.now() / 1000 - maxStartTimeOffsetSeconds; - return convertOtelTimeToSeconds(span.startTime) < cutoff; + return spanTimeInputToSeconds(span.startTime) < cutoff; } function parseSpan(span: ReadableSpan): { op?: string; origin?: SpanOrigin; source?: TransactionSource } { @@ -236,8 +236,8 @@ function createTransactionForOtelSpan(span: ReadableSpan): TransactionEvent { }, }, spans: [], - start_timestamp: convertOtelTimeToSeconds(span.startTime), - timestamp: convertOtelTimeToSeconds(span.endTime), + start_timestamp: spanTimeInputToSeconds(span.startTime), + timestamp: spanTimeInputToSeconds(span.endTime), transaction: description, type: 'transaction', sdkProcessingMetadata: { @@ -294,9 +294,9 @@ function createAndFinishSpanForOtelSpan(node: SpanNode, spans: SpanJSON[], remai data: allData, description, parent_span_id: parentSpanId, - start_timestamp: convertOtelTimeToSeconds(startTime), + start_timestamp: spanTimeInputToSeconds(startTime), // This is [0,0] by default in OTEL, in which case we want to interpret this as no end time - timestamp: convertOtelTimeToSeconds(endTime) || undefined, + timestamp: spanTimeInputToSeconds(endTime) || undefined, status: getStatusMessage(status), // As per protocol, span status is allowed to be undefined op, origin, diff --git a/packages/opentelemetry/src/utils/convertOtelTimeToSeconds.ts b/packages/opentelemetry/src/utils/convertOtelTimeToSeconds.ts deleted file mode 100644 index 64087aeffc4d..000000000000 --- a/packages/opentelemetry/src/utils/convertOtelTimeToSeconds.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** Convert an OTEL time to seconds */ -export function convertOtelTimeToSeconds([seconds, nano]: [number, number]): number { - return seconds + nano / 1_000_000_000; -} diff --git a/packages/opentelemetry/test/utils/convertOtelTimeToSeconds.test.ts b/packages/opentelemetry/test/utils/convertOtelTimeToSeconds.test.ts deleted file mode 100644 index 4f4911cee0cb..000000000000 --- a/packages/opentelemetry/test/utils/convertOtelTimeToSeconds.test.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { convertOtelTimeToSeconds } from '../../src/utils/convertOtelTimeToSeconds'; - -describe('convertOtelTimeToSeconds', () => { - it('works', () => { - expect(convertOtelTimeToSeconds([0, 0])).toEqual(0); - expect(convertOtelTimeToSeconds([1000, 50])).toEqual(1000.00000005); - expect(convertOtelTimeToSeconds([1000, 505])).toEqual(1000.000000505); - }); -});