Skip to content

Commit

Permalink
feat: sentry setup
Browse files Browse the repository at this point in the history
  • Loading branch information
lui7henrique committed Oct 16, 2024
1 parent 790a86a commit b178a15
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"@opentelemetry/sdk-metrics": "^1.26.0",
"@opentelemetry/sdk-node": "^0.53.0",
"@opentelemetry/sdk-trace-node": "^1.26.0",
"@sentry/node": "^8.34.0",
"@sentry/profiling-node": "^8.34.0",
"bcrypt": "^5.1.1",
"date-fns": "^4.1.0",
"drizzle-orm": "0.33.0",
Expand Down
26 changes: 12 additions & 14 deletions src/config/instrumentation.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import opentelemetry from '@opentelemetry/sdk-node'
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node'
import { env } from '@/env'
import Sentry from '@sentry/node'
import { nodeProfilingIntegration } from '@sentry/profiling-node'

export 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,
},
}),
],
Sentry.init({
dsn: env.SENTRY_DSN,
integrations: [nodeProfilingIntegration()],

// Tracing
tracesSampleRate: 1.0, // Capture 100% of the transactions

// Set sampling rate for profiling - this is relative to tracesSampleRate
profilesSampleRate: 1.0,
})
1 change: 1 addition & 0 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const envSchema = z.object({
REDIS_URL: z.string(),
JWT_SECRET: z.string(),
BASE_URL: z.string(),
SENTRY_DSN: z.string().optional(),
})

export const env = envSchema.parse(process.env)
5 changes: 3 additions & 2 deletions src/http/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import fastifyRedis from '@fastify/redis'
import fastifySwagger from '@fastify/swagger'
import fastifySwaggerUi from '@fastify/swagger-ui'
import fastify from 'fastify'
import Sentry from '@sentry/node'

import {
jsonSchemaTransform,
Expand All @@ -26,7 +27,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 @@ -120,7 +120,8 @@ app.setErrorHandler((error, _, reply) => {
return reply.status(500).send({ message: 'Internal server error.' })
})

sdk.start()
Sentry.setupFastifyErrorHandler(app)

app
.listen({
port: env.PORT,
Expand Down

0 comments on commit b178a15

Please sign in to comment.