Files
web/apps/scandic-web/instrumentation.ts
Anton Gunnarsson 048a477e52 Merged in feat/common-package (pull request #2333)
feat: Add common package

* Add isEdge, safeTry and dataCache to new common package

* Add eslint and move prettier config

* Fix yarn lock

* Clean up tests

* Add lint-staged config to common

* Add missing dependencies


Approved-by: Joakim Jäderberg
2025-06-11 13:08:39 +00:00

56 lines
1.6 KiB
TypeScript

import * as Sentry from "@sentry/nextjs"
import { isEdge } from "@scandic-hotels/common/utils/isEdge"
import { env } from "./env/server"
export async function register() {
/*
Order matters!
Sentry hooks into OpenTelemetry, modifying its behavior.
Application Insights relies on OpenTelemetry exporters,
and these may not work correctly if Sentry has already altered the instrumentation pipeline.
*/
await configureApplicationInsights()
await configureSentry()
}
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() {
if (isEdge) {
await import("./sentry.edge.config")
} else {
await import("./sentry.server.config")
}
}