Skip to content

feat: Add OpenTelemetry instrumentation with Drizzle ORM support#46

Open
kubiks-bot[bot] wants to merge 2 commits into
mainfrom
feature/add-opentelemetry-instrumentation
Open

feat: Add OpenTelemetry instrumentation with Drizzle ORM support#46
kubiks-bot[bot] wants to merge 2 commits into
mainfrom
feature/add-opentelemetry-instrumentation

Conversation

@kubiks-bot

@kubiks-bot kubiks-bot Bot commented Jun 10, 2026

Copy link
Copy Markdown

Overview

This PR adds comprehensive OpenTelemetry instrumentation to the API server with automatic Drizzle ORM database query tracing.

Changes

  • ✅ Install OpenTelemetry SDK packages:

    • @opentelemetry/sdk-node - Core SDK
    • @opentelemetry/auto-instrumentations-node - Auto instrumentation for Node.js
    • @opentelemetry/exporter-trace-otlp-http - OTLP HTTP exporter
    • @kubiks/otel-drizzle - Drizzle ORM-specific instrumentation
  • ✅ Create src/instrumentation.ts to:

    • Initialize OpenTelemetry SDK
    • Configure OTLP exporter pointing to Kubiks
    • Enable automatic instrumentation for Node.js
    • Register Drizzle ORM instrumentation for database query tracing
    • Handle graceful shutdown on SIGTERM
  • ✅ Update src/index.ts to import instrumentation first (before other modules)

  • ✅ Add .env.example with required OpenTelemetry configuration:

    • OTEL_EXPORTER_OTLP_ENDPOINT - Kubiks ingestion endpoint
    • OTEL_EXPORTER_OTLP_HEADERS - API key authentication
    • OTEL_SERVICE_NAME - Service identifier

Features

  • Automatic HTTP request tracing via Express
  • Database query tracing for all Drizzle ORM operations (SELECT, INSERT, UPDATE, DELETE)
  • Automatic error tracking and span status propagation
  • Graceful service shutdown with trace flushing

Environment Configuration

Add these environment variables to your .env:

OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.kubiks.app
OTEL_EXPORTER_OTLP_HEADERS=x-kubiks-key=YOUR_KUBIKS_API_KEY
OTEL_SERVICE_NAME=api-server

What Gets Traced

  • HTTP Requests: All Express endpoints automatically traced
  • Database Queries: Drizzle ORM SELECT, INSERT, UPDATE, DELETE operations
  • Errors: Failed operations are marked with error status
  • Performance: Duration of all operations measured

Next Steps

  1. Merge this PR
  2. Set environment variables in your deployment
  3. Deploy and monitor traces in Kubiks dashboard
  4. Check out additional integrations for Autumn, Resend, QStash, etc. as needed

Summary by cubic

Add OpenTelemetry to the API server with automatic HTTP and Drizzle ORM tracing, exporting spans to Kubiks via OTLP HTTP. The SDK now starts before Express by preloading instrumentation in build and start.

  • New Features

    • Initialize OTel SDK with Node auto‑instrumentations (Express) and @kubiks/otel-drizzle.
    • Export traces via @opentelemetry/exporter-trace-otlp-http; flush on SIGTERM.
    • Load instrumentation before the app: include src/instrumentation.ts in the build, preload ./dist/instrumentation.mjs in start, and import ./instrumentation in src/index.ts.
  • Migration

    • Set OTEL_EXPORTER_OTLP_ENDPOINT (default https://ingest.kubiks.app), OTEL_EXPORTER_OTLP_HEADERS (x-kubiks-key=YOUR_KUBIKS_API_KEY), and OTEL_SERVICE_NAME.
    • Deploy and verify traces in the Kubiks dashboard.

Written for commit 408fd16. Summary will update on new commits.

Review in cubic

- Add @opentelemetry/sdk-node and related packages
- Add @kubiks/otel-drizzle for database query tracing
- Create instrumentation.ts to initialize OpenTelemetry
- Configure OTLP exporter for Kubiks ingestion
- Add environment variable configuration
- Update entry point to load instrumentation
@vercel

vercel Bot commented Jun 10, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
sanbox Ready Ready Preview, Comment Jun 10, 2026 2:08pm

@snyk-io

snyk-io Bot commented Jun 10, 2026

Copy link
Copy Markdown

Snyk checks have failed. 2 issues have been found so far.

Status Scan Engine Critical High Medium Low Total (2)
Open Source Security 0 1 1 0 2 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@kilo-code-bot

kilo-code-bot Bot commented Jun 10, 2026

Copy link
Copy Markdown

Kilo Code Review could not run — your account is out of credits.

Add credits or switch to a free model to enable reviews on this change.

- Update build.mjs to include instrumentation.ts as entry point
- Update start script to require instrumentation file before index.mjs
- This ensures OpenTelemetry SDK is initialized before the Express app starts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants