Using `@sentry/nextjs` and `@sentry/cloudflare` together crashes every request with `context.getValue is not a function`
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 48/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- nextjs, typescript
- Área
- observability
Línea de trabajo
Start with packages/server-utils/src/async-context.ts and packages/opentelemetry/src/asyncContextStrategy.ts, comparing how each strategy discovers and reuses AsyncLocalStorage. Run both reproduction snippets and verify that mismatched stores no longer cause getCurrentScope or trace.getSpan to crash; the unsupported combined SDK behavior should remain explicit.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description
A Next.js app on Cloudflare Workers that initializes @sentry/nextjs in instrumentation.ts and also wraps the Worker entry with @sentry/cloudflare's withSentry fails on every request:
TypeError: e.getValue is not a function
at getScopesFromContext
at getScopes
...
at _onSpanEnded
at end
Seen with @sentry/nextjs@11.0.0-rc.1 and @sentry/cloudflare@11.0.0-rc.1, which share the same @sentry/core.
Root cause
The two SDKs install different async context strategies, and the second one reuses the AsyncLocalStorage of the first even though the two strategies put different things into it:
| Strategy | Installed by | ALS store |
|---|---|---|
setAsyncLocalStorageAsyncContextStrategy (packages/server-utils/src/async-context.ts) |
@sentry/cloudflare (withSentry) |
{ scope, isolationScope } |
setOpenTelemetryContextAsyncContextStrategy (packages/opentelemetry/src/asyncContextStrategy.ts) |
@sentry/nextjs edge build (via @sentry/vercel-edge) |
an OpenTelemetry Context, also read by the global context manager it registers |
Both pick up an existing store like this, without checking which strategy created it (added in #22889):
const existing = getAsyncContextStrategy(getMainCarrier()).getTracingChannelBinding?.()?.asyncLocalStorage;
const asyncLocalStorage = existing ?? new AsyncLocalStorage();
Once the stores are shared, api.context.active() returns the plain { scope, isolationScope } object, and getScopesFromContext(ctx) (or trace.getSpan(ctx)) calls ctx.getValue() on it. It fails in both install orders.
Reproduction
No framework needed:
import { getCurrentScope, withIsolationScope } from '@sentry/core';
import { setAsyncLocalStorageAsyncContextStrategy } from '@sentry/cloudflare';
import { setOpenTelemetryContextAsyncContextStrategy } from '@sentry/opentelemetry';
setAsyncLocalStorageAsyncContextStrategy();
withIsolationScope(() => {
setOpenTelemetryContextAsyncContextStrategy();
getCurrentScope(); // TypeError: context.getValue is not a function
});
The reverse order fails the same way:
import { context, trace } from '@opentelemetry/api';
setOpenTelemetryContextAsyncContextStrategy();
setAsyncLocalStorageAsyncContextStrategy();
withIsolationScope(() => {
trace.getSpan(context.active()); // TypeError: context.getValue is not a function
});
Expected
A strategy only reuses an AsyncLocalStorage that holds the store shape it expects, for example by tagging the binding with its store type and creating a fresh ALS on a mismatch.
This only stops the crash. Two SDKs in one runtime still end up with one active strategy and one current client, so combining @sentry/nextjs and @sentry/cloudflare stays unsupported. It would still be better to fail soft than to break every request. The same clash can happen with any other pair of SDKs that use different strategies.
- Lenguaje dominante
- TypeScript
- Estrellas
- 8.7k
- Forks
- 1.9k
- Merge medio
- 1 d 16 h
- PR fusionados (30 d)
- 576
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de getsentry/sentry-javascript
-
Browser Bug Next.js Traces Waiting for: Product Owner
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
getsentry/sentry-javascript#24672 · 1 comentario ·
-
Flaky Test React Router Framework Spans Tests
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
getsentry/sentry-javascript#24348 · 1 comentario ·
-
javascript
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
getsentry/sentry-javascript#24200 · 2 comentarios ·
-
javascript Task
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
getsentry/sentry-javascript#24134 · 1 comentario ·
-
Cloudflare Workers javascript Tests
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
getsentry/sentry-javascript#24051 · 1 comentario ·
Todos los issues de getsentry/sentry-javascript
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
mksglu/context-mode#1200 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
jaegertracing/jaeger-ui#4506 ·
-
area:desktop area:ui bug platform:macos
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
anthropics/claude-code#96687 ·
-
good first issue
Dificultad 1/5 Menos de una hora Aptitud para principiantes 95/100
AOSSIE-Org/DebateAI#582 · 2 comentarios ·