- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 1.3k
 
Setup otel/tracing example #5552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| node_modules | ||
| package-lock.json | ||
| yarn.lock | ||
| 
     | 
||
| .DS_Store | ||
| .cache | ||
| .env | ||
| .vercel | ||
| .output | ||
| .nitro | ||
| /build/ | ||
| /api/ | ||
| /server/build | ||
| /public/build# Sentry Config File | ||
| .env.sentry-build-plugin | ||
| /test-results/ | ||
| /playwright-report/ | ||
| /blob-report/ | ||
| /playwright/.cache/ | ||
| .tanstack | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| **/build | ||
| **/public | ||
| pnpm-lock.yaml | ||
| routeTree.gen.ts | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "files.watcherExclude": { | ||
| "**/routeTree.gen.ts": true | ||
| }, | ||
| "search.exclude": { | ||
| "**/routeTree.gen.ts": true | ||
| }, | ||
| "files.readonlyInclude": { | ||
| "**/routeTree.gen.ts": true | ||
| } | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # Welcome to TanStack.com! | ||
| 
     | 
||
| This site is built with TanStack Router! | ||
| 
     | 
||
| - [TanStack Router Docs](https://tanstack.com/router) | ||
| 
     | 
||
| It's deployed automagically with Netlify! | ||
| 
     | 
||
| - [Netlify](https://netlify.com/) | ||
| 
     | 
||
| ## Development | ||
| 
     | 
||
| From your terminal: | ||
| 
     | 
||
| ```sh | ||
| pnpm install | ||
| pnpm dev | ||
| ``` | ||
| 
     | 
||
| This starts your app in development mode, rebuilding assets on file changes. | ||
| 
     | 
||
| ## Editing and previewing the docs of TanStack projects locally | ||
| 
     | 
||
| The documentations for all TanStack projects except for `React Charts` are hosted on [https://tanstack.com](https://tanstack.com), powered by this TanStack Router app. | ||
| In production, the markdown doc pages are fetched from the GitHub repos of the projects, but in development they are read from the local file system. | ||
| 
     | 
||
| Follow these steps if you want to edit the doc pages of a project (in these steps we'll assume it's [`TanStack/form`](https://github.com/tanstack/form)) and preview them locally : | ||
| 
     | 
||
| 1. Create a new directory called `tanstack`. | ||
| 
     | 
||
| ```sh | ||
| mkdir tanstack | ||
| ``` | ||
| 
     | 
||
| 2. Enter the directory and clone this repo and the repo of the project there. | ||
| 
     | 
||
| ```sh | ||
| cd tanstack | ||
| git clone git@github.com:TanStack/tanstack.com.git | ||
| git clone git@github.com:TanStack/form.git | ||
| ``` | ||
| 
     | 
||
| > [!NOTE] | ||
| > Your `tanstack` directory should look like this: | ||
| > | ||
| > ``` | ||
| > tanstack/ | ||
| > | | ||
| > +-- form/ | ||
| > | | ||
| > +-- tanstack.com/ | ||
| > ``` | ||
| > [!WARNING] | ||
| > Make sure the name of the directory in your local file system matches the name of the project's repo. For example, `tanstack/form` must be cloned into `form` (this is the default) instead of `some-other-name`, because that way, the doc pages won't be found. | ||
| 3. Enter the `tanstack/tanstack.com` directory, install the dependencies and run the app in dev mode: | ||
| ```sh | ||
| cd tanstack.com | ||
| pnpm i | ||
| # The app will run on https://localhost:3000 by default | ||
| pnpm dev | ||
| ``` | ||
| 4. Now you can visit http://localhost:3000/form/latest/docs/overview in the browser and see the changes you make in `tanstack/form/docs`. | ||
| 
     | 
||
| > [!NOTE] | ||
| > The updated pages need to be manually reloaded in the browser. | ||
| > [!WARNING] | ||
| > You will need to update the `docs/config.json` file (in the project's repo) if you add a new doc page! | ||
| 
         
      Comment on lines
    
      +1
     to 
      +72
    
   
  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace README content to match the OTEL example. The README describes the TanStack.com documentation site workflow, including instructions for editing docs across TanStack projects. However, this is the  The README should describe: 
 Apply this diff to provide appropriate documentation: -# Welcome to TanStack.com!
+# TanStack Start + OpenTelemetry Example
 
-This site is built with TanStack Router!
+This example demonstrates OpenTelemetry tracing integration with TanStack Router and React Start.
 
-- [TanStack Router Docs](https://tanstack.com/router)
-
-It's deployed automagically with Netlify!
-
-- [Netlify](https://netlify.com/)
+## Features
+
+- Manual OpenTelemetry instrumentation
+- Jaeger for trace visualization
+- Server-side tracing with TanStack Start
 
 ## Development
 
-From your terminal:
+1. Start the Jaeger instance:
 
 ```sh
-pnpm install
-pnpm dev
+docker-compose up -d-This starts your app in development mode, rebuilding assets on file changes.-## Editing and previewing the docs of TanStack projects locally-The documentations for all TanStack projects except for 
 | 
||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| version: "3.9" | ||
| services: | ||
| jaeger: | ||
| image: jaegertracing/all-in-one:1.57 | ||
| container_name: jaeger | ||
| environment: | ||
| - COLLECTOR_OTLP_ENABLED=true | ||
| ports: | ||
| - "16686:16686" # Jaeger UI | ||
| - "4317:4317" # OTLP gRPC | ||
| - "4318:4318" # OTLP HTTP (used by app) | ||
| restart: unless-stopped | ||
| 
     | 
||
| 
     | 
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,36 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "name": "tanstack-start-example-otel", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "private": true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "sideEffects": false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "type": "module", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "scripts": { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "dev": "vite dev", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "build": "vite build && tsc --noEmit", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "start": "node .output/server/index.mjs" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 
         
      Comment on lines
    
      +6
     to 
      +10
    
   
  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chainVerify the start script output path. Vite usually emits to dist/ by default; the script starts .output/server/index.mjs. Ensure your build config writes to .output/server. 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Check for vite config and SSR/output settings
fd -HI '^vite\.config\.(ts|mjs|js)$' .
rg -n --no-messages -C2 'outDir|ssr|build' $(fd -HI '^vite\.config\.(ts|mjs|js)$' . || echo)
# Confirm referenced file exists (if already built)
test -f examples/react/start-otel/.output/server/index.mjs && echo "Found .output/server/index.mjs" || echo "Note: .output/server/index.mjs not present (build not run or outDir differs)."Length of output: 33906 #!/bin/bash
# Extract vite config for start-otel specifically
cat examples/react/start-otel/vite.config.tsLength of output: 416 Length of output: 1180 💡 Result: Short answer: TanStack Start's Vite plugin no longer always produces a .output folder by itself — to get the traditional .output server bundle you must enable Nitro in your Vite build (either Nitro v3's vite plugin or the compatibility @tanstack/nitro-v2-vite-plugin). Add the Nitro Vite plugin alongside tanstackStart and the framework plugin; Nitro will generate the .output/server entry (or a dist/ server bundle if you don't use the Nitro plugin). [1][2][3] Example (vite.config.ts): export default defineConfig({ Notes: 
 Sources: 
 Length of output: 590 Add Nitro plugin to vite.config.ts or update the start script path to match actual build output. The vite.config.ts for start-otel uses  🤖 Prompt for AI Agents | 
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "dependencies": { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "@opentelemetry/api": "^1.9.0", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "@opentelemetry/exporter-trace-otlp-proto": "^0.206.0", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "@opentelemetry/sdk-node": "^0.206.0", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "@opentelemetry/sdk-trace-node": "^2.1.0", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "@tanstack/react-router": "^1.133.15", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "@tanstack/react-router-devtools": "^1.133.15", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "@tanstack/react-start": "^1.133.15", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "react": "^19.0.0", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "react-dom": "^19.0.0", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "tailwind-merge": "^2.6.0", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "zod": "^3.24.2" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 
         
      Comment on lines
    
      +11
     to 
      +23
    
   
  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Use workspace: for internal TanStack packages in the monorepo.* This keeps examples pinned to local workspace builds and avoids version drift. -    "@tanstack/react-router": "^1.133.15",
-    "@tanstack/react-router-devtools": "^1.133.15",
-    "@tanstack/react-start": "^1.133.15",
+    "@tanstack/react-router": "workspace:*",
+    "@tanstack/react-router-devtools": "workspace:*",
+    "@tanstack/react-start": "workspace:*",As per coding guidelines. 📝 Committable suggestion
 
        Suggested change
       
    
 🤖 Prompt for AI Agents🧩 Analysis chainAlign OpenTelemetry package versions (avoid mixing 0.x, 1.x, 2.x). Mixing majors across OTel core packages can cause runtime incompatibilities. Align all @opentelemetry/* core packages to a single compatible line and avoid redundant SDKs (sdk-node vs sdk-trace-node). Example (illustrative — pick one coherent version set used by the repo): -    "@opentelemetry/api": "^1.9.0",
-    "@opentelemetry/exporter-trace-otlp-proto": "^0.206.0",
-    "@opentelemetry/sdk-node": "^0.206.0",
-    "@opentelemetry/sdk-trace-node": "^2.1.0",
+    "@opentelemetry/api": "^1.9.0",
+    "@opentelemetry/sdk-node": "<aligned-version>",
+    "@opentelemetry/exporter-trace-otlp-proto": "<aligned-version>",
+    // Remove if using sdk-node:
+    // "@opentelemetry/sdk-trace-node": "<aligned-version>",
+    // Optional but recommended for stable keys:
+    "@opentelemetry/semantic-conventions": "<aligned-version>",🏁 Script executed: #!/bin/bash
set -euo pipefail
pkg=examples/react/start-otel/package.json
echo "OTel package versions in $pkg"
jq -r '
  [.dependencies,.devDependencies]|add|to_entries
  | map(select(.key|startswith("@opentelemetry/")))
  | .[] | "\(.key) = \(.value)"
' "$pkg" | sort
echo
echo "Distinct major.minor groups:"
jq -r '
  [.dependencies,.devDependencies]|add|to_entries
  | map(select(.key|startswith("@opentelemetry/")))
  | .[] | .value
' "$pkg" | sed -E 's/[^0-9]*([0-9]+)\.([0-9]+).*/\1.\2/' | sort -uLength of output: 261 </web_search> 🏁 Script executed: #!/bin/bash
# Check for internal workspace dependencies in this package.json
echo "=== Internal dependencies in examples/react/start-otel/package.json ==="
jq -r '.dependencies | to_entries[] | select(.value | startswith("workspace:")) | "\(.key): \(.value)"' examples/react/start-otel/package.json 2>/dev/null || echo "No workspace dependencies found"
echo
# Find all package.json files in the repo and extract OTel versions
echo "=== OpenTelemetry versions across all package.json files ==="
find . -name "package.json" -type f | while read -r pf; do
  otel_count=$(jq -r '[.dependencies,.devDependencies]|add|to_entries|map(select(.key|startswith("@opentelemetry/")))|length' "$pf" 2>/dev/null || echo "0")
  if [ "$otel_count" -gt 0 ]; then
    echo "$pf:"
    jq -r '[.dependencies,.devDependencies]|add|to_entries|map(select(.key|startswith("@opentelemetry/")))|.[]|"\(.key) = \(.value)"' "$pf" 2>/dev/null | sort
    echo
  fi
done | head -100Length of output: 366 🌐 Web query: 💡 Result: Do you mean the OpenTelemetry package compatibilities between the "experimental" 0.* series and the "stable" 1.* / 2.* series (SDK/API/semantic-conventions packages)? If so, can you confirm which language or package (Java, JS, Python, semantic-conventions, Collector, etc.) you need the matrix for? 🌐 Web query: 💡 Result: Short answer 
 Compatibility guidance 
 Practical notes 
 If you want I can: 
 Sources Align OpenTelemetry package versions to a single major (currently mixing 0.x, 1.x, 2.x). Matching major versions is required to avoid API/behavior mismatches, and mix-and-matching 1.x and 2.x packages is not recommended. Your package.json currently has: 
 @opentelemetry/sdk-node and @opentelemetry/sdk-trace-node are designed to interoperate and should be used together. Align all  🤖 Prompt for AI Agents | 
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "devDependencies": { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "@types/node": "^22.5.4", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "@types/react": "^19.0.8", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "@types/react-dom": "^19.0.3", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "@vitejs/plugin-react": "^4.6.0", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "autoprefixer": "^10.4.20", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "postcss": "^8.5.1", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "tailwindcss": "^3.4.17", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "typescript": "^5.7.2", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "vite": "^7.1.7", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "vite-tsconfig-paths": "^5.1.4" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| export default { | ||
| plugins: { | ||
| tailwindcss: {}, | ||
| autoprefixer: {}, | ||
| }, | ||
| } | 
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,19 @@ | ||||||||||
| { | ||||||||||
| "name": "", | ||||||||||
| "short_name": "", | ||||||||||
| 
         
      Comment on lines
    
      +2
     to 
      +3
    
   
  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add placeholder values for PWA manifest names. The  Apply this diff to add example values: -  "name": "",
-  "short_name": "",
+  "name": "TanStack Router OTEL Example",
+  "short_name": "OTEL Example",📝 Committable suggestion
 
        Suggested change
       
    
 🤖 Prompt for AI Agents | 
||||||||||
| "icons": [ | ||||||||||
| { | ||||||||||
| "src": "/android-chrome-192x192.png", | ||||||||||
| "sizes": "192x192", | ||||||||||
| "type": "image/png" | ||||||||||
| }, | ||||||||||
| { | ||||||||||
| "src": "/android-chrome-512x512.png", | ||||||||||
| "sizes": "512x512", | ||||||||||
| "type": "image/png" | ||||||||||
| } | ||||||||||
| ], | ||||||||||
| "theme_color": "#ffffff", | ||||||||||
| "background_color": "#ffffff", | ||||||||||
| "display": "standalone" | ||||||||||
| } | ||||||||||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import { | ||
| ErrorComponent, | ||
| Link, | ||
| rootRouteId, | ||
| useMatch, | ||
| useRouter, | ||
| } from '@tanstack/react-router' | ||
| import type { ErrorComponentProps } from '@tanstack/react-router' | ||
| 
     | 
||
| export function DefaultCatchBoundary({ error }: ErrorComponentProps) { | ||
| const router = useRouter() | ||
| const isRoot = useMatch({ | ||
| strict: false, | ||
| select: (state) => state.id === rootRouteId, | ||
| }) | ||
| 
     | 
||
| console.error('DefaultCatchBoundary Error:', error) | ||
| 
     | 
||
| return ( | ||
| <div className="min-w-0 flex-1 p-4 flex flex-col items-center justify-center gap-6"> | ||
| <ErrorComponent error={error} /> | ||
| <div className="flex gap-2 items-center flex-wrap"> | ||
| <button | ||
| onClick={() => { | ||
| router.invalidate() | ||
| }} | ||
| className={`px-2 py-1 bg-gray-600 dark:bg-gray-700 rounded text-white uppercase font-extrabold`} | ||
| > | ||
| Try Again | ||
| </button> | ||
| {isRoot ? ( | ||
| <Link | ||
| to="/" | ||
| className={`px-2 py-1 bg-gray-600 dark:bg-gray-700 rounded text-white uppercase font-extrabold`} | ||
| > | ||
| Home | ||
| </Link> | ||
| ) : ( | ||
| <Link | ||
| to="/" | ||
| className={`px-2 py-1 bg-gray-600 dark:bg-gray-700 rounded text-white uppercase font-extrabold`} | ||
| onClick={(e) => { | ||
| e.preventDefault() | ||
| window.history.back() | ||
| }} | ||
| > | ||
| Go Back | ||
| </Link> | ||
| )} | ||
| </div> | ||
| </div> | ||
| ) | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { Link } from '@tanstack/react-router' | ||
| 
     | 
||
| export function NotFound({ children }: { children?: any }) { | ||
| return ( | ||
| <div className="space-y-2 p-2"> | ||
| <div className="text-gray-600 dark:text-gray-400"> | ||
| {children || <p>The page you are looking for does not exist.</p>} | ||
| </div> | ||
| <p className="flex items-center gap-2 flex-wrap"> | ||
| <button | ||
| onClick={() => window.history.back()} | ||
| className="bg-emerald-500 text-white px-2 py-1 rounded uppercase font-black text-sm" | ||
| > | ||
| Go back | ||
| </button> | ||
| <Link | ||
| to="/" | ||
| className="bg-cyan-600 text-white px-2 py-1 rounded uppercase font-black text-sm" | ||
| > | ||
| Start Over | ||
| </Link> | ||
| </p> | ||
| </div> | ||
| ) | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { ErrorComponent } from '@tanstack/react-router' | ||
| import type { ErrorComponentProps } from '@tanstack/react-router' | ||
| 
     | 
||
| export function PostErrorComponent({ error }: ErrorComponentProps) { | ||
| return <ErrorComponent error={error} /> | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { ErrorComponent } from '@tanstack/react-router' | ||
| import type { ErrorComponentProps } from '@tanstack/react-router' | ||
| 
     | 
||
| export function UserErrorComponent({ error }: ErrorComponentProps) { | ||
| return <ErrorComponent error={error} /> | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { NodeSDK } from '@opentelemetry/sdk-node' | ||
| import { SimpleSpanProcessor } from '@opentelemetry/sdk-trace-node' | ||
| import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto' | ||
| 
     | 
||
| const sdk = new NodeSDK({ | ||
| serviceName: 'tanstack-start', | ||
| spanProcessors: [ | ||
| new SimpleSpanProcessor( | ||
| new OTLPTraceExporter({ | ||
| url: 'http://localhost:4318/v1/traces', | ||
| }), | ||
| ), | ||
| ], | ||
| }) | ||
| 
     | 
||
| sdk.start() | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix comment placement and formatting.
The Sentry Config File comment should be on its own line before
.env.sentry-build-plugin, not appended to the end of/public/build. Additionally,.gitignorefiles should end with a newline.Ensure the file ends with a newline after the last entry.
🤖 Prompt for AI Agents