Skip to content
Logixlysia
Esc
↑↓navigate↵open⌘Jpreview
On this page

OpenTelemetry

Correlate logs with active trace and span IDs

Install the optional peer dependency:

bun add @opentelemetry/api

Import from the logixlysia/otel subpath:

import { Elysia } from 'elysia'
import logixlysia from 'logixlysia'
import { otelEnricher } from 'logixlysia/otel'

const app = new Elysia()
  .use(logixlysia({ config: { enrichers: [otelEnricher()] } }))
  .get('/', () => 'ok')

otelEnricher() is a request-phase enricher, so the ids reach every sink. To merge them by hand instead, call injectTraceContext from onRequest:

import { Elysia } from 'elysia'
import logixlysia from 'logixlysia'
import { injectTraceContext } from 'logixlysia/otel'

const plugin = logixlysia()

const app = new Elysia()
  .use(plugin)
  .onRequest(({ request, store }) => {
    injectTraceContext(store.logger, request)
  })
  .get('/', () => 'ok')

When an active span exists, trace_id, span_id, trace_flags and trace_sampled are merged into the request context bag and appear on the access log and on every custom log line. trace_flags is the span’s flags byte as two hex digits, as in a traceparent header, and trace_sampled is true when its sampled bit is set. The OTLP and HyperDX adapters copy the two ids and the flags byte into each record’s native traceId, spanId and flags.

Logixlysia does not start an OpenTelemetry SDK—you bring your own tracer provider and instrumentation.

Was this page helpful?