getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.9k stars 1.56k forks source link

SDK client is not available when using Replay with a direct client. #9790

Open rodolfoBee opened 10 months ago

rodolfoBee commented 10 months ago

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/browser

SDK Version

7.85.0

Framework Version

No response

Link to Sentry event

No response

SDK Setup

import {
    BrowserClient,
    defaultStackParser,
    makeFetchTransport,
    defaultIntegrations,
    Hub,
    Replay
  } from "@sentry/browser";
​
  const client = new BrowserClient({
    dsn: "MY_DSN",
    transport: makeFetchTransport,
    stackParser: defaultStackParser,
    integrations: defaultIntegrations,
    replaysSessionSampleRate: 1.0,
    replaysOnErrorSampleRate: 1.0,
    integrations:[
      new Replay({
        // Additional SDK configuration goes in here, for example:
        maskAllText: true,
        blockAllMedia: true,
      }),
    ],
  });
​

  const hub = new Hub(client);
​
  const replay = hub.getIntegration(Replay);
  replay.start()  

​  //.....

replay.stop()

Steps to Reproduce

Run a simple server with the above setup.

Expected Result

Being able to record replays using the client directly.

Actual Result

The following warning is presented in the console: SDK client is not available. from this line.

lforst commented 10 months ago

It looks like you didn't bind the client. Could that be the case? https://docs.sentry.io/platforms/javascript/configuration/tree-shaking/#:~:text=getCurrentHub().bindClient(client)%3B

rodolfoBee commented 9 months ago

I'm following the steps from here: https://docs.sentry.io/platforms/javascript/troubleshooting/#using-a-client-directly

What is the correct way of using the client? With getCurrentHub().bindClient(client); , const hub = new Hub(client); or both?

mydea commented 9 months ago

You cannot use replay with an unbound client, as of now. Replay is always global and will only work for the current, main hub. So using it with a client directly is not supported as of now.

What's the use case there? E.g. Replay will not work for e.g. browser extensions and similar things as of now.