Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

clearUserInfo() doesn't clear the cached user id, so baggage keeps the previous user's id

Aperta Adatta ai principianti
#1,495 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
javascript, react-native, typescript

Direzione di ricerca

Inizia da packages/core/src/sdk/UserInfoSingleton/UserInfoSingleton.ts, dove clearUserInfo si limita a impostare this.userInfo su undefined, e dal metodo clearAccountInfo di AccountInfoProvider accanto ad esso. Il modulo rum/helper.ts esporta già clearCachedUserId e clearCachedAccountId, che non hanno chiamanti. È completato quando entrambi i metodi clear chiamano anche questi helper e un test che chiama setUserInfo e poi clearUserInfo, aspettandosi che getCachedUserId restituisca undefined, passa.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the bug

DdSdkReactNative.clearUserInfo() doesn't clear the cached user id that resource tracking uses for the baggage header, so after a logout the app keeps sending the previous user's id in baggage on first-party requests.

UserInfoProvider.setUserInfo calls setCachedUserId(userInfo.id) (added in df2b8e68, "Cache userId and accountId when first set"), and RequestContext reads getCachedUserId() to build baggage: user.id=…. But UserInfoProvider.clearUserInfo only resets this.userInfo:

// packages/core/src/sdk/UserInfoSingleton/UserInfoSingleton.ts
clearUserInfo = () => {
    this.userInfo = undefined;
};

clearCachedUserId() exists in rum/helper.ts but has no callers. AccountInfoProvider.clearAccountInfo has the same gap with clearCachedAccountId().

The effect is that every traced request after clearUserInfo() (signed-out requests, and the next user's first requests before setUserInfo runs again) carries the previous user's id in baggage. Backends that tag or propagate baggage (e.g. dd-trace's default DD_TRACE_BAGGAGE_TAG_KEYS) then attribute those requests to the wrong user, and may forward the id downstream.

Reproduction steps
  1. Initialize the SDK with firstPartyHosts for a host you control and resource tracking enabled.
  2. await DdSdkReactNative.setUserInfo({ id: 'user-a' }), then make a request to that host. baggage contains user.id=user-a (expected).
  3. await DdSdkReactNative.clearUserInfo(), then make another request to that host.
  4. baggage still contains user.id=user-a.

Minimal check without a network request:

UserInfoSingleton.getInstance().setUserInfo({ id: 'user-a' });
UserInfoSingleton.getInstance().clearUserInfo();
getCachedUserId(); // 'user-a', expected undefined
Expected behavior

After clearUserInfo(), baggage omits user.id (the header builder already skips it when the cached id is undefined). Same for account.id after clearAccountInfo().

Suggested fix:

-import { setCachedUserId } from '../../rum/helper';
+import { clearCachedUserId, setCachedUserId } from '../../rum/helper';
 ...
     clearUserInfo = () => {
         this.userInfo = undefined;
+        clearCachedUserId();
     };

and the equivalent clearCachedAccountId() call in AccountInfoProvider.clearAccountInfo. We're carrying this as a patch-package patch on 3.8.0 for now.

Affected SDK versions

3.0.0 through 3.10.0 (still present on develop)

Latest working SDK version

2.x (no cached user id)

Did you confirm if the latest SDK version fixes the bug?

Yes, checked develop / 3.10.0 and it's still present.

Integration Methods

NPM

React Native Version

0.86.3 (Expo SDK 57)

Other relevant information

Both iOS and Android are affected, since the header is built in the JS request proxy.

Lingua principale
TypeScript
Stelle
145
Fork
65
Merge medio
2g 16h
PR unite (30g)
19

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di DataDog/dd-sdk-reactnative

Tutte le issue di DataDog/dd-sdk-reactnative

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.