generated from apostrophecms/starter-kit-assembly-essentials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtelemetry.js
41 lines (35 loc) · 1.12 KB
/
telemetry.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import fs from 'node:fs/promises';
import { NodeSDK, resources } from '@opentelemetry/sdk-node';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
import { JaegerExporter } from '@opentelemetry/exporter-jaeger';
// 1. Add the application meta data (resource)
const { name, version } = JSON.parse(await fs.readFile('./package.json'));
const resource = new resources.Resource({
[SemanticResourceAttributes.SERVICE_NAME]: name,
[SemanticResourceAttributes.SERVICE_VERSION]: version
});
// 2. Initialize the exporter
const traceExporter = new JaegerExporter({
tags: [],
endpoint: 'http://localhost:14268/api/traces'
});
// 3. Initialize the SDK
const sdk = new NodeSDK({
resource,
traceExporter,
instrumentations: [ getNodeAutoInstrumentations() ]
});
// 4. The shutdown handler
const shutdown = async () => {
await sdk
.shutdown()
.then(
() => console.log('OpenTelemetry stopped'),
(err) => console.log('Error shutting down OpenTelemetry', err)
);
};
export {
sdk,
shutdown
};