From 635eb3a7c3bf9173529a0f0a02392d30f81412dd Mon Sep 17 00:00:00 2001 From: Luiz Henrique <7henrique18@gmail.com> Date: Mon, 14 Oct 2024 10:17:04 -0300 Subject: [PATCH] feat(config): Optimize instrumentation setup for better performance --- bun.lockb | Bin 248930 -> 248930 bytes src/config/instrumentation.ts | 29 ++++++++++++++--------------- src/http/server.ts | 6 ++---- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/bun.lockb b/bun.lockb index 9d5f4fbb1eff1772fc966951b967020c6a82353b..f437f55d146d67e0b7ef072b67cf505610742b1e 100644 GIT binary patch delta 54 zcmaDfga6SC{)QIDElk0El1vOxV8F=0pw7V1U^cJXb@GbNN7K(7V3Kd|?qk~C-N$_0 F767>B5vc$G delta 58 zcmaDfga6SC{)QIDElk0EN{n#^dZq??Mhpgw3=HZF3=L-Us$D0q=zPS)!~g;9rF~4> KOZ%AL+5!LqkPzGe diff --git a/src/config/instrumentation.ts b/src/config/instrumentation.ts index 923a8c6..2813c28 100644 --- a/src/config/instrumentation.ts +++ b/src/config/instrumentation.ts @@ -1,19 +1,18 @@ -import { NodeSDK } from '@opentelemetry/sdk-node' -import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node' -import { - PeriodicExportingMetricReader, - ConsoleMetricExporter, -} from '@opentelemetry/sdk-metrics' +import opentelemetry from '@opentelemetry/sdk-node' import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http' +import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node' -const otlpExporter = new OTLPTraceExporter({ - url: 'http://localhost:4318/v1/traces', +const sdk = new opentelemetry.NodeSDK({ + traceExporter: new OTLPTraceExporter(), + instrumentations: [ + getNodeAutoInstrumentations({ + // we recommend disabling fs autoinstrumentation since it can be noisy + // and expensive during startup + '@opentelemetry/instrumentation-fs': { + enabled: false, + }, + }), + ], }) -export const sdk = new NodeSDK({ - traceExporter: otlpExporter, - metricReader: new PeriodicExportingMetricReader({ - exporter: new ConsoleMetricExporter(), - }), - instrumentations: [getNodeAutoInstrumentations()], -}) +sdk.start() diff --git a/src/http/server.ts b/src/http/server.ts index 1c6cea8..1b46262 100644 --- a/src/http/server.ts +++ b/src/http/server.ts @@ -1,3 +1,5 @@ +import '@/config/instrumentation' + import fastifyCors from '@fastify/cors' import fastifyJwt from '@fastify/jwt' import fastifyRateLimit from '@fastify/rate-limit' @@ -24,7 +26,6 @@ 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() @@ -118,9 +119,6 @@ app.setErrorHandler((error, _, reply) => { return reply.status(500).send({ message: 'Internal server error.' }) }) -sdk.start() - -app.ready() app .listen({ port: env.PORT,