47 lines
1.5 KiB
JavaScript
47 lines
1.5 KiB
JavaScript
// OpenTelemetry Node SDK bootstrap for the FarmaClic scraper.
|
|
// Started as a side-effect require from index.js (CommonJS).
|
|
//
|
|
// Env vars:
|
|
// OTEL_SERVICE_NAME — default: farmaclic-scraper
|
|
// OTEL_EXPORTER_OTLP_ENDPOINT — OTLP gRPC endpoint (e.g. http://alloy:4317)
|
|
|
|
const { NodeSDK } = require('@opentelemetry/sdk-node');
|
|
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');
|
|
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-grpc');
|
|
const { resourceFromAttributes } = require('@opentelemetry/resources');
|
|
const {
|
|
ATTR_SERVICE_NAME,
|
|
ATTR_SERVICE_NAMESPACE,
|
|
} = require('@opentelemetry/semantic-conventions');
|
|
|
|
const serviceName = process.env.OTEL_SERVICE_NAME || 'farmaclic-scraper';
|
|
const otlpEndpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT || 'http://localhost:4317';
|
|
|
|
const sdk = new NodeSDK({
|
|
resource: resourceFromAttributes({
|
|
[ATTR_SERVICE_NAME]: serviceName,
|
|
[ATTR_SERVICE_NAMESPACE]: 'farmaclic',
|
|
}),
|
|
traceExporter: new OTLPTraceExporter({ url: otlpEndpoint }),
|
|
instrumentations: [
|
|
getNodeAutoInstrumentations({
|
|
'@opentelemetry/instrumentation-fs': { enabled: false },
|
|
'@opentelemetry/instrumentation-dns': { enabled: false },
|
|
}),
|
|
],
|
|
});
|
|
|
|
sdk.start();
|
|
|
|
const shutdown = async () => {
|
|
try {
|
|
await sdk.shutdown();
|
|
} catch (err) {
|
|
// eslint-disable-next-line no-console
|
|
console.error('OpenTelemetry shutdown failed', err);
|
|
}
|
|
};
|
|
|
|
process.on('SIGTERM', shutdown);
|
|
process.on('SIGINT', shutdown);
|