diff --git a/instrumentation.ts b/instrumentation.ts index ac09da613..f034eaf45 100644 --- a/instrumentation.ts +++ b/instrumentation.ts @@ -5,17 +5,29 @@ export async function register() { process.env.NEXT_RUNTIME === "nodejs" && env.APPLICATION_INSIGHTS_CONNECTION_STRING ) { - const { AzureMonitorTraceExporter } = await import( - "@azure/monitor-opentelemetry-exporter" - ) + 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 connectionString = 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, }) } } diff --git a/package-lock.json b/package-lock.json index 14135cd53..05aaa94fb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,8 @@ "@hookform/error-message": "^2.0.1", "@hookform/resolvers": "^3.3.4", "@netlify/plugin-nextjs": "^5.1.1", + "@opentelemetry/api": "^1.9.0", + "@opentelemetry/sdk-metrics": "^1.25.1", "@radix-ui/react-slot": "^1.0.2", "@react-aria/ssr": "^3.9.5", "@scandic-hotels/design-system": "git+https://x-token-auth:$DESIGN_SYSTEM_ACCESS_TOKEN@bitbucket.org/scandic-swap/design-system.git#v0.1.0-rc.8", diff --git a/package.json b/package.json index c826f1e30..426eef100 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,8 @@ "@hookform/error-message": "^2.0.1", "@hookform/resolvers": "^3.3.4", "@netlify/plugin-nextjs": "^5.1.1", + "@opentelemetry/api": "^1.9.0", + "@opentelemetry/sdk-metrics": "^1.25.1", "@radix-ui/react-slot": "^1.0.2", "@react-aria/ssr": "^3.9.5", "@scandic-hotels/design-system": "git+https://x-token-auth:$DESIGN_SYSTEM_ACCESS_TOKEN@bitbucket.org/scandic-swap/design-system.git#v0.1.0-rc.8",