Datadog APM Trace Injector Plugin for LogLayer
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.
Installation
This plugin requires the dd-trace library to be installed in your project:
npm install @loglayer/plugin-datadog-apm-trace-injector dd-traceUsage
// 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');Configuration
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<string, any>) => void |
Optional. Error handler for tracer operation failures |
Documentation
For more details, visit https://loglayer.dev/plugins/datadog-apm-trace-injector