OpenTelemetry instrumentation for bunyan
This module provides automatic instrumentation for injection of trace context to bunyan
.
Compatible with OpenTelemetry JS API and SDK 1.0+
.
Installation
npm install --save @opentelemetry/instrumentation-bunyan
Supported Versions
Usage
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { BunyanInstrumentation } = require('@opentelemetry/instrumentation-bunyan');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const provider = new NodeTracerProvider();
provider.register();
registerInstrumentations({
instrumentations: [
new BunyanInstrumentation({
logHook: (span, record) => {
record['resource.service.name'] = provider.resource.attributes['service.name'];
},
}),
],
});
bunyan.createLogger({ name: 'example' }).info('foo');
Fields added to bunyan records
For the current active span, the following will be added to the bunyan record:
trace_id
span_id
trace_flags
When no span context is active or the span context is invalid, injection is skipped.
Useful links
License
Apache 2.0 - See LICENSE for more information.