JSPM

@trace0/lambda-otel-logger

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 21
  • Score
    100M100P100Q57538F
  • License MIT

Zero-config OpenTelemetry-based logger for AWS Lambda Node.js functions

Package Exports

  • @trace0/lambda-otel-logger
  • @trace0/lambda-otel-logger/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@trace0/lambda-otel-logger) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@trace0/lambda-otel-logger

Zero-config OpenTelemetry-based logger for AWS Lambda Node.js functions.

Automatically captures all console log output, injects OTel trace context (traceId, spanId), and exports logs as OTLP JSON to the Trace0 ingest endpoint.

How it works

console.log() 
  → ConsoleAppender (captures + creates OTel LogRecord)
    → BatchLogProcessor (buffers during invocation)
      → OTLPJsonLogExporter (POST to Trace0 ingest endpoint)

Based on the OpenTelemetry Logs API specification.

Installation

npm install @trace0/lambda-otel-logger

Usage

1. Add as the first import in your Lambda handler entry point:

import '@trace0/lambda-otel-logger'; // must be first
import { flush } from '@trace0/lambda-otel-logger';

2. Call flush() at the end of every invocation:

export const handler = async (event: APIGatewayProxyEvent, context: Context) => {
  try {
    return await yourHandler(event, context);
  } finally {
    await flush(); // always flush before Lambda freezes
  }
};

3. Set environment variables:

OTEL_EXPORTER_OTLP_ENDPOINT=https://app.trace0hq.com/api
OTEL_EXPORTER_OTLP_HEADERS=X-API-KEY=YOUR_TRACE0_ENV_API_KEY

That's it. No changes to your existing console.log calls required.

Environment Variables

Variable Required Default Description
OTEL_EXPORTER_OTLP_ENDPOINT Yes Your Trace0 ingest endpoint
OTEL_EXPORTER_OTLP_HEADERS Yes Your Trace0 environment API key

Log Formats

The library handles all common logging patterns without any code changes:

// JSON string — message extracted as body, remaining fields as attributes
console.log(JSON.stringify({ message: 'User created', userId: '123' }));

// Plain string
console.log('Hello world');

// Multiple args
console.log('User created with Id:', userId);

// All severity levels supported
console.debug('Debug message');
console.info('Info message');
console.warn('Warning message');
console.error('Error message');

Log Record Format

Each log record is exported as OTLP JSON with the following fields:

{
  "timeUnixNano": "1234567890000000000",
  "severityNumber": 9,
  "severityText": "INFO",
  "body": { "stringValue": "User created" },
  "attributes": [
    { "key": "userId", "value": { "stringValue": "123" } }
  ],
  "traceId": "abc123...",
  "spanId": "def456..."
}

Requirements