Skip to content

feat(tracing): Add long task collection #5529

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 24 commits into from
Aug 12, 2022
Merged

Conversation

k-fish
Copy link
Member

@k-fish k-fish commented Aug 5, 2022

fixes #3807

Summary

This adds long task collection to represent long running ui behaviour as spans in your frontend transactions. Behind an unexposed option for now.

For context, we've been collecting long tasks in our main sentry UI now, and they can be quite helpful to determine where and when the ui is being blocked (and might hint where to add custom spans if a user chose to do so).

Screenshot

Example of us using it in Sentry already

163429297-517a84f3-4229-4ea2-9fd0-3b93c6c76414

This adds long task collection to represent long running ui behaviour as spans in your frontend transactions. Behind an unexposed option for now.
@k-fish k-fish requested review from 0Calories, AbhiPrasad and a team August 5, 2022 15:46
@@ -69,7 +69,7 @@ export interface BrowserTracingOptions extends RequestInstrumentationOptions {
*
* Default: undefined
*/
_metricOptions?: Partial<{ _reportAllChanges: boolean }>;
_metricOptions?: Partial<{ _reportAllChanges: boolean, _reportLongTasks: boolean }>;
Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't really want to make another option bundle here, re-using something called 'metric options' when it makes spans doesn't sound totally right to me though.

Copy link
Member

Choose a reason for hiding this comment

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

Can we just turn it on by default? Do we really need to gate to an option?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair.

const transaction = getActiveTransaction() as IdleTransaction | undefined;
let po : PerformanceObserver | undefined = undefined;
const entryHandler: PerformanceEntryHandler = (entry: PerformanceEntry): void => {
if (transaction?.endTimestamp && po) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Checking for transaction being finished using end, if that still works, otherwise this just makes a span for long tasks, just keeping it simple to start, we can add attribution etc. later if it seems helpful.

Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to do this? Let's just attach it to any running transaction. Also we can't use optional chaining - it's increased final bundle as it's esnext feature.

@k-fish k-fish requested review from a team and lobsterkatie and removed request for a team August 5, 2022 15:48
@AbhiPrasad
Copy link
Member

200

On my review list for today

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.

We'll need to add tests before we can merge to validate.

We have browser integration tests - we can test if the span gets added here (and muck around with different scenarios and compare between chrome/safari/firefox): https://github.com/getsentry/sentry-javascript/tree/master/packages/integration-tests

https://github.com/getsentry/sentry-javascript/tree/master/packages/integration-tests/suites/tracing/metrics

const transaction = getActiveTransaction() as IdleTransaction | undefined;
let po : PerformanceObserver | undefined = undefined;
const entryHandler: PerformanceEntryHandler = (entry: PerformanceEntry): void => {
if (transaction?.endTimestamp && po) {
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to do this? Let's just attach it to any running transaction. Also we can't use optional chaining - it's increased final bundle as it's esnext feature.

@@ -148,6 +148,7 @@ export class BrowserTracing implements Integration {

const { _metricOptions } = this.options;
startTrackingWebVitals(_metricOptions && _metricOptions._reportAllChanges);
startTrackingLongTasks(_metricOptions && _metricOptions._reportLongTasks);
Copy link
Member

Choose a reason for hiding this comment

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

IMO we rm -rf the option and just :shipit:

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah I'm fine with that

@github-actions
Copy link
Contributor

github-actions bot commented Aug 5, 2022

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 19.39 KB (+0.03% 🔺)
@sentry/browser - ES5 CDN Bundle (minified) 59.99 KB (0%)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 17.96 KB (0%)
@sentry/browser - ES6 CDN Bundle (minified) 52.88 KB (0%)
@sentry/browser - Webpack (gzipped + minified) 19.73 KB (0%)
@sentry/browser - Webpack (minified) 64.21 KB (0%)
@sentry/react - Webpack (gzipped + minified) 19.75 KB (0%)
@sentry/nextjs Client - Webpack (gzipped + minified) 44.39 KB (+0.51% 🔺)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 25.89 KB (+0.4% 🔺)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 24.26 KB (+0.94% 🔺)

@k-fish k-fish changed the title rfc(perf): Add long task collection feat(perf): Add long task collection Aug 5, 2022
@AbhiPrasad AbhiPrasad changed the title feat(perf): Add long task collection feat(tracing): Add long task collection Aug 8, 2022
@@ -19,6 +19,10 @@ module.exports = async ({ page, url, requests }) => {
description: 'GET http://example.com',
op: 'http.client',
},
{
description: 'Long Task',
op: 'ui.long-task',
Copy link
Member

Choose a reason for hiding this comment

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

woah :o

@0Calories
Copy link
Contributor

Seems like a new experimental feature, but we may be able to use TaskAttributionTiming to get some contextual data for LongTasks, which we could attach as additional data on LongTask spans

@AbhiPrasad
Copy link
Member

The task attributions doesn't have good details IMO (spec: https://w3c.github.io/longtasks/#sec-TaskAttributionTiming), I don't know how much value we'll get by attaching it to the span.

@0Calories
Copy link
Contributor

Yeah you're right, that's unfortunate. I was hoping that we might be able to get some useful info from containerName, but didn't realize the possible values were so limited

@k-fish k-fish force-pushed the ref/add-long-task-collection branch from f0879db to 63a171c Compare August 12, 2022 14:50
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.

Good to merge this in when you are! We'll need to update the docs page to add the new experimental option: https://github.com/getsentry/sentry-docs/blob/master/src/platforms/javascript/common/performance/instrumentation/automatic-instrumentation.mdx

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.

Add Long Tasks API as spans
3 participants