Skip to content

Commit

Permalink
feat(config): Optimize instrumentation setup for better performance
Browse files Browse the repository at this point in the history
  • Loading branch information
lui7henrique committed Oct 14, 2024
1 parent d516cb4 commit 635eb3a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
Binary file modified bun.lockb
Binary file not shown.
29 changes: 14 additions & 15 deletions src/config/instrumentation.ts
Original file line number Diff line number Diff line change
@@ -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()
6 changes: 2 additions & 4 deletions src/http/server.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import '@/config/instrumentation'

import fastifyCors from '@fastify/cors'
import fastifyJwt from '@fastify/jwt'
import fastifyRateLimit from '@fastify/rate-limit'
Expand All @@ -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()

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 635eb3a

Please sign in to comment.