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: crash reporter settings #393

Merged
merged 17 commits into from
Jan 9, 2025
Merged

Conversation

cristianoventura
Copy link
Collaborator

Description

This PR depends on #365. It adds a new option to the Settings dialog that allows users to opt out of k6 Studio sending error/crash reports to Sentry.

How to Test

  • manually throw an error anywhere in the application that is triggered on user click (e.g. toggle theme)
  • toggle the setting and check that the error event is not sent when the setting is disabled

Checklist

  • I have performed a self-review of my code.
  • I have added tests for my changes.
  • I have run linter locally (npm run lint) and all checks pass.
  • I have run tests locally (npm test) and all tests pass.
  • I have commented on my code, particularly in hard-to-understand areas.

Screenshots (if appropriate):

Screenshot 2024-12-30 at 11 04 28 AM

Related PR(s)/Issue(s)

@cristianoventura cristianoventura self-assigned this Dec 31, 2024
onCheckedChange={field.onChange}
/>{' '}
Send crash reports and error data to Grafana to help improve k6
Studio. <Link href="">Learn more.</Link>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We'll likely need a link here leading to a doc similar to the usage collection.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we remove the link until we have the doc? Currently, it reloads the app

Copy link
Collaborator Author

@cristianoventura cristianoventura Jan 7, 2025

Choose a reason for hiding this comment

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

I was waiting for feedback and thinking that we could potentially have that link before releasing this feature. I just removed it and we can add it back later.

Comment on lines +71 to +74
beforeSend: (event) => {
if (appSettings.telemetry.errorReport) {
return event
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sentry is always initialized in Prod mode, but the event is dynamically sent based on the errorReport setting.

Comment on lines 120 to 123
telemetry: {
usageReport: settings.usageReport.enabled,
errorReport: true,
},
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

A migration was needed since usageReport was renamed to `telemetry

Copy link
Collaborator

Choose a reason for hiding this comment

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

Don't we need to bump schema version, copy schema to v3 and add the adjustments there?
Everything works now, but if we introduce another change that depends on useageReport or telemetry and the user has skipped one version between updates - the migration won't work anymore because we lose that middle step.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You're right! I thought we hadn't released that change yet but it looks like v2 is the latest one in prod.

@cristianoventura cristianoventura marked this pull request as ready for review January 2, 2025 16:31
@cristianoventura cristianoventura requested a review from a team as a code owner January 2, 2025 16:31
@cristianoventura cristianoventura requested review from going-confetti, e-fisher and Llandy3d and removed request for a team January 2, 2025 16:31
Copy link
Collaborator

@e-fisher e-fisher left a comment

Choose a reason for hiding this comment

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

Added comments about migration and empty link

Base automatically changed from feat/crash-reporter to main January 7, 2025 15:08
Copy link
Collaborator

@going-confetti going-confetti left a comment

Choose a reason for hiding this comment

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

In my opinion, the checkbox label/description should give the user a better understanding of where the data is sent, especially since we don't have the docs yet

src/components/Settings/TelemetrySettings.tsx Outdated Show resolved Hide resolved
}

export const AppSettingsSchema = z.object({
version: z.literal('3.0'),
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's probably too late to ask this, but in which cases would we bump the "minor" version? Maybe it's unnecessary and could be omitted from this version on?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Since all migrations are required (and likely cause breaking changes) and automatically fast-forwarded, I don't think bumping the minor would ever be suitable 🤔. We could use timestamps instead, like other major frameworks do. This change could also be incorporated into #392 where the migration name and version are automatically generated.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We could use timestamps instead, like other major frameworks do. This change could also be incorporated into #392 where the migration name and version are automatically generated.

I like this idea!


// conditionally send the event based on the user's settings
beforeSend: (event) => {
if (appSettings.telemetry.errorReport) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I remember writing a comment about this, but can't find anymore, probably forgot to submit it, sorry about that 😅

appSettings could be undefined, we need to update type to be AppSettings | undefined where is declared and add checks here. I've added a throw to appReady callback before appSettings variable is initialized and got this exception

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch! I chose to initialize the variable with the defaultSettings object instead. If we leave it as undefined, we'd need to perform additional type checks in multiple places, which could increase the overall maintenance effort.

Copy link
Collaborator

@e-fisher e-fisher left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@@ -79,7 +88,7 @@ const PROXY_RETRY_LIMIT = 5
let proxyRetryCount = 0
let currentClientRoute = '/'
let wasAppClosedByClient = false
export let appSettings: AppSettings
export let appSettings = defaultSettings
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure how I feel about this, as it can lead to a situation when defaultSettings would be used instead of the actual settings. I see that it's only imported in browser.ts - can we add detectBrowserPath as a parameter to launchBrowser instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not sure how I feel about this, as it can lead to a situation when defaultSettings would be used instead of the actual settings

@going-confetti This already happens. The getSettings method returns the default object if the settings file can't be parsed. It's a fault tolerance mechanism. appSettings will be set at some point (either to the actual settings or failover to default)

} catch (error) {
log.error('Failed to parse settings file', error)
// if the file is invalid during runtime,
// return a valid settings object so the app can keep running
return defaultSettings

I see that it's only imported in browser.ts - can we add detectBrowserPath as a parameter to launchBrowser instead?

This is a good idea! There will be probably additional places where we'll have to use appSettings with the separation of modules that we plan to work on #378, so I'll defer this change to when we get there.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This already happens. The getSettings method returns the default object if the settings file can't be parsed. It's a fault tolerance mechanism. appSettings will be set at some point (either to the actual settings or failover to default)

IMO it could be a big deal if the settings can't be parsed and we use default settings as a fallback without informing the user. For example, if they have custom proxy configuration and stuff suddenly stops working.
Seems out of scope of this PR though

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed! We can work on something to let users know that the default config was loaded if the parsing fails.

@cristianoventura cristianoventura merged commit 898bde8 into main Jan 9, 2025
2 checks passed
@cristianoventura cristianoventura deleted the feat/crash-reporter-settings branch January 9, 2025 16:31
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