OpenTelemetry SDK Setup Issue with TanStack Start
I'm trying to set up OpenTelemetry in my TanStack Start project but running into build errors.
My Setup
- TanStack Start with
cloudflare-module
target
- Installed @opentelemetry/sdk-node
- Call setupOtel()
function in server.ts
The Problem
When I run the build script ( vite build && tsc --noEmit
), I get this error:
The error happens after the Building Nitro Server (preset: cloudflare-module, compatibility date: 2024-11-13)
log line.
What I've Tried
1. Installing the missing package - Adding @opentelemetry/exporter-jaeger
just creates a new issue (same issue mentioned in this GitHub issue)
2. Setting external packages - Tried ssr.external: ["@opentelemetry/sdk-node"]
in Vite config (no effect)
3. Server-only setup - Only importing OTEL on server side still fails:
4. Excluding from optimization - Added "@opentelemetry/sdk-node"
to optimizeDeps.exclude
in Vite config
My setupOtel
Function
Looking For Help
Has anyone successfully set up OpenTelemetry with TanStack Start and Cloudflare? Any advice on the right configuration would be helpful.
The NextJS solutions I found don't seem to apply here, so I'm wondering if there's a TanStack Start specific approach I'm missing.3 Replies
wise-whiteOP•6d ago
Update: interestingly, this error only surfaces for cloudflare worker builds. I switched my target to netlify, and this error does not occur.
genetic-orange•5d ago
seems like
@opentelemetry/sdk-node
does not work on cloudflaregenetic-orange•5d ago
an alternative might be https://github.com/evanderkoogh/otel-cf-workers
GitHub
GitHub - evanderkoogh/otel-cf-workers: An OpenTelemetry compatible ...
An OpenTelemetry compatible library for instrumenting and exporting traces for Cloudflare Workers - evanderkoogh/otel-cf-workers