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

The lazy loader for Sentry does not initialize a command queue for all of its methods (e.g. setTag) #27391

Closed
pastelsky opened this issue Jul 14, 2021 · 8 comments

Comments

@pastelsky
Copy link

pastelsky commented Jul 14, 2021

Environment

SaaS (https://sentry.io/)

Version

No response

Steps to Reproduce

I'm currently using this code snippet —

https://docs.sentry.io/platforms/javascript/install/lazy-load-sentry/

to lazy load sentry onto my page. However, this script only seems to initialize a queue for some of sentry's methods.

Screenshot 2021-07-14 at 8 01 15 AM

Notably, methods like setTag and setExtra are missing.

Expected Result

The loader script should buffer all of Sentry's public methods until the bundle is loaded — or if not, at-least provide
stubs for them so that users aren't caught unaware and don't have to addnull checks when switching to the lazy snippet.

Actual Result

Trying to access window.Sentry.setTag before the actual sentry bundle has loaded results in an error — because the setTag method isn't found.

@getsentry-release
Copy link

Routing to @getsentry/team-webplatform for triage. ⏲️

@kamilogorek
Copy link
Contributor

kamilogorek commented Jul 14, 2021

A quick workaround for now: depending on the environments you support, this can be mitigated using Proxy API - https://docs.sentry.io/platforms/javascript/troubleshooting/#using-the-javascript-proxy-api

@AbhiPrasad
Copy link
Member

You can also use configureScope to gain access to setTags and setExtra. See: https://docs.sentry.io/platforms/javascript/enriching-events/scopes/#configuring-the-scope

Sentry.configureScope((scope) => {
  scope.setTags(...);
  scope.setExtra(...);
});

@pastelsky
Copy link
Author

@AbhiPrasad I'm aware of that, however, in this case I didn't intend on setting it only for a particular scope (was a global tag)

@kamilogorek thanks! we're worked around this right now by adding additional null checks, but the proxy fallback does look more full-proof.

@AbhiPrasad
Copy link
Member

setTag and configureScope both mutate the same scope reference, the one on the current active (global) hub. pushScope is the operation that will create a particular scope to use.

configureScope(scope => {
  scope.setTag("configure", "scope");
  Sentry.captureMessage(...);
});

pushScope(scope => {
  scope.setTag("push", "scope");
  Sentry.captureMessage(...);
});

// more logic here and there

// will have tag: { configure: "scope" } from `configureScope` call
Sentry.captureException(error)

https://github.com/getsentry/sentry-javascript/blob/778ad8badc87723b709e6a2b01f50c0f7487c7d6/packages/hub/src/hub.ts#L341-L346

https://github.com/getsentry/sentry-javascript/blob/778ad8badc87723b709e6a2b01f50c0f7487c7d6/packages/hub/src/hub.ts#L300-L303

@chadwhitacre
Copy link
Member

chadwhitacre commented Jul 20, 2021

Putting this on the backlog, @kamilogorek @AbhiPrasad please adjust if needed.

@lobsterkatie
Copy link
Member

I've added this to our backlog as something to consider.

@mydea
Copy link
Member

mydea commented Jun 17, 2024

I will close this because we are unlikely to support this, we want to keep the loader minimal for now!

@mydea mydea closed this as completed Jun 17, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jul 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants