Slackbot
12/17/2023, 11:46 AMPranay
Abdulmalik Salawu
12/17/2023, 2:05 PM// tracing.ts
'use strict'
const process = require('process');
import * as opentelemetry from '@opentelemetry/sdk-node';
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
import { Resource } from '@opentelemetry/resources';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
const exporterOptions = {
url: '<http://signoz-otel-collector.platform.svc.cluster.local:4318/v1/traces>'
}
const traceExporter = new OTLPTraceExporter(exporterOptions);
const sdk = new opentelemetry.NodeSDK({
traceExporter,
instrumentations: [getNodeAutoInstrumentations()],
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: 'posts_service'
})
});
// initialize the SDK and register with the OpenTelemetry API
// this enables the API to record telemetry
sdk.start()
// gracefully shut down the SDK on process exit
process.on('SIGTERM', () => {
sdk.shutdown()
.then(() => console.log('Tracing terminated'))
.catch((error) => console.log('Error terminating tracing', error))
.finally(() => process.exit(0));
});
export default sdk;
Abdulmalik Salawu
12/17/2023, 2:06 PMimport mongoose from 'mongoose';
import { app } from './app';
import tracer from './tracer';
import dotenv from 'dotenv';
dotenv.config();
const start = async () => {
await tracer.start();