| 1 | import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node'; |
| 2 | import { NodeSDK } |
| 3 | import Pyroscope from '@pyroscope/nodejs |
| 4 | |
| 5 | // Without a collector to ship to, the SDK retries against localhost and fills the log with export failures, so telemetry stays opt-in. |
| 6 | if (process.env. |
| 7 | const sdk = |
| 8 | serviceName: 'ghost-api', |
| 9 | instrumentations: [ |
| 10 | getNodeAutoInstrumentations({ |
| 11 | // Every pack operation reads thousands of files; a span each buries the request they belong to. |
| 12 | '@opentelemetry/instrumentation-fs': { enabled: |
| 13 | }), |
| 14 | ], |
| 15 | }); |
| 16 | sdk.start(); |
| 17 | // Containers stop on SIGTERM; without a flush the last batch of spans and the last collection of metrics die with the process. |
| 18 | process.once('SIGTERM |
| 19 | } |
| 20 | |
| 21 | // Profiling ships to Pyroscope directly: it is a push protocol of its own, not OTLP. |
| 22 | if (process.env. |
| 23 | Pyroscope.init({ |
| 24 | appName: 'ghost-api', |
| 25 | serverAddress: process.env |
| 26 | // Wall time alone cannot tell a request blocked on postgres from one burning CPU. |
| 27 | wall: { collectCpuTime: true |
| 28 | }); |
| 29 | Pyroscope.start(); |
| 30 | } |