-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathcreateSpan.ts
40 lines (37 loc) · 1.07 KB
/
createSpan.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import type { Context, SpanContext, TimeInput } from '@opentelemetry/api';
import { SpanKind } from '@opentelemetry/api';
import type { Tracer } from '@opentelemetry/sdk-trace-base';
import { Span } from '@opentelemetry/sdk-trace-base';
import { uuid4 } from '@sentry/core';
export function createSpan(
name?: string,
{
spanId,
parentSpanId,
traceId,
startTime,
}: {
spanId?: string;
parentSpanId?: string;
traceId?: string;
startTime?: TimeInput;
} = {},
): Span {
const spanProcessor = {
onStart: () => {},
onEnd: () => {},
};
const tracer = {
resource: 'test-resource',
instrumentationLibrary: 'test-instrumentation-library',
getSpanLimits: () => ({}),
getActiveSpanProcessor: () => spanProcessor,
} as unknown as Tracer;
const spanContext: SpanContext = {
spanId: spanId || uuid4(),
traceId: traceId || uuid4(),
traceFlags: 0,
};
// eslint-disable-next-line deprecation/deprecation
return new Span(tracer, {} as Context, name || 'test', spanContext, SpanKind.INTERNAL, parentSpanId, [], startTime);
}