The official Splunk documentation for this page is Connect Node.js trace data with logs. For instructions on how to contribute to the docs, see CONTRIBUTING.md.
The Splunk Distribution of OpenTelemetry JS automatically injects trace metadata into logs so that Node.js logging libraries can access it. You can use trace metadata to correlate traces with log events and explore logs in Observability Cloud.
The following logging librares are supported:
- Bunyan
- Pino
- Winston
The following attributes are automatically injected into logs:
- Trace information:
trace_id
,span_id
, andtrace_flags
- Resource attributes:
service.name
,service.version
, anddeployment.environment
(asservice.environment
)
The format of each log message depends on the logging library. The following is a sample log message formatted by the Pino library:
{"level":30,"time":1979374615686,"pid":728570,"hostname":"my_host","trace_id":"f8e261432221096329baf5e62090d856","span_id":"3235afe76b55fe51","trace_flags":"01","url":"/lkasd","msg":"request handler"}
To enable log injection, install the instrumentation package for your logging library:
@opentelemetry/instrumentation-bunyan @opentelemetry/instrumentation-pino @opentelemetry/instrumentation-winston
To inject trace data into formatted logs, refer to the documentation of each library.