@loglayer/plugin-datadog-apm-trace-injector
Version:
Injects DataDog APM traces to logs in LogLayer.
58 lines (41 loc) • 2.27 kB
Markdown
//img.shields.io/npm/v/%40loglayer%2Fplugin-datadog-apm-trace-injector)](https://www.npmjs.com/package/@loglayer/plugin-datadog-apm-trace-injector)
[](https://www.npmjs.com/package/@loglayer/plugin-datadog-apm-trace-injector)
[](http://www.typescriptlang.org/)
A plugin for [LogLayer](https://loglayer.dev) 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`](https://github.com/DataDog/dd-trace-js) 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<string, any>) => void` | Optional. Error handler for tracer operation failures |
For more details, visit [https://loglayer.dev/plugins/datadog-apm-trace-injector](https://loglayer.dev/plugins/datadog-apm-trace-injector)
[![NPM Version](https: