@codefresh-io/cf-telemetry
v4.1.1
Published
Base utils for monitoring.
Maintainers
Keywords
Readme
cf-telemetry
Base utils for monitoring.
Includes:
- Logs, fast and well-structured.
- MongoDB client monitoring helper.
- OpenTelemetry auto instrumentation, API and helpers.
- Prometheus server and custom metrics.
- Pyroscope to profile CPU and memory.
Usage
Add import '@codefresh-io/cf-telemetry/init' statement at the very beginning of the application lifecycle.
Please refer to the separate docs above for further configuration and usage details.
// index.ts
// ↓ Should be imported first
import '@codefresh-io/cf-telemetry/init'
// ↓ Keep one blank line below to prevent automatic import reorderingLifecycle notice
This library only registers terminate listener beforeExit event to gracefully terminate instrumentation, which may include flushing logs, metrics, and profiles.
Please ensure calling terminate() method of this library before calling process.exit(), or to include it in your application logic that handles SIGINT/SIGTERM signals, to ensure graceful termination of instrumentation.
import { terminate } from '@codefresh-io/cf-telemetry/init'
// ...your application logic
await terminate(); // Ensure graceful termination of instrumentation
process.exit(0); // Now it's safe to exit the processimport { terminate } from '@codefresh-io/cf-telemetry/init'
process.on('SIGINT', async () => {
await terminate(); // Ensure graceful termination of instrumentation
process.exit(130); // Now it's safe to exit the process
});
process.on('SIGTERM', async () => {
await terminate(); // Ensure graceful termination of instrumentation
process.exit(143); // Now it's safe to exit the process
});Environment variables
| Variable | Required | Default value | Description |
|------------------------| -------- |-------------------------------------------------------------------|---------------------------------------------|
| CF_SERVICE_NAME | optional | unknown_service:node | Sets service name for OpenTelemetry, Pyroscope and Prometheus. |
| CF_SERVICE_VERSION | optional | unknown | Sets service name for OpenTelemetry, Pyroscope and Prometheus. |
