Skip to content

Commit 8ee214a

Browse files
feat(observability): export Trigger.dev telemetry to Grafana Cloud OTLP
Wire OTLP HTTP exporters for traces, logs, and metrics from the Trigger.dev runtime to Grafana Cloud. Auth uses Basic with instance ID and API token. Gated behind GRAFANA_OTLP_ENDPOINT, GRAFANA_INSTANCE_ID, and GRAFANA_API_TOKEN — all three must be set together or all unset; partial config throws at startup.
1 parent bdf9ffc commit 8ee214a

4 files changed

Lines changed: 37 additions & 0 deletions

File tree

apps/sim/lib/core/config/env.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ export const env = createEnv({
157157
LOG_LEVEL: z.enum(['DEBUG', 'INFO', 'WARN', 'ERROR']).optional(), // Minimum log level to display (defaults to ERROR in production, DEBUG in development)
158158
PROFOUND_API_KEY: z.string().min(1).optional(), // Profound analytics API key
159159
PROFOUND_ENDPOINT: z.string().url().optional(), // Profound analytics endpoint
160+
GRAFANA_OTLP_ENDPOINT: z.string().url().optional(), // Grafana Cloud OTLP HTTP gateway base URL (e.g., https://otlp-gateway-prod-us-east-0.grafana.net/otlp). Trigger.dev exporters append /v1/traces, /v1/logs, /v1/metrics.
161+
GRAFANA_INSTANCE_ID: z.string().min(1).optional(), // Grafana Cloud instance ID (Basic auth username for OTLP)
162+
GRAFANA_API_TOKEN: z.string().min(1).optional(), // Grafana Cloud API token (Basic auth password for OTLP)
160163

161164
// External Services
162165
BROWSERBASE_API_KEY: z.string().min(1).optional(), // Browserbase API key for browser automation

apps/sim/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
"@modelcontextprotocol/sdk": "1.29.0",
6666
"@monaco-editor/react": "4.7.0",
6767
"@opentelemetry/api": "^1.9.0",
68+
"@opentelemetry/exporter-logs-otlp-http": "^0.217.0",
69+
"@opentelemetry/exporter-metrics-otlp-proto": "^0.217.0",
6870
"@opentelemetry/exporter-trace-otlp-http": "^0.217.0",
6971
"@opentelemetry/resources": "^2.7.0",
7072
"@opentelemetry/sdk-node": "^0.217.0",

apps/sim/trigger.config.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,36 @@
1+
import { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-http'
2+
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-proto'
3+
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'
14
import { additionalFiles, additionalPackages } from '@trigger.dev/build/extensions/core'
25
import { defineConfig } from '@trigger.dev/sdk'
36
import { env } from './lib/core/config/env'
47

8+
const grafanaEndpoint = env.GRAFANA_OTLP_ENDPOINT
9+
const grafanaInstanceId = env.GRAFANA_INSTANCE_ID
10+
const grafanaToken = env.GRAFANA_API_TOKEN
11+
const grafanaConfigured = Boolean(grafanaEndpoint || grafanaInstanceId || grafanaToken)
12+
const grafanaFullyConfigured = Boolean(grafanaEndpoint && grafanaInstanceId && grafanaToken)
13+
14+
if (grafanaConfigured && !grafanaFullyConfigured) {
15+
throw new Error(
16+
'Grafana OTLP telemetry is partially configured. Set GRAFANA_OTLP_ENDPOINT, GRAFANA_INSTANCE_ID, and GRAFANA_API_TOKEN together, or leave all three unset.'
17+
)
18+
}
19+
20+
const grafanaTelemetry = grafanaFullyConfigured
21+
? (() => {
22+
const baseUrl = grafanaEndpoint!.replace(/\/+$/, '')
23+
const headers = {
24+
Authorization: `Basic ${Buffer.from(`${grafanaInstanceId}:${grafanaToken}`).toString('base64')}`,
25+
}
26+
return {
27+
exporters: [new OTLPTraceExporter({ url: `${baseUrl}/v1/traces`, headers })],
28+
logExporters: [new OTLPLogExporter({ url: `${baseUrl}/v1/logs`, headers })],
29+
metricExporters: [new OTLPMetricExporter({ url: `${baseUrl}/v1/metrics`, headers })],
30+
}
31+
})()
32+
: undefined
33+
534
export default defineConfig({
635
project: env.TRIGGER_PROJECT_ID!,
736
runtime: 'node-22',
@@ -14,6 +43,7 @@ export default defineConfig({
1443
},
1544
},
1645
dirs: ['./background'],
46+
...(grafanaTelemetry ? { telemetry: grafanaTelemetry } : {}),
1747
build: {
1848
external: ['isolated-vm'],
1949
extensions: [

bun.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)