-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathspanJsonToStreamedSpan.ts
More file actions
23 lines (21 loc) · 977 Bytes
/
spanJsonToStreamedSpan.ts
File metadata and controls
23 lines (21 loc) · 977 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import type { RawAttributes } from '../../attributes';
import type { SerializedStreamedSpan, SpanJSON, StreamedSpanJSON } from '../../types-hoist/span';
import { streamedSpanJsonToSerializedSpan } from '../../utils/spanUtils';
/**
* Converts a v1 SpanJSON (from a legacy transaction) to a serialized v2 StreamedSpan.
*/
export function spanJsonToSerializedStreamedSpan(span: SpanJSON): SerializedStreamedSpan {
const streamedSpan: StreamedSpanJSON = {
trace_id: span.trace_id,
span_id: span.span_id,
parent_span_id: span.parent_span_id,
name: span.description || '',
start_timestamp: span.start_timestamp,
end_timestamp: span.timestamp || span.start_timestamp,
status: !span.status || span.status === 'ok' || span.status === 'cancelled' ? 'ok' : 'error',
is_segment: false,
attributes: { ...(span.data as RawAttributes<Record<string, unknown>>) },
links: span.links,
};
return streamedSpanJsonToSerializedSpan(streamedSpan);
}