aboutsummaryrefslogtreecommitdiffstats
path: root/packages/api/index.ts
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2025-12-29 19:11:16 +0200
committerGitHub <noreply@github.com>2025-12-29 17:11:16 +0000
commit5537fe85ed65444359bfd066707760d6395fc7a4 (patch)
tree03024b1312f04d9cd4ff09b327eae7cea3f258a9 /packages/api/index.ts
parentf7920bdc94d97a6a94477f49e145432607b94951 (diff)
downloadkarakeep-5537fe85ed65444359bfd066707760d6395fc7a4.tar.zst
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 <noreply@anthropic.com>
Diffstat (limited to 'packages/api/index.ts')
-rw-r--r--packages/api/index.ts17
1 files changed, 16 insertions, 1 deletions
diff --git a/packages/api/index.ts b/packages/api/index.ts
index 3df7b429..ac31c977 100644
--- a/packages/api/index.ts
+++ b/packages/api/index.ts
@@ -1,9 +1,11 @@
+import { httpInstrumentationMiddleware } from "@hono/otel";
import { Hono } from "hono";
import { cors } from "hono/cors";
import { logger as loggerMiddleware } from "hono/logger";
import { poweredBy } from "hono/powered-by";
import { loadAllPlugins } from "@karakeep/shared-server";
+import serverConfig from "@karakeep/shared/config";
import logger from "@karakeep/shared/logger";
import { Context } from "@karakeep/trpc";
@@ -52,7 +54,20 @@ const app = new Hono<{
logger.info(str);
}),
)
- .use(poweredBy())
+ .use(poweredBy());
+
+// Add OpenTelemetry middleware if tracing is enabled
+if (serverConfig.tracing.enabled) {
+ app.use(
+ "*",
+ httpInstrumentationMiddleware({
+ serviceName: `${serverConfig.tracing.serviceName}-api`,
+ serviceVersion: serverConfig.serverVersion ?? "unknown",
+ }),
+ );
+}
+
+app
.use(
cors({
origin: "*",