Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release health sessions not sent when using a direct client #14804

Open
3 tasks done
rodolfoBee opened this issue Dec 19, 2024 · 16 comments
Open
3 tasks done

Release health sessions not sent when using a direct client #14804

rodolfoBee opened this issue Dec 19, 2024 · 16 comments
Assignees
Labels
Package: browser Issues related to the Sentry Browser SDK

Comments

@rodolfoBee
Copy link
Member

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

"@sentry/browser": "^8.47.0"

Framework Version

No response

Link to Sentry event

No response

Reproduction Example/SDK Setup

import {
  BrowserClient,
  defaultStackParser,
  getDefaultIntegrations,
  browserSessionIntegration,
  makeFetchTransport,
  Scope,
} from "@sentry/browser";

// filter integrations that use the global variable
const integrations = getDefaultIntegrations({}).filter(
  (defaultIntegration) => {
    return !["BrowserApiErrors", "Breadcrumbs", "GlobalHandlers"].includes(
      defaultIntegration.name,
    );
  },
);

const client = new BrowserClient({
  dsn: "...",
  transport: makeFetchTransport,
  stackParser: defaultStackParser,
  integrations: [ ...integrations, browserSessionIntegration()],
  release:"directClient@1.0.0",
  autoSessionTracking:true,
  initialScope: {
    user: { id: 42, email: "john.doe@example.com" },
  },
});

const scope = new Scope();
scope.setClient(client);

client.init(); // initializing has to be done after setting the client on the scope
// rest of the logic

Steps to Reproduce

  1. Run a simple app with the configuration above

Expected Result

The SDK sends release health sessions to Sentry to track release health and adoption on the Releases page.

Actual Result

No release session event is sent to Sentry.

Explicitly setting the browserSessionIntegration integration and/or autoSessionTracking have no effect on the result, this should also be automatic when a release version is set in the init as per:

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Dec 19, 2024
@github-actions github-actions bot added the Package: browser Issues related to the Sentry Browser SDK label Dec 19, 2024
@s1gr1d
Copy link
Member

s1gr1d commented Dec 20, 2024

Hello,
I'm gonna try to reproduce this. But one follow-up questions: How does the application look like where Sentry is running? Is this a browser extension or any other shared environment as a BrowserClient is explicitly created?

@ionutholbia
Copy link

@s1gr1d In our case Sentry is initialized in the service worker of a browser extension. I think @rodolfoBee also reproduced the issue but now sure how he tested.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Dec 20, 2024
@s1gr1d
Copy link
Member

s1gr1d commented Dec 20, 2024

in the service worker of a browser extension

The BrowserSession integration might not be set up correctly. Can you enable debug: true and check if you get a warning like this: "Using the browserSessionIntegration in non-browser environments is not supported.".

The SDK checks if WINDOW.document is available. I just want to check if you're running into this condition.

@ionutholbia
Copy link

ionutholbia commented Dec 20, 2024

Image

The first print is mine.

Haven't received a print like: "Using the browserSessionIntegration in non-browser environments is not supported."

Maybe it's worth mentioning that if I initialize Sentry on a global scope using Sentry.init then Release healthy sessions work fine.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Dec 20, 2024
@s1gr1d
Copy link
Member

s1gr1d commented Dec 20, 2024

Thanks for this information! I'll look into this.

@ionutholbia
Copy link

Hi @s1gr1d ! Do you have an update on this ticket?

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jan 7, 2025
@s1gr1d
Copy link
Member

s1gr1d commented Jan 7, 2025

Hello, not so far as I was busy with other things during the holiday break. I will take a look this week and give you an update.

@lforst
Copy link
Member

lforst commented Jan 7, 2025

I think I figured it out. So basically previously we didn't support session tracking for client-based setups at all. We then extracted the logic from Sentry.init() into an integration, however the logic depends on the fact that the client is set on the "current scope" (Sentry.getCurrentScope()). This means that the browserSessionIntegration() only works if Sentry.getCurrentScope().setClient(client) is called before calling client.init().

All of this is obviously suboptimal - we'll look into fixing it.

@lforst lforst self-assigned this Jan 7, 2025
@ionutholbia
Copy link

Hi @lforst,

Thank you for you answer! Setting a client at a global scope using getCurrentScope wouldn't help much for our usecase. We would like to initialize a Sentry client (Two different Sentry Projects) for two different modules. I would guess that if we would implement this workaround we will have Sessions only for one project.

I will still try to do that until we would have a fix.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jan 8, 2025
@lforst
Copy link
Member

lforst commented Jan 8, 2025

@ionutholbia Thanks for the background! Can I ask for the exact outcome you have with the API? Also, would you mind elaborating how your setup looks like with the different projects? I don't think I fully comprehended it yet.

The fix I have in mind is probably that for every client on the page that has the browserSessionIntegration() sessions will be sent via the respective client. This means you could have 2+ sessions per page. Is this also what you are looking for?

@ionutholbia
Copy link

ionutholbia commented Jan 8, 2025

Basically our browser extension has two different functionalities that are more or less independent. We want to have two different Sentry Projects (2 DSNs) for these two functionalities. To implement this we will use 2 clients. Here is a snippet of the code. Current as a workaround for sessions we are setting only one client as current scope.

IMO your proposed solution should work for us.

this.client = new BrowserClient({
      dsn: this.configuration.dsn, 
      transport: makeFetchTransport,
      stackParser: defaultStackParser,
      integrations,
      tracesSampleRate: this.configuration.sampleRate,
      release: this.configuration.productVersion,
      environment: this.configuration.environment,
    })

    this.scope = new Scope()

    this.scope.setUser({ id: this.configuration.telemetryId })

    this.scope.setClient(this.client)
    if (this.configuration.setClientAsGlobalScope) { //Workaround for one client
      getCurrentScope().setClient(this.client)
    }

    this.client.init() // initializing has to be done after setting the client on the scope

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jan 8, 2025
@lforst
Copy link
Member

lforst commented Jan 8, 2025

Okay that tracks. Thanks for clarifying!

@getsantry getsantry bot removed the status in GitHub Issues with 👀 3 Jan 8, 2025
@s1gr1d s1gr1d removed their assignment Jan 9, 2025
@ionutholbia
Copy link

Hi @lforst,
Do you have any updates on this bug? Unfortunately the workaround suggested by you to call Sentry.getCurrentScope().setClient(client) before calling client.init() didn't work for me.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jan 17, 2025
@lforst
Copy link
Member

lforst commented Jan 17, 2025

no updates

@swissmo
Copy link

swissmo commented Feb 3, 2025

Hello,
I was wondering if there was any news about this issue?

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Feb 3, 2025
@lforst
Copy link
Member

lforst commented Feb 3, 2025

Hi, there are no updates. Also, and please don't take this the wrong way, it is entirely meant as a heads up: I recommend not asking for updates on issues unless they were obviously forgotten about. This issue is on our backlog but is currently not a priority. "Update comments" create noise for us that we have to filter out and slow us down which is in no one's interest. In the meantime, I want to encourage you to propose and contribute a solution - we are open to accepting them. Thanks and hope you understand!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: browser Issues related to the Sentry Browser SDK
Projects
Status: No status
Development

No branches or pull requests

5 participants