Skip to content

feat(core): Allow metrics aggregator per client #10949

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

Merged
merged 3 commits into from
Mar 6, 2024

Conversation

timfish
Copy link
Collaborator

@timfish timfish commented Mar 6, 2024

This PR adds the ability to override the client used for metrics rather than being tied to using the single client getClient() returns.

Sentry.metrics.increment('counter', 1, { client });

It also adds a getMetricsAggregatorForClient exported function which is required so the Electron SDK can access the current aggregator.

sendEnvelope was added to the Client type so that all usages of BaseClient<ClientOptions> could be replaced with Client.

@timfish timfish requested a review from AbhiPrasad March 6, 2024 16:05
@timfish
Copy link
Collaborator Author

timfish commented Mar 6, 2024

I'm half tempted to make it the last function parameter with a default of getClient():

function increment(name: string, value: number = 1, data?: MetricData, client: Client = getClient()): void {

Copy link
Contributor

github-actions bot commented Mar 6, 2024

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay, Feedback) - Webpack (gzipped) 77.46 KB (+0.11% 🔺)
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 68.66 KB (+0.11% 🔺)
@sentry/browser (incl. Tracing, Replay with Canvas) - Webpack (gzipped) 72.57 KB (+0.11% 🔺)
@sentry/browser (incl. Tracing, Replay) - Webpack with treeshaking flags (gzipped) 62.22 KB (+0.12% 🔺)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 32.91 KB (+0.21% 🔺)
@sentry/browser (incl. browserTracingIntegration) - Webpack (gzipped) 32.91 KB (+0.21% 🔺)
@sentry/browser (incl. Feedback) - Webpack (gzipped) 31.36 KB (+0.06% 🔺)
@sentry/browser (incl. sendFeedback) - Webpack (gzipped) 31.37 KB (+0.05% 🔺)
@sentry/browser - Webpack (gzipped) 22.57 KB (+0.05% 🔺)
@sentry/browser (incl. Tracing, Replay, Feedback) - ES6 CDN Bundle (gzipped) 75.56 KB (+0.17% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 67.15 KB (+0.16% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 33.02 KB (+0.34% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped) 24.01 KB (+0.17% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 210.85 KB (+0.15% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 99.66 KB (+0.32% 🔺)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 71.76 KB (+0.16% 🔺)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 36.19 KB (+0.38% 🔺)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 68.94 KB (+0.1% 🔺)
@sentry/react - Webpack (gzipped) 22.6 KB (+0.05% 🔺)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 85.36 KB (+0.08% 🔺)
@sentry/nextjs Client - Webpack (gzipped) 49.77 KB (+0.14% 🔺)
@sentry-internal/feedback - Webpack (gzipped) 17.41 KB (0%)

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.

I don't mind passing client into the data bag, I'd rather not introduce an additional function argument.

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.

Do we have to backport this to v7?

/**
* @ignore This is for internal use only.
*/
getMetricsAggregatorForClient,
Copy link
Member

Choose a reason for hiding this comment

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

Actually should we export this as a separate method to help with treeshaking?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The getMetricsAggregatorForClient function is in the call chain for all the other Sentry.metrics.* functions so there will be no impact to tree shaking.

@AbhiPrasad AbhiPrasad merged commit 02b0dad into develop Mar 6, 2024
@AbhiPrasad AbhiPrasad deleted the timfish/metrics-per-client branch March 6, 2024 18:16
@timfish
Copy link
Collaborator Author

timfish commented Mar 6, 2024

Do we have to backport this to v7?

Unlikely!

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.

2 participants