Skip to content

Commit d2b8d94

Browse files
committed
Update createSpan
1 parent 8b4c773 commit d2b8d94

File tree

1 file changed

+21
-28
lines changed

1 file changed

+21
-28
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { SpanContext, TimeInput } from '@opentelemetry/api';
2-
import { SpanKind } from '@opentelemetry/api';
2+
import { context, trace, SpanKind } from '@opentelemetry/api';
33
import type { SpanProcessor } from '@opentelemetry/sdk-trace-node';
44
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
55
import { uuid4 } from '@sentry/core';
@@ -31,36 +31,29 @@ export function createSpan(
3131
});
3232

3333
const tracer = provider.getTracer('test-instrumentation-library');
34+
const tId = traceId || uuid4();
3435

35-
// const tracer = {
36-
// resource: 'test-resource',
37-
// instrumentationLibrary: 'test-instrumentation-library',
38-
// getSpanLimits: () => ({}),
39-
// getActiveSpanProcessor: () => spanProcessor,
40-
// } as unknown as Tracer;
36+
const parentSpan = tracer.startSpan(name || 'test', {
37+
kind: SpanKind.INTERNAL,
38+
links: [],
39+
startTime,
40+
});
4141

42-
const tId = traceId || uuid4();
42+
parentSpan.spanContext().spanId = parentSpanId || uuid4();
43+
parentSpan.spanContext().traceId = tId;
44+
parentSpan.spanContext().traceFlags = 0;
4345

44-
const parentSpanContext: SpanContext = {
45-
spanId: parentSpanId || uuid4(),
46-
traceId: tId,
47-
traceFlags: 0,
48-
};
46+
trace.setSpan(context.active(), parentSpan);
4947

50-
const spanContext: SpanContext = {
51-
spanId: spanId || uuid4(),
52-
traceId: tId,
53-
traceFlags: 0,
54-
};
48+
const childSpan = tracer.startSpan(name || 'test', {
49+
kind: SpanKind.INTERNAL,
50+
links: [],
51+
startTime,
52+
});
53+
54+
childSpan.spanContext().spanId = spanId || uuid4();
55+
childSpan.spanContext().traceId = tId;
56+
childSpan.spanContext().traceFlags = 0;
5557

56-
return tracer.startSpan(
57-
name || 'test',
58-
{
59-
kind: SpanKind.INTERNAL,
60-
links: [],
61-
spanContext,
62-
startTime,
63-
},
64-
parentSpanContext,
65-
);
58+
return childSpan;
6659
}

0 commit comments

Comments
 (0)