Transport for the LogLayer logging library for sending logs using the OpenTelemetry Logs SDK. This allows you to integrate logs with OpenTelemetry's observability ecosystem.
Compatible with OpenTelemetry JS API and SDK 1.0+
.
In most cases, you should use the OpenTelemetry Plugin instead as it stamps logs with trace context. Use this transport if you are using OpenTelemetry log processors, where the log processors do the actual shipping of logs.
A lot of the code is based on the @opentelemetry/winston-transport code, which is licensed under Apache 2.0.
npm install loglayer @loglayer/transport-opentelemetry serialize-error
Follow the OpenTelemetry Getting Started Guide to set up OpenTelemetry in your application.
import { LogLayer } from 'loglayer'
import { OpenTelemetryTransport } from '@loglayer/transport-opentelemetry'
import { serializeError } from 'serialize-error'
const logger = new LogLayer({
// This will send logs to the OpenTelemetry SDK
// Where it sends to depends on the configured logRecordProcessors in the SDK
transport: [new OpenTelemetryTransport({
// Optional: provide a custom error handler
onError: (error) => console.error('OpenTelemetry logging error:', error),
// Optional: disable the transport
enabled: process.env.NODE_ENV !== 'test',
// Optional: enable console debugging
consoleDebug: process.env.DEBUG === 'true',
// Optional: set minimum log level to process (defaults to 'trace')
level: 'info'
})],
errorSerializer: serializeError,
});
For more details and examples, visit https://loglayer.dev/transports/opentelemetry