Skip to content

feat(enrichers): add OTel auto-instrumentation bridge via createOtelSpanEnricher#388

Draft
HugoRCD wants to merge 2 commits into
mainfrom
evl-182-f26e
Draft

feat(enrichers): add OTel auto-instrumentation bridge via createOtelSpanEnricher#388
HugoRCD wants to merge 2 commits into
mainfrom
evl-182-f26e

Conversation

@HugoRCD

@HugoRCD HugoRCD commented Jun 18, 2026

Copy link
Copy Markdown
Owner

Adds createOtelSpanEnricher to evlog/enrichers — a zero-dependency enricher that bridges evlog with the OpenTelemetry SDK when it's running.

How it works: The OTel API registers itself on globalThis[Symbol.for('opentelemetry.js.api.1')]. This enricher reads the active span from that global on first use (per enricher instance) and attaches traceId/spanId to evlog events.

Why this matters over the existing createTraceContextEnricher:

  • createTraceContextEnricher parses W3C traceparent headers — only works on the HTTP layer
  • createOtelSpanEnricher reads from OTel's async context manager — works for background jobs, queue consumers, internal spans, or any async context where OTel has propagated a span

Tradeoffs / constraints:

  • Per-instance lazy init: resolved once per createOtelSpanEnricher() call, on first event. If OTel registers after the enricher first fires, it won't be picked up (uncommon in practice)
  • Accesses Symbol.for('opentelemetry.js.api.1') which is OTel API's documented global key (stable across 1.x)
  • No new dependency added to the package

Usage:

import { createOtelSpanEnricher } from 'evlog/enrichers'

app.use(evlog({ enrich: createOtelSpanEnricher() }))

…tion bridge

Adds a zero-dependency enricher that reads the active OpenTelemetry span
from @opentelemetry/api's global singleton (Symbol.for('opentelemetry.js.api.1'))
and attaches traceId/spanId to evlog events automatically.

This bridges evlog with OTel auto-instrumentation: when the OTel SDK is running,
log events are correlated with active traces without any HTTP header parsing.
Works for background jobs and internal spans, not just HTTP-layer requests.
The enricher is a no-op when OTel is not present.

Generated with [Linear](https://linear.app/hrcd/issue/EVL-182/explore-otel-auto-instrumentation-for-evlog#agent-session-e90a8d6d)

Co-authored-by: linear-code[bot] <222613912+linear-code[bot]@users.noreply.github.com>
@vercel

vercel Bot commented Jun 18, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
evlog-docs Ready Ready Preview, Comment, Open in v0 Jun 18, 2026 2:40pm
just-use-evlog Ready Ready Preview, Comment Jun 18, 2026 2:40pm

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: b9d62fdc-6804-4bdb-81f0-2185796f7d22

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch evl-182-f26e

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Hey there and thank you for opening this pull request! 👋🏼

We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted.

Details:

Unknown scope "enrichers" found in pull request title "feat(enrichers): add OTel auto-instrumentation bridge via createOtelSpanEnricher". Scope must match one of: ai, axiom, bench, better-auth, better-stack, core, datadog, deps, docs, dx, elysia, express, fastify, fs, hono, hyperdx, nestjs, next, nitro, nuxt, orpc, otlp, playground, posthog, react-router, release, repo, sentry, stream, sveltekit, tanstack-start, vite, workers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant