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): Add getGlobalScope() method #9920

Merged
merged 4 commits into from
Dec 21, 2023
Merged

feat(core): Add getGlobalScope() method #9920

merged 4 commits into from
Dec 21, 2023

Conversation

mydea
Copy link
Member

@mydea mydea commented Dec 19, 2023

This scope lives in module scope and is applied to all events.

Please review this carefully, as it is important that data is correctly applied etc. There should be a decent amount of tests covering all of this, but just to make sure. This was mostly ported/extracted from node-experimental.

@mydea mydea self-assigned this Dec 19, 2023
Copy link
Contributor

github-actions bot commented Dec 19, 2023

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay, Feedback) - Webpack (gzipped) 75.6 KB (+0.23% 🔺)
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 67.02 KB (+0.3% 🔺)
@sentry/browser (incl. Tracing, Replay) - Webpack with treeshaking flags (gzipped) 60.6 KB (+0.3% 🔺)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 31.61 KB (+0.58% 🔺)
@sentry/browser (incl. Feedback) - Webpack (gzipped) 30.22 KB (+0.52% 🔺)
@sentry/browser - Webpack (gzipped) 21.91 KB (+0.86% 🔺)
@sentry/browser (incl. Tracing, Replay, Feedback) - ES6 CDN Bundle (gzipped) 73.03 KB (+0.29% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 64.72 KB (+0.31% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 30.93 KB (+0.74% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped) 22.96 KB (+0.85% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 203.1 KB (+0.34% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 93.02 KB (+0.75% 🔺)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 68.08 KB (+1.02% 🔺)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 33.88 KB (+0.62% 🔺)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 67.4 KB (+0.3% 🔺)
@sentry/react - Webpack (gzipped) 21.95 KB (+0.87% 🔺)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 84.16 KB (+0.23% 🔺)
@sentry/nextjs Client - Webpack (gzipped) 48.79 KB (+0.4% 🔺)
@sentry-internal/feedback - Webpack (gzipped) 16.56 KB (+1.11% 🔺)

@@ -469,7 +472,7 @@ export class Scope implements ScopeInterface {
}

/** @inheritDoc */
public getScopeData(): ScopeData {
public getPerScopeData(): ScopeData {
Copy link
Member

Choose a reason for hiding this comment

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

Does getPerScopeData have to be public API?

I also am not the biggest fan of the scope class being aware of a separate global scope. I'd rather it be the consumers of the scope that decide to use the global scope.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, I see your point. I'll see if we can do this another way!

@mydea mydea force-pushed the fn/globalScope branch 2 times, most recently from 0ed9262 to b17d167 Compare December 20, 2023 10:46
// of `@sentry/core` that does not have the `getAttachments` method.
// See: https://github.com/getsentry/sentry-javascript/issues/5229
// Merge scope data together
const data = getGlobalScope().getScopeData();
Copy link
Member Author

Choose a reason for hiding this comment

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

@AbhiPrasad I refactored this so that the global scope is merged/applied in prepareEvent.

const data = getGlobalScope().getPerScopeData();
const isolationScopeData = this._getIsolationScope().getPerScopeData();
const scopeData = this.getPerScopeData();
const globalScope = getGlobalScope();
Copy link
Member Author

Choose a reason for hiding this comment

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

When we introduce the isolation scope in a follow up PR, we can clean this up here and drastically simplify this! But for now I think this is "OK".

Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

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

Thanks for making the change!

import type { Scope } from '@sentry/types';

interface GlobalData {
globalScope?: Scope;
Copy link
Member

Choose a reason for hiding this comment

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

m: we need to be careful for global{s}.ts because of #5969

Let's rename this file to globalscope.ts? Also why do we have the indirection to GLOBAL_DATA.globalScope, can't we point to globalScope directly? If we refactor to need more GLOBAL_DATA, items, we can add it back.

@mydea mydea merged commit eb9bc56 into develop Dec 21, 2023
95 checks passed
@mydea mydea deleted the fn/globalScope branch December 21, 2023 10:29
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.

3 participants