Injects DataDog APM traces to logs in LogLayer.
npm install @loglayer/plugin-datadog-apm-trace-injector


A plugin for LogLayer that automatically injects Datadog APM trace context into your logs. This enables correlation between your application logs and distributed traces in Datadog.
This plugin requires the dd-trace library to be installed in your project:
``bash`
npm install @loglayer/plugin-datadog-apm-trace-injector dd-trace
`typescript
// dd-trace generally needs to be the first import of any project
// as it needs to patch node_module packages before they are imported
import tracer from 'dd-trace';
import { LogLayer } from 'loglayer';
import { datadogTraceInjectorPlugin } from '@loglayer/plugin-datadog-apm-trace-injector';
tracer.init();
// Create the plugin
const traceInjector = datadogTraceInjectorPlugin({
tracerInstance: tracer,
// Enable the plugin only if the Datadog API key is set
disabled: !process.env.DD_API_KEY
});
// Add to your LogLayer instance
const log = new LogLayer({
plugins: [traceInjector],
});
// Your logs will now automatically include trace context
log.info('User action completed');
`
The plugin accepts the following configuration options:
| Option | Type | Description |
|--------|------|-------------|
| id | string | Optional. Unique identifier for the plugin |tracerInstance
| | Tracer | Required. The dd-trace tracer instance |disabled
| | boolean | Optional. Disable the plugin |onError
| | (error: Error, data?: Record
For more details, visit https://loglayer.dev/plugins/datadog-apm-trace-injector