From 58e4a1c21c1a63517c6a3ba3495758e675a40423 Mon Sep 17 00:00:00 2001 From: Luiz Henrique <7henrique18@gmail.com> Date: Mon, 14 Oct 2024 10:33:02 -0300 Subject: [PATCH] feat(config): Export OpenTelemetry SDK to allow access in server - Improve modularity. --- src/config/instrumentation.ts | 4 +--- src/http/server.ts | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/config/instrumentation.ts b/src/config/instrumentation.ts index 2813c28..da47a4b 100644 --- a/src/config/instrumentation.ts +++ b/src/config/instrumentation.ts @@ -2,7 +2,7 @@ import opentelemetry from '@opentelemetry/sdk-node' import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http' import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node' -const sdk = new opentelemetry.NodeSDK({ +export const sdk = new opentelemetry.NodeSDK({ traceExporter: new OTLPTraceExporter(), instrumentations: [ getNodeAutoInstrumentations({ @@ -14,5 +14,3 @@ const sdk = new opentelemetry.NodeSDK({ }), ], }) - -sdk.start() diff --git a/src/http/server.ts b/src/http/server.ts index 1b46262..07345bc 100644 --- a/src/http/server.ts +++ b/src/http/server.ts @@ -26,6 +26,7 @@ import { loginRoute } from './routes/login' import { registerEventRoute } from './routes/register-event' import { registerHostRoute } from './routes/register-host' import { registerSubscriptionRoute } from './routes/register-subscription' +import { sdk } from '@/config/instrumentation' const app = fastify() @@ -119,6 +120,7 @@ app.setErrorHandler((error, _, reply) => { return reply.status(500).send({ message: 'Internal server error.' }) }) +sdk.start() app .listen({ port: env.PORT,