Function: initTelemetry()
initTelemetry(
options):void
Defined in: src/observability/telemetry.ts:253
Initializes the OpenTelemetry SDK.
Parameters
options
TelemetryOptions = {}
Configuration options
Returns
void
Remarks
Must be called before the application starts to ensure all modules are instrumented. Sets up:
- Trace exporter (OTLP → OTEL Collector → Tempo)
- Metric exporter (OTLP → OTEL Collector → Prometheus)
- Auto-instrumentation for HTTP, PostgreSQL, Redis
Registers SIGTERM handler for graceful shutdown.
Example
// At the very start of your application
import { initTelemetry } from './observability/telemetry.js';
// Initialize with defaults (reads from environment)
initTelemetry();
// Or with explicit configuration
initTelemetry({
serviceName: 'chive-appview',
serviceVersion: '0.1.0',
environment: 'production',
otlpEndpoint: 'http://otel-collector:4318',
});
// Then import and start your application
import { startServer } from './server.js';
startServer();
Throws
Error if telemetry is already initialized
Since
0.1.0