examples/with-otel/README.md
This example shows a Turborepo monorepo with a local OpenTelemetry Collector, Prometheus, and Grafana for visualizing Turborepo's OTEL metrics.
Run the following command:
npx create-turbo@latest -e with-otel
This Turborepo includes the following packages/apps:
docs: a Next.js appweb: another Next.js app@repo/ui: a stub React component library shared by both web and docs applications@repo/eslint-config: eslint configurations (includes eslint-config-next and eslint-config-prettier)@repo/typescript-config: tsconfig.jsons used throughout the monorepoEach package/app is 100% TypeScript.
This Turborepo has some additional tools already setup for you:
The included docker-compose.yml starts:
otel-collector -- OTLP gRPC receiver with a debug exporter and Prometheus exporterprometheus -- scrapes metrics from the collectorgrafana -- pre-configured with a Turborepo dashboard (anonymous access enabled)| Service | Port |
|---|---|
| OTLP gRPC | 4317 |
| Collector metrics | 8888 |
| Prometheus exporter | 8889 |
| Prometheus UI | 9090 |
| Grafana UI | 3001 |
docker compose up -d
Confirm it's ready:
docker compose logs otel-collector
# Look for: "Everything is ready. Begin running and processing data."
macOS / Linux:
export TURBO_EXPERIMENTAL_OTEL_ENABLED=1
export TURBO_EXPERIMENTAL_OTEL_ENDPOINT=https://127.0.0.1:4317
export TURBO_EXPERIMENTAL_OTEL_RESOURCE="service.name=turborepo,env=local"
export TURBO_EXPERIMENTAL_OTEL_METRICS_TASK_DETAILS=1
Windows (PowerShell):
$env:TURBO_EXPERIMENTAL_OTEL_ENABLED=1
$env:TURBO_EXPERIMENTAL_OTEL_ENDPOINT="https://127.0.0.1:4317"
$env:TURBO_EXPERIMENTAL_OTEL_RESOURCE="service.name=turborepo,env=local"
$env:TURBO_EXPERIMENTAL_OTEL_METRICS_TASK_DETAILS=1
turbo build
Collector logs (debug exporter):
docker compose logs --tail=100 otel-collector
You should see entries like:
Metrics {"otelcol.component.id": "debug", "otelcol.signal": "metrics", "resource metrics": 1, "metrics": 4, "data points": 4}
Resource attributes:
-> env: Str(local)
-> service.name: Str(turborepo)
Metric #0
-> Name: turbo.run.duration_ms
Metric #1
-> Name: turbo.run.tasks.attempted
Metric #2
-> Name: turbo.run.tasks.failed
Metric #3
-> Name: turbo.run.tasks.cached
Prometheus UI: Click any of these links to open pre-filled queries:
{__name__=~"turbo_run_.+"}Grafana dashboard: Open http://localhost:3001 -- the Turborepo Runs dashboard is pre-configured and loads automatically. No login required. The dashboard includes:
docker compose down
Learn more about the power of Turborepo: