Files
web/instrumentation.ts
2024-12-19 10:35:20 +00:00

50 lines
1.4 KiB
TypeScript

import * as Sentry from "@sentry/nextjs"
import { env } from "./env/server"
export async function register() {
await configureSentry()
await configureApplicationInsights()
}
export const onRequestError = Sentry.captureRequestError
async function configureApplicationInsights() {
if (
process.env.NEXT_RUNTIME === "nodejs" &&
env.APPLICATION_INSIGHTS_CONNECTION_STRING
) {
const { AzureMonitorTraceExporter, AzureMonitorMetricExporter } =
await import("@azure/monitor-opentelemetry-exporter")
const { registerOTel } = await import("@vercel/otel")
const { PeriodicExportingMetricReader } = await import(
"@opentelemetry/sdk-metrics"
)
const connectionString: string = env.APPLICATION_INSIGHTS_CONNECTION_STRING
const traceExporter = new AzureMonitorTraceExporter({ connectionString })
const azureMetricExporter = new AzureMonitorMetricExporter({
connectionString,
})
const azureMetricReader = new PeriodicExportingMetricReader({
exporter: azureMetricExporter,
exportIntervalMillis: 10000,
})
registerOTel({
serviceName: "scandic-web",
traceExporter,
metricReader: azureMetricReader,
})
}
}
async function configureSentry() {
switch (process.env.NEXT_RUNTIME) {
case "edge": {
await import("./sentry.edge.config")
}
case "nodejs": {
await import("./sentry.server.config")
}
}
}