From 5537fe85ed65444359bfd066707760d6395fc7a4 Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Mon, 29 Dec 2025 19:11:16 +0200 Subject: feat: Add open telemetry (#2318) * feat: add OpenTelemetry tracing infrastructure Introduce distributed tracing capabilities using OpenTelemetry: - Add @opentelemetry packages to shared-server for tracing - Create tracing utility module with span helpers (withSpan, addSpanEvent, etc.) - Add tRPC middleware for automatic span creation on API calls - Initialize tracing in API and workers entry points - Add demo instrumentation to bookmark creation and crawler worker - Add configuration options (OTEL_TRACING_ENABLED, OTEL_EXPORTER_OTLP_ENDPOINT, etc.) - Document tracing configuration in environment variables docs When enabled, traces are collected for tRPC calls, bookmark creation flow, and crawler operations, with support for any OTLP-compatible backend (Jaeger, Tempo, etc.) * refactor: remove tracing from workers for now Keep tracing infrastructure but remove worker instrumentation: - Remove tracing initialization from workers entry point - Remove tracing instrumentation from crawler worker - Fix formatting in tracing files The tracing infrastructure remains available for future use. * add hono and next tracing * remove extra span logging * more fixes * update config * some fixes * upgrade packages * remove unneeded packages --------- Co-authored-by: Claude --- packages/shared/config.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'packages/shared') diff --git a/packages/shared/config.ts b/packages/shared/config.ts index c10634e2..28dcc624 100644 --- a/packages/shared/config.ts +++ b/packages/shared/config.ts @@ -211,6 +211,12 @@ const allEnv = z.object({ // Database configuration DB_WAL_MODE: stringBool("false"), + + // OpenTelemetry tracing configuration + OTEL_TRACING_ENABLED: stringBool("false"), + OTEL_EXPORTER_OTLP_ENDPOINT: z.string().url().optional(), + OTEL_SERVICE_NAME: z.string().default("karakeep"), + OTEL_SAMPLE_RATE: z.coerce.number().min(0).max(1).default(1.0), }); const serverConfigSchema = allEnv.transform((val, ctx) => { @@ -413,6 +419,12 @@ const serverConfigSchema = allEnv.transform((val, ctx) => { database: { walMode: val.DB_WAL_MODE, }, + tracing: { + enabled: val.OTEL_TRACING_ENABLED, + otlpEndpoint: val.OTEL_EXPORTER_OTLP_ENDPOINT, + serviceName: val.OTEL_SERVICE_NAME, + sampleRate: val.OTEL_SAMPLE_RATE, + }, }; if (obj.auth.emailVerificationRequired && !obj.email.smtp) { ctx.addIssue({ -- cgit v1.2.3-70-g09d2