Adapters
Send logs via OpenTelemetry Protocol (OTLP) to Grafana, Datadog, Honeycomb, and any compatible backend. Supports gRPC and HTTP transports.

The OTLP (OpenTelemetry Protocol) adapter sends logs in the standard OpenTelemetry format. This works with any OTLP-compatible backend including:

  • Grafana Cloud (Loki)
  • Datadog
  • Honeycomb
  • Jaeger
  • Splunk
  • New Relic
  • Self-hosted OpenTelemetry Collector

Installation

The OTLP adapter comes bundled with evlog:

import { createOTLPDrain } from 'evlog/otlp'

Quick Start

1. Set your OTLP endpoint

.env
OTLP_ENDPOINT=http://localhost:4318

2. Wire the drain to your framework

// server/plugins/evlog-drain.ts
import { createOTLPDrain } from 'evlog/otlp'

export default defineNitroPlugin((nitroApp) => {
  nitroApp.hooks.hook('evlog:drain', createOTLPDrain())
})

Configuration

The adapter reads configuration from multiple sources (highest priority first):

  1. Overrides passed to createOTLPDrain()
  2. Runtime config at runtimeConfig.otlp (Nuxt/Nitro only)
  3. Environment variables

Environment Variables

VariableNuxt aliasDescription
OTLP_ENDPOINTNUXT_OTLP_ENDPOINTOTLP HTTP endpoint (e.g., http://localhost:4318)
OTLP_SERVICE_NAMENUXT_OTLP_SERVICE_NAMEOverride service name
OTLP_HEADERSNUXT_OTLP_HEADERSCustom headers (format: Key=Value,Key2=Value2)
OTLP_AUTHNUXT_OTLP_AUTHShortcut for Authorization header

Standard OpenTelemetry variables are also supported as fallbacks:

VariableDescription
OTEL_EXPORTER_OTLP_ENDPOINTOTLP endpoint
OTEL_EXPORTER_OTLP_HEADERSHeaders in OTEL format
OTEL_SERVICE_NAMEService name

Runtime Config (Nuxt only)

nuxt.config.ts
export default defineNuxtConfig({
  runtimeConfig: {
    otlp: {
      endpoint: '', // Set via NUXT_OTLP_ENDPOINT
    },
  },
})

Override Options

const drain = createOTLPDrain({
  endpoint: 'http://localhost:4318',
  serviceName: 'my-api',
  headers: {
    'Authorization': 'Bearer xxx',
  },
  resourceAttributes: {
    'deployment.environment': 'staging',
  },
})

Full Configuration Reference

OptionTypeDefaultDescription
endpointstring-OTLP HTTP endpoint (required)
serviceNamestringFrom eventOverride service.name resource attribute
headersobject-Custom HTTP headers for authentication
resourceAttributesobject-Additional OTLP resource attributes
timeoutnumber5000Request timeout in milliseconds

Provider-Specific Setup

Grafana Cloud

  1. Go to your Grafana Cloud portal
  2. Navigate to Connections > Collector > OpenTelemetry
  3. Copy your OTLP endpoint and generate credentials
.env
OTLP_ENDPOINT=https://otlp-gateway-prod-us-central-0.grafana.net/otlp
OTEL_EXPORTER_OTLP_HEADERS=Authorization=Basic%20base64-encoded-credentials
Grafana uses URL-encoded headers. The %20 is a space character. The adapter automatically decodes this format.

Datadog

.env
OTLP_ENDPOINT=https://http-intake.logs.datadoghq.com
OTLP_HEADERS=DD-API-KEY=your-api-key

Local OpenTelemetry Collector

For development and testing, run a local collector:

otel-collector.yaml
receivers:
  otlp:
    protocols:
      http:
        endpoint: 0.0.0.0:4318

exporters:
  debug:
    verbosity: detailed

service:
  pipelines:
    logs:
      receivers: [otlp]
      exporters: [debug]
docker run --rm -p 4318:4318 \
  -v $(pwd)/otel-collector.yaml:/etc/otelcol/config.yaml \
  otel/opentelemetry-collector:latest
.env
OTLP_ENDPOINT=http://localhost:4318

OTLP Log Format

evlog maps wide events to the OTLP log format:

evlog FieldOTLP Field
levelseverityNumber / severityText
timestamptimeUnixNano
serviceResource attribute service.name
environmentResource attribute deployment.environment
versionResource attribute service.version
regionResource attribute cloud.region
traceIdtraceId
spanIdspanId
All other fieldsLog attributes

Severity Mapping

evlog LevelOTLP Severity NumberOTLP Severity Text
debug5DEBUG
info9INFO
warn13WARN
error17ERROR

Troubleshooting

Missing endpoint error

[evlog/otlp] Missing endpoint. Set OTLP_ENDPOINT or OTEL_EXPORTER_OTLP_ENDPOINT

Make sure your endpoint environment variable is set and the server was restarted.

401 Unauthorized

Your authentication headers may be missing or incorrect. Check:

  1. The OTEL_EXPORTER_OTLP_HEADERS format is correct
  2. Credentials are valid and not expired
  3. The endpoint URL is correct

404 Not Found

The adapter sends to /v1/logs. Make sure your endpoint:

  • Supports OTLP HTTP (not gRPC)
  • Is the base URL without /v1/logs suffix

Logs not appearing

  1. Check the server console for [evlog/otlp] error messages
  2. Test with a local collector first to verify the format
  3. Check your backend's ingestion delay (some have 1-2 minute delays)

Direct API Usage

For advanced use cases:

server/utils/otlp.ts
import { sendToOTLP, sendBatchToOTLP, toOTLPLogRecord } from 'evlog/otlp'

// Send a single event
await sendToOTLP(event, {
  endpoint: 'http://localhost:4318',
})

// Send multiple events
await sendBatchToOTLP(events, {
  endpoint: 'http://localhost:4318',
})

// Convert event to OTLP format (for inspection)
const otlpRecord = toOTLPLogRecord(event)

Next Steps