Skip to content

feat: Add OpenTelemetry instrumentation with Drizzle ORM tracing#47

Open
kubiks-bot[bot] wants to merge 1 commit into
mainfrom
feature/add-otel-instrumentation
Open

feat: Add OpenTelemetry instrumentation with Drizzle ORM tracing#47
kubiks-bot[bot] wants to merge 1 commit into
mainfrom
feature/add-otel-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, enabling distributed tracing and observability with Kubiks.

Changes

  • OpenTelemetry SDK Setup: Configured with Node.js SDK for comprehensive tracing
  • Auto-Instrumentation: Enabled for Express.js and HTTP layers
  • Drizzle ORM Tracing: Database query tracing with @kubiks/otel-drizzle
  • OTLP Exporter: Configured to send traces to Kubiks ingest endpoint
  • Environment Configuration: Added .env.example with all required environment variables

New Files

  • artifacts/api-server/src/instrumentation.ts - OpenTelemetry SDK initialization
  • artifacts/api-server/.env.example - Environment configuration template

Modified Files

  • artifacts/api-server/src/index.ts - Import instrumentation before app initialization
  • artifacts/api-server/package.json - Added dependencies (installed via pnpm)

Dependencies Added

  • @opentelemetry/sdk-node - Core SDK
  • @opentelemetry/auto-instrumentations-node - Auto-instrumentation for Node.js
  • @opentelemetry/exporter-trace-otlp-http - OTLP HTTP exporter
  • @opentelemetry/api - OpenTelemetry API
  • @opentelemetry/resources - Resource support
  • @opentelemetry/semantic-conventions - Semantic conventions
  • @kubiks/otel-drizzle - Drizzle ORM instrumentation

Configuration

Set these environment variables to enable tracing:

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

What's Traced

  • ✨ Express.js routes and middleware
  • ✨ HTTP requests and responses
  • ✨ Database queries via Drizzle ORM
  • ✨ Automatic error and performance metrics

Testing

The instrumentation will automatically:

  1. Start collecting traces when the server starts
  2. Send all traces to Kubiks at https://ingest.kubiks.app
  3. Gracefully shutdown and flush remaining traces on SIGTERM

No changes required to existing route handlers - instrumentation is transparent!


Summary by cubic

Add OpenTelemetry tracing to the API server with auto-instrumentation for Express/HTTP and Drizzle ORM, exporting spans to Kubiks via OTLP HTTP. Improves observability without changing route code.

  • New Features

    • Initialize tracing with @opentelemetry/sdk-node.
    • Auto-instrument express and http via @opentelemetry/auto-instrumentations-node.
    • Trace Drizzle queries using @kubiks/otel-drizzle (includes db.statement).
    • Export spans with @opentelemetry/exporter-trace-otlp-http to https://ingest.kubiks.app.
    • Load ./instrumentation before app setup to capture all spans.
    • Add .env.example with required OTEL/Kubiks variables and graceful SIGTERM flush.
  • Migration

    • Set env vars: OTEL_SERVICE_NAME, OTEL_EXPORTER_OTLP_ENDPOINT, and either OTEL_EXPORTER_OTLP_HEADERS with x-kubiks-key=... or KUBIKS_API_KEY.
    • No app changes needed; routes and handlers are traced automatically.

Written for commit a35b3fe. Summary will update on new commits.

Review in cubic

- Initialize OpenTelemetry SDK with auto-instrumentations
- Add Drizzle ORM instrumentation for database query tracing
- Configure OTLP exporter for Kubiks ingest endpoint
- Add environment variable configuration template
- Instrument Express.js and HTTP layers automatically
@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.

@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:07pm

@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.

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