@codefresh-io/cf-telemetry
v3.8.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 notices
[!IMPORTANT] Please read this section carefully to understand how this library handles application lifecycle events and how it affects application lifecycle.
This library registers listeners for SIGINT, SIGTERM and beforeExit events to gracefully terminate instrumentation, which may include flushing logs, metrics, and profiles.
Effect on application lifecycle
As this library registers listeners for SIGINT and SIGTERM events, Node.js' default handlers for such signals will be removed: Node.js will no longer exit on non-Windows platforms on such signals. More details in the doc.
Please make sure you add your own exit handlers for these signals.
Instrumentation shutdown
None of the events above happens if proces.exit() is called directly. This means that if you call process.exit() in your application, the library will not be able to gracefully terminate instrumentation. This may lead to loss of logs, metrics, and other telemetry data.
Please ensure calling terminate() method of this library before calling process.exit() 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 processEnvironment 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. |
