Closed clifinger closed 3 weeks ago
Hello @clifinger, did you try the trace-context example? This is the most convenient way to have spanId and traceId in your logs.
If that's not acceptable for some reason, check this issue where we discussed an alternative to using pino instrumentation: https://github.com/pinojs/pino-opentelemetry-transport/issues/160
Hello @Vunovati,
To be honest, I like the way we currently handle observability in our project. I don't want my team to spend too much time implementing observability in new projects or functions.
For now, we just use:
--require '@opentelemetry/auto-instrumentations-node/register'
and
import { pino } from "pino";
import { context, trace } from "@opentelemetry/api";
const transport = pino.transport({
target: "pino-opentelemetry-transport",
});
const logger = pino(
{
mixin() {
const span = trace.getSpan(context.active());
if (span) {
return {
traceId: span.spanContext().traceId,
spanId: span.spanContext().spanId,
};
}
return {};
},
},
transport,
);
export default logger;
export type Logger = typeof logger;
We inject it, and everything works automatically.
Just to let you know,
To have the traceId and spanId with
@opentelemetry/auto-instrumentations-node
I had to specify it:Best regards