diff --git a/bun.lockb b/bun.lockb index 9d5f4fb..f437f55 100644 Binary files a/bun.lockb and b/bun.lockb differ 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,