Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@loglayer/plugin-datadog-apm-trace-injector

loglayer33.7kMIT1.0.7TypeScript support: included

Injects DataDog APM traces to logs in LogLayer.

logging, log, loglayer, plugin, datadog, trace, injector, stamp, apm, dd-trace

readme

Datadog APM Trace Injector Plugin for LogLayer

NPM Version NPM Downloads TypeScript

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-trace

Usage

// 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

changelog

LogLayer Changelog

Please visit the What's New page for latest updates.

Visit the home page to see changelog links for LogLayer packages.