Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

Using `@sentry/nextjs` and `@sentry/cloudflare` together crashes every request with `context.getValue is not a function`

Ouverte
#24,603 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
48/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
nextjs, typescript
Domaine
observability

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Bug Cloudflare Workers Next.js
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.

Langage dominant
TypeScript
Étoiles
8.7k
Forks
1.9k
Merge moyen
1 j 16 h
PR mergées (30 j)
576

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de getsentry/sentry-javascript

Toutes les issues de getsentry/sentry-javascript

Issues similaires

Plus d'issues TypeScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.