OpenTelemetry instrumentation for bunyan
This module provides automatic instrumentation for injection of trace context to bunyan
.
Installation
npm install --save @opentelemetry/instrumentation-bunyan
Usage
const { NodeTracerProvider } = require('@opentelemetry/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.