Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭 适合新手
#1,495 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
javascript, react-native, typescript

调研方向

从 packages/core/src/sdk/UserInfoSingleton/UserInfoSingleton.ts 开始,其中 clearUserInfo 只把 this.userInfo 设为 undefined,同时查看旁边 AccountInfoProvider 的 clearAccountInfo 方法。rum/helper.ts 模块已经导出了 clearCachedUserId 和 clearCachedAccountId,但它们没有任何调用方。完成的标准是:两个 clear 方法都调用这些 helper,并且一个先调用 setUserInfo 再调用 clearUserInfo、期望 getCachedUserId 返回 undefined 的测试能够通过。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
TypeScript
星标
145
派生
65
平均合并
2 天 16 小时
30 天内合并 PR
19

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

DataDog/dd-sdk-reactnative 的其他 Issue

查看 DataDog/dd-sdk-reactnative 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。