-
Notifications
You must be signed in to change notification settings - Fork 533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pino instrumentation is not sending log message to the logHook method #2592
Comments
tl;dr: instrumentation-pino is working as designed. Though it isn't clear in the documentation, the record in reproI made the following change to your --- tracing.js.orig 2024-12-11 12:44:45
+++ tracing.js 2024-12-11 13:29:28
@@ -1,4 +1,4 @@
-const { BatchSpanProcessor, AlwaysOnSampler} = require("@opentelemetry/sdk-trace-base");
+const { SimpleSpanProcessor, BatchSpanProcessor, AlwaysOnSampler, ConsoleSpanExporter} = require("@opentelemetry/sdk-trace-base");
const { NodeTracerProvider } = require("@opentelemetry/sdk-trace-node");
const { Resource } = require("@opentelemetry/resources");
const {
@@ -24,7 +24,7 @@
if (config?.tracing?.enableDebug) {
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.ALL);
}
- const exporter = new OTLPTraceExporter(config.tracing);
+ const exporter = new ConsoleSpanExporter();
const provider = new NodeTracerProvider({
sampler: new AlwaysOnSampler(),
@@ -32,7 +32,7 @@
[SEMRESATTRS_SERVICE_NAME]: config.service_name,
}),
});
- provider.addSpanProcessor(new BatchSpanProcessor(exporter, config?.batchSpanProcessorConfig));
+ provider.addSpanProcessor(new SimpleSpanProcessor(exporter));
provider.register({
propagator: new B3Propagator({
injectEncoding: B3InjectEncoding.MULTI_HEADER,
@@ -57,6 +57,7 @@
{
enabled: true,
logHook: (span, record) => {
+ console.log('XXX logHook called with record=', record);
span.addEvent("log", record);
},
} Then I used this const {initTracing} = require('./tracing');
initTracing({
tracing: {}
});
const {trace} = require('@opentelemetry/api');
const pino = require('pino');
const tracer = trace.getTracer('example');
const log = pino();
tracer.startActiveSpan('manual-span', span => {
log.info('hi')
span.end();
}); For completeness, here is my {
"name": "asdf.20241211t084855",
"version": "1.0.0",
"main": "index.js",
"dependencies": {
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/exporter-trace-otlp-grpc": "^0.56.0",
"@opentelemetry/instrumentation": "^0.56.0",
"@opentelemetry/instrumentation-express": "^0.46.0",
"@opentelemetry/instrumentation-http": "^0.56.0",
"@opentelemetry/instrumentation-pino": "^0.45.0",
"@opentelemetry/propagator-b3": "^1.29.0",
"@opentelemetry/resources": "^1.29.0",
"@opentelemetry/sdk-trace-base": "^1.29.0",
"@opentelemetry/sdk-trace-node": "^1.29.0",
"@opentelemetry/semantic-conventions": "^1.28.0",
"pino": "^9.5.0"
}
} When I run that I see:
As you said, the log message is not sent to the
Going back to the original implementation of The original intent of the why is the log "message" there with instrumentation-winston?
why is it called "record" then?So why does what could be done here?Getting access to the log message in the Currently the Have you considered using the OpenTelemetry Logs signal and sending Pino log records via OTLP, rather than adding the log messages as Span Events? To do that you'd want a change to tracing.js something like this:
Then re-running main:
You can see that OpenTelemetry is emitting the LogRecord and separately the Span. The OpenTelemetry The main question is whether your current telemetry backend supports OTel Logs well or at all. |
What version of OpenTelemetry are you using?
What version of Node are you using?
v20.11.1
What did you do?
I am adding pino log messages to the my span using logHook of pino instrumentation. I tried with winston instrumentation. Log messages are adding to the span and able to see it in the jaager UI.
What did you expect to see?
I want log message should be there part of record parameter as like to winston. So I can add it in the span.
What did you see instead?
I don't see log message. But I see only traceId, spanId and trace flags.
Additional context
I am using jaeger all in one collector to collect the traces from my service. I am using GRPC OLTP Trace Exporter to export the traces. I have used pino logger for logging and registered pino instrumentation for automatic log correlation with span Id, trace ID.
tracing.js
The text was updated successfully, but these errors were encountered: