updated OTEL example referenced in #29282
Signed-off-by: Eddie Hale <eddie.hale@gmail.com>
This commit is contained in:
@@ -28,25 +28,25 @@ In your `packages/backend/src` folder, create an `instrumentation.js` file.
|
||||
|
||||
```typescript title="in packages/backend/src/instrumentation.js"
|
||||
// Prevent from running more than once (due to worker threads)
|
||||
if (!require('node:worker_threads').isMainThread) {
|
||||
return;
|
||||
const { isMainThread } = require('node:worker_threads');
|
||||
|
||||
if (isMainThread) {
|
||||
const { NodeSDK } = require('@opentelemetry/sdk-node');
|
||||
const {
|
||||
getNodeAutoInstrumentations,
|
||||
} = require('@opentelemetry/auto-instrumentations-node');
|
||||
const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus');
|
||||
|
||||
// By default exports the metrics on localhost:9464/metrics
|
||||
const prometheus = new PrometheusExporter();
|
||||
const sdk = new NodeSDK({
|
||||
// You can add a traceExporter field here too
|
||||
metricReader: prometheus,
|
||||
instrumentations: [getNodeAutoInstrumentations()],
|
||||
});
|
||||
|
||||
sdk.start();
|
||||
}
|
||||
|
||||
const { NodeSDK } = require('@opentelemetry/sdk-node');
|
||||
const {
|
||||
getNodeAutoInstrumentations,
|
||||
} = require('@opentelemetry/auto-instrumentations-node');
|
||||
const { PrometheusExporter } = require('@opentelemetry/exporter-prometheus');
|
||||
|
||||
// By default exports the metrics on localhost:9464/metrics
|
||||
const prometheus = new PrometheusExporter();
|
||||
const sdk = new NodeSDK({
|
||||
// You can add a traceExporter field here too
|
||||
metricReader: prometheus,
|
||||
instrumentations: [getNodeAutoInstrumentations()],
|
||||
});
|
||||
|
||||
sdk.start();
|
||||
```
|
||||
|
||||
You probably won't need all of the instrumentation inside `getNodeAutoInstrumentations()` so make sure to
|
||||
|
||||
Reference in New Issue
Block a user