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

feat(core): Deprecate session APIs on hub and add global replacements #10054

Merged
merged 10 commits into from
Jan 5, 2024

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented Jan 4, 2024

Deprecates and adds top-level replacements for

  • hub.startSession -> Sentry.startSession
  • hub.endSession -> Sentry.endSession
  • hub.captureException -> Sentry.captureSession

These APIs were mostly used in browser and node startSessionTracking functions which were called on Sentry.init. I updated these usages with the global replacements and it seems integration tests are happy with it.
For now, we not only put the session onto the isolation scope but also onto the current scope to avoid changing event processing and stuff like the ANR worker, as well as avoid "soft-breaking" users who use hub.(get|set)Session.

Also, it looks like we didn't have unit tests for session APIs before (but we did have integration tests). Therefore

  • added integration test, explicitly testing the deprecated hub.startSession API
  • previously existing session integration tests now test the new top level API
  • added basic unit tests for the deprecated API
  • added basic unit tests for the new top level API

ref #10033

@@ -721,7 +721,7 @@ export abstract class BaseClient<O extends ClientOptions> implements Client<O> {
throw new SentryError(`${beforeSendLabel} returned \`null\`, will not send event.`, 'log');
}

const session = scope && scope.getSession();
const session = (scope && scope.getSession()) || getIsolationScope().getSession();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me a bit uncomfortable tbh, not sure if we for now should simply still use hub.startSession in browser/node startSessionTracking. But this change seems to be necessary for browser, since scope.getSession() returned undefined

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, is this correct in the new implementation, I wonder? Or should we simply always take the one from the isolation scope? 🤔 because the scope here would generally be the final scope being applied and can even be a temporary scope, like new Scope() 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thinking about this, I guess it doesn't hurt, if you pass a scope that actually has a session on it I guess it makes sense that we use this. But it will/should use the isolationScope in 99% of cases I guess?

Copy link
Member Author

@Lms24 Lms24 Jan 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, is this correct in the new implementation, I wonder?

You mean that we set it onto the isolation scope? I think that should be correct 🤔
EDIT: But not "complete" (see answer below)

Or should we simply always take the one from the isolation scope? 🤔

I guess it would be more correct if we're okay with not supporting people adding their own session to their current scope 🤔 Not sure if that's even a thing...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait, for v7 we probably still need to set the session also on the current scope, right? So that getCurrentHub().getScope().getSession() still returns the session

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably makes calling getIsolationScope obsolete here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm I guess so, you're right! :(

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reworked the top level APIs to also modify the current scope's session. For now this will work and spare us mocking with event processing

Copy link
Contributor

github-actions bot commented Jan 4, 2024

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay, Feedback) - Webpack (gzipped) 76.26 KB (+0.16% 🔺)
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 67.64 KB (+0.18% 🔺)
@sentry/browser (incl. Tracing, Replay) - Webpack with treeshaking flags (gzipped) 61.26 KB (+0.19% 🔺)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 32.28 KB (+0.47% 🔺)
@sentry/browser (incl. Feedback) - Webpack (gzipped) 30.62 KB (+0.42% 🔺)
@sentry/browser - Webpack (gzipped) 22.37 KB (+0.75% 🔺)
@sentry/browser (incl. Tracing, Replay, Feedback) - ES6 CDN Bundle (gzipped) 73.71 KB (+0.17% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 65.36 KB (+0.21% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 31.53 KB (+0.35% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped) 23.49 KB (+0.57% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 204.96 KB (+0.24% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 94.85 KB (+0.52% 🔺)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 69.71 KB (+0.71% 🔺)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 34.48 KB (+0.26% 🔺)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 68.02 KB (+0.14% 🔺)
@sentry/react - Webpack (gzipped) 22.4 KB (+0.74% 🔺)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 84.75 KB (+0.19% 🔺)
@sentry/nextjs Client - Webpack (gzipped) 49.36 KB (+0.34% 🔺)
@sentry-internal/feedback - Webpack (gzipped) 16.73 KB (0%)

@Lms24 Lms24 requested review from mydea and lforst January 4, 2024 12:34
const client = getClient();
const isolationScope = getIsolationScope();

const { release, environment = DEFAULT_ENVIRONMENT } = (client && client.getOptions()) || {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: should we maybe just bail out if no client is found? Doesn't matter probably, but for clarity...

Copy link
Member Author

@Lms24 Lms24 Jan 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm thinking about this, if we do so, we have to return undefined which I'm not sure we want to do. Also this means the signature of the replacement would slightly differ from the deprecated hub method. Since we're only taking env and release from the client I think it's okay to continue. Obviously, no
session will be sent but to me this aligns more with the concept of no-op spans for example.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, sounds good to me!

});

// End existing session if there's one
const currentSession = isolationScope.getSession && isolationScope.getSession();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: IMHO no need to check for getSession existance, if you have code without this everything will fail here anyhow I guess xD

@Lms24 Lms24 self-assigned this Jan 4, 2024
@Lms24 Lms24 marked this pull request as ready for review January 4, 2024 15:13
@Lms24 Lms24 requested review from AbhiPrasad and mydea January 4, 2024 15:13
@Lms24 Lms24 force-pushed the lms/feat-start-end-session branch 2 times, most recently from 7c8f841 to f392633 Compare January 4, 2024 16:51
@Lms24 Lms24 force-pushed the lms/feat-start-end-session branch from 24181c7 to 566016d Compare January 5, 2024 12:45
@Lms24 Lms24 enabled auto-merge (squash) January 5, 2024 12:57
@Lms24 Lms24 merged commit ecb4f7f into develop Jan 5, 2024
96 checks passed
@Lms24 Lms24 deleted the lms/feat-start-end-session branch January 5, 2024 13:28
c298lee pushed a commit that referenced this pull request Jan 9, 2024
…#10054)

Deprecates and adds top-level replacements for

* `hub.startSession` -> `Sentry.startSession`
* `hub.endSession` -> `Sentry.endSession`
* `hub.captureException` -> `Sentry.captureSession`

These APIs were mostly used in browser and node `startSessionTracking`
functions which were called on `Sentry.init`. I updated these usages
with the global replacements and it seems integration tests are happy
with it.
For now, we not only put the session onto the isolation scope but also
onto the current scope to avoid changing event processing and stuff like
the ANR worker, as well as avoid "soft-breaking" users who use
`hub.(get|set)Session`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants