Skip to content

Add instructions for adding initial scope when using BrowserClient #5345

@yuval-sentry

Description

@yuval-sentry

Core or SDK?

Platform/SDK

Which part? Which one?

Javascript

Description

Per our client:
"The real problem here is that BrowserClient accepts an initialScope parameter in its constructor and in its TypeScript types but does not actually do anything with it, leading to confusion. This is likely something that should be fixed by either not accepting the initialScope parameter in BrowserClient, or by actually acting on the initialScope parameter.
Once I looked at the source code and discovered that initialScope does nothing, I figured out the rest.
At least documenting this solution for capturing user sessions with BrowserClient on the docs site would be helpful."

Suggested Solution

Add a reference for when using BrowserClient with a code sample like this one:

const initialScope = new Sentry.Scope();
  initialScope.update({
    user: { id: '1234-test' },
  });

  const sentryHub = new Sentry.Hub(sentryClient, initialScope);
  sentryHub.startSession();
  sentryHub.captureSession();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions