Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở Phù hợp với người mới
#1,495 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@hippi345 đang làm issue này rồi.

Từ ngày 18/10/2026.

  • #1498 của @hippi345 — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
javascript, react-native, typescript
Lĩnh vực
analytics, frontend

Hướng nghiên cứu

Bắt đầu từ packages/core/src/sdk/UserInfoSingleton/UserInfoSingleton.ts, nơi clearUserInfo chỉ gán this.userInfo thành undefined, và từ phương thức clearAccountInfo của AccountInfoProvider nằm cạnh đó. Module rum/helper.ts đã export clearCachedUserId và clearCachedAccountId, nhưng chưa có nơi nào gọi chúng. Công việc hoàn thành khi cả hai phương thức clear cũng gọi các helper này, và một test gọi setUserInfo rồi clearUserInfo, kỳ vọng getCachedUserId trả về undefined, chạy thành công.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
TypeScript
Star
145
Fork
65
Merge trung bình
2 ngày 16 giờ
Pull request đã merge (30 ngày)
19

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của DataDog/dd-sdk-reactnative

Tất cả issue của DataDog/dd-sdk-reactnative

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.