diff --git a/src/tracing/decorators/span.ts b/src/tracing/decorators/span.ts index 5ef8e55..810f5a8 100644 --- a/src/tracing/decorators/span.ts +++ b/src/tracing/decorators/span.ts @@ -1,21 +1,14 @@ -import { context, trace } from '@opentelemetry/api'; +import { trace } from '@opentelemetry/api'; export function Span(name?: string) { - return ( - target: any, - propertyKey: string, - propertyDescriptor: PropertyDescriptor, - ) => { + return (target: any, propertyKey: string, propertyDescriptor: PropertyDescriptor) => { const method = propertyDescriptor.value; // eslint-disable-next-line no-param-reassign propertyDescriptor.value = function PropertyDescriptor(...args: any[]) { - const currentSpan = trace.getSpan(context.active()); const tracer = trace.getTracer('default'); + const spanName = name || `${target.constructor.name}.${propertyKey}`; - return context.with(trace.setSpan(context.active(), currentSpan), () => { - const span = tracer.startSpan( - name || `${target.constructor.name}.${propertyKey}`, - ); + return tracer.startActiveSpan(spanName, span => { if (method.constructor.name === 'AsyncFunction') { return method.apply(this, args).finally(() => { span.end();