From 8a23320ede2e2234d3268ce38b52bd2e1e680205 Mon Sep 17 00:00:00 2001 From: Scott Cazan Date: Fri, 9 Jan 2026 15:27:09 +0100 Subject: [PATCH 1/2] Trying out better logging workaround for edge --- apps/app/src/instrumentation.ts | 69 ++++++++++++++++++++------------- scripts/check_skip_deploy.sh | 2 +- 2 files changed, 43 insertions(+), 28 deletions(-) diff --git a/apps/app/src/instrumentation.ts b/apps/app/src/instrumentation.ts index bf57f96d9..ce1d8d8c5 100644 --- a/apps/app/src/instrumentation.ts +++ b/apps/app/src/instrumentation.ts @@ -1,7 +1,12 @@ import { diag } from '@opentelemetry/api'; +import { logs } from '@opentelemetry/api-logs'; import { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-http'; import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http'; -import { BatchLogRecordProcessor } from '@opentelemetry/sdk-logs'; +import { + BatchLogRecordProcessor, + LoggerProvider, + SimpleLogRecordProcessor, +} from '@opentelemetry/sdk-logs'; import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics'; import { OTLPHttpJsonTraceExporter, registerOTel } from '@vercel/otel'; @@ -11,20 +16,30 @@ export function register() { const otelEndpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT; const headers = parseHeaders(process.env.OTEL_EXPORTER_OTLP_HEADERS); + const isEdgeRuntime = process.env.NEXT_RUNTIME === 'edge'; - // Configure log export - const logRecordProcessors = - // Logging doesn't currently work on edge with OTel - process.env.NEXT_RUNTIME !== 'edge' && otelEndpoint - ? [ - new BatchLogRecordProcessor( - new OTLPLogExporter({ - url: `${otelEndpoint}/v1/logs`, - headers, - }), - ), - ] - : undefined; + // Configure log export with edge runtime workaround + // See: https://github.com/vercel/otel/issues/104 + // The workaround is to create our own LoggerProvider with empty logRecordLimits + // to avoid "Cannot read properties of undefined (reading 'attributeCountLimit')" error + if (otelEndpoint) { + const logExporter = new OTLPLogExporter({ + url: `${otelEndpoint}/v1/logs`, + headers, + }); + + // Use SimpleLogRecordProcessor for edge (more compatible), BatchLogRecordProcessor for Node.js + const logProcessor = isEdgeRuntime + ? new SimpleLogRecordProcessor(logExporter) + : new BatchLogRecordProcessor(logExporter); + + const loggerProvider = new LoggerProvider({ + // Empty logRecordLimits is the workaround for edge runtime bug + logRecordLimits: {}, + processors: [logProcessor], + }); + logs.setGlobalLoggerProvider(loggerProvider); + } // Configure trace exporter const traceExporter = otelEndpoint @@ -34,23 +49,23 @@ export function register() { }) : undefined; - // Configure metrics exporter - const metricReaders = otelEndpoint - ? [ - new PeriodicExportingMetricReader({ - exporter: new OTLPMetricExporter({ - url: `${otelEndpoint}/v1/metrics`, - headers, + // Configure metrics exporter (metrics not supported on edge runtime) + const metricReaders = + otelEndpoint && !isEdgeRuntime + ? [ + new PeriodicExportingMetricReader({ + exporter: new OTLPMetricExporter({ + url: `${otelEndpoint}/v1/metrics`, + headers, + }), + exportIntervalMillis: 5000, }), - // Logs are also flushed on exit - exportIntervalMillis: 5000, - }), - ] - : undefined; + ] + : undefined; registerOTel({ serviceName: process.env.OTEL_SERVICE_NAME || 'common', - logRecordProcessors, + // Don't pass logRecordProcessors - we've already set up our own LoggerProvider above traceExporter, metricReaders, }); diff --git a/scripts/check_skip_deploy.sh b/scripts/check_skip_deploy.sh index ac77ae98b..b5a380c50 100644 --- a/scripts/check_skip_deploy.sh +++ b/scripts/check_skip_deploy.sh @@ -3,7 +3,7 @@ set -e # Execute the turbo-ignore command only if the current branch is "dev" or "main" -if [[ "$VERCEL_GIT_COMMIT_REF" == "dev" || "$VERCEL_GIT_COMMIT_REF" == "main" ]]; then +if [[ "$VERCEL_GIT_COMMIT_REF" == "dev" || "$VERCEL_GIT_COMMIT_REF" == "main" || "$VERCEL_GIT_COMMIT_REF" == "log-debugging" ]]; then npx turbo-ignore --fallback=HEAD^1 else echo "Error: This command should only be run on 'dev' or 'main'. Current branch: $VERCEL_GIT_COMMIT_REF" From 7468ab6672eef054e9cd20880837f2b518c6603a Mon Sep 17 00:00:00 2001 From: Scott Cazan Date: Fri, 9 Jan 2026 16:39:06 +0100 Subject: [PATCH 2/2] Remove skip-deploy exception --- scripts/check_skip_deploy.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/check_skip_deploy.sh b/scripts/check_skip_deploy.sh index b5a380c50..ac77ae98b 100644 --- a/scripts/check_skip_deploy.sh +++ b/scripts/check_skip_deploy.sh @@ -3,7 +3,7 @@ set -e # Execute the turbo-ignore command only if the current branch is "dev" or "main" -if [[ "$VERCEL_GIT_COMMIT_REF" == "dev" || "$VERCEL_GIT_COMMIT_REF" == "main" || "$VERCEL_GIT_COMMIT_REF" == "log-debugging" ]]; then +if [[ "$VERCEL_GIT_COMMIT_REF" == "dev" || "$VERCEL_GIT_COMMIT_REF" == "main" ]]; then npx turbo-ignore --fallback=HEAD^1 else echo "Error: This command should only be run on 'dev' or 'main'. Current branch: $VERCEL_GIT_COMMIT_REF"