Weekly downloads: 3.8 mln
https://www.npmjs.com/package/winston
import opentelemetry from '@opentelemetry/api';
import { Format, format } from 'logform';
import { createLogger } from 'winston';
function tracingFormat(): Format {
const tracer = opentelemetry.trace.getTracer('logform');
return format(info => {
const span = tracer.getCurrentSpan();
if (span) {
const context = span.context();
info['trace.id'] = context.traceId;
info['span.id'] = context.spanId;
}
return info;
})();
}
const logger = createLogger({
format: format.combine(tracingFormat(), format.json())
});
I think we can close this one since https://github.com/open-telemetry/opentelemetry-js/pull/736 has been closed ?
@pauldraper Hi. What is a solution for @opentelemetry/[email protected] ? we don't have tracer.getCurrentSpan() anymore
@pauldraper Hi. What is a solution for @opentelemetry/[email protected] ? we don't have
tracer.getCurrentSpan()anymore
You can get the currently active span by doing
import { context, getSpan, Span } from "@opentelemetry/api";
const span: Span | undefined = getSpan(context.active());
@pauldraper Hi. What is a solution for @opentelemetry/[email protected] ? we don't have
tracer.getCurrentSpan()anymoreYou can get the currently active span by doing
import { context, getSpan, Span } from "@opentelemetry/api"; const span: Span | undefined = getSpan(context.active());
Will this not require span.end()?
Will this not require span.end()?
Nope, you get a reference to an existing span or undefined. No span is created/started here. As the span here is started by someone else the responsibly to end it is still there not here.
Most helpful comment