mirror of
https://github.com/simstudioai/sim.git
synced 2026-09-24 15:45:35 +08:00
* feat(db): attribute Postgres connections by runtime via application_name * improvement(db): label migration-runner connection sim-migrate; trim DB_APP_NAME comment * fix(db): label realtime's shared @sim/db connections sim-realtime too The realtime process uses both its own socketDb pool and the shared @sim/db client (handlers, preflight, permissions). Only socketDb was labeled, so the shared client defaulted to sim-app, mislabeling much of realtime's DB traffic. Set DB_APP_NAME=sim-realtime at the process level (bootstrap before the dynamic @/index import for prod; dev/start scripts for local) so both clients report it.
86 lines
3.0 KiB
TypeScript
86 lines
3.0 KiB
TypeScript
import { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-http'
|
|
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http'
|
|
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'
|
|
import { resourceFromAttributes } from '@opentelemetry/resources'
|
|
import {
|
|
additionalFiles,
|
|
additionalPackages,
|
|
syncEnvVars,
|
|
} from '@trigger.dev/build/extensions/core'
|
|
import { defineConfig } from '@trigger.dev/sdk'
|
|
import { env } from './lib/core/config/env'
|
|
import { parseOtlpHeaders } from './lib/monitoring/otlp'
|
|
|
|
const grafanaEndpoint = env.GRAFANA_OTLP_ENDPOINT
|
|
const grafanaHeaders = env.GRAFANA_OTLP_HEADERS
|
|
const grafanaDeploymentEnvironment = env.GRAFANA_DEPLOYMENT_ENVIRONMENT
|
|
const grafanaConfigured = Boolean(grafanaEndpoint || grafanaHeaders || grafanaDeploymentEnvironment)
|
|
const grafanaFullyConfigured = Boolean(
|
|
grafanaEndpoint && grafanaHeaders && grafanaDeploymentEnvironment
|
|
)
|
|
|
|
if (grafanaConfigured && !grafanaFullyConfigured) {
|
|
throw new Error(
|
|
'Grafana OTLP telemetry is partially configured. Set GRAFANA_OTLP_ENDPOINT, GRAFANA_OTLP_HEADERS, and GRAFANA_DEPLOYMENT_ENVIRONMENT together, or leave all three unset.'
|
|
)
|
|
}
|
|
|
|
const grafanaTelemetry = grafanaFullyConfigured
|
|
? (() => {
|
|
const baseUrl = grafanaEndpoint!.replace(/\/+$/, '')
|
|
const headers = parseOtlpHeaders(grafanaHeaders!)
|
|
if (Object.keys(headers).length === 0) {
|
|
throw new Error(
|
|
'GRAFANA_OTLP_HEADERS is set but yielded no valid key=value pairs. Expected format: "key1=value1,key2=value2".'
|
|
)
|
|
}
|
|
const resource = resourceFromAttributes({
|
|
'deployment.environment.name': grafanaDeploymentEnvironment!,
|
|
})
|
|
return {
|
|
exporters: [new OTLPTraceExporter({ url: `${baseUrl}/v1/traces`, headers })],
|
|
logExporters: [new OTLPLogExporter({ url: `${baseUrl}/v1/logs`, headers })],
|
|
metricExporters: [new OTLPMetricExporter({ url: `${baseUrl}/v1/metrics`, headers })],
|
|
resource,
|
|
}
|
|
})()
|
|
: undefined
|
|
|
|
export default defineConfig({
|
|
project: env.TRIGGER_PROJECT_ID!,
|
|
runtime: 'node-22',
|
|
logLevel: 'log',
|
|
maxDuration: 5400,
|
|
retries: {
|
|
enabledInDev: false,
|
|
default: {
|
|
maxAttempts: 1,
|
|
},
|
|
},
|
|
dirs: ['./background'],
|
|
...(grafanaTelemetry ? { telemetry: grafanaTelemetry } : {}),
|
|
build: {
|
|
external: ['isolated-vm', '@earendil-works/pi-coding-agent', 'cpu-features'],
|
|
extensions: [
|
|
syncEnvVars(() => [{ name: 'DB_APP_NAME', value: 'sim-trigger' }]),
|
|
additionalFiles({
|
|
files: [
|
|
'./lib/execution/isolated-vm-worker.cjs',
|
|
'./lib/execution/sandbox/bundles/pptxgenjs.cjs',
|
|
'./lib/execution/sandbox/bundles/docx.cjs',
|
|
'./lib/execution/sandbox/bundles/pdf-lib.cjs',
|
|
],
|
|
}),
|
|
additionalPackages({
|
|
packages: [
|
|
'unpdf',
|
|
'isolated-vm',
|
|
'react-dom',
|
|
'@react-email/render',
|
|
'@earendil-works/pi-coding-agent',
|
|
],
|
|
}),
|
|
],
|
|
},
|
|
})
|