Skip to content
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

feat(otel): Export & use spanTimeInputToSeconds for otel span exporter #12699

Merged
merged 2 commits into from
Jul 4, 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
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export {
getRootSpan,
getActiveSpan,
addChildSpanToSpan,
spanTimeInputToSeconds,
} from './utils/spanUtils';
export { parseSampleRate } from './utils/parseSampleRate';
export { applySdkMetadata } from './utils/sdkMetadata';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/utils/spanUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
12 changes: 6 additions & 6 deletions packages/opentelemetry/src/spanExporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ 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';
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';
Expand Down Expand Up @@ -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 } {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions packages/opentelemetry/src/utils/convertOtelTimeToSeconds.ts

This file was deleted.

This file was deleted.

Loading