-
Notifications
You must be signed in to change notification settings - Fork 2
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
Update wonder-stuff-sentry to Sentry v9 #1122
Open
jeremywiebe
wants to merge
5
commits into
main
Choose a base branch
from
jer/sentry-8
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+199
−324
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ef0f6c3
Add dev/peer deps for wonder-stuff-sentry for Sentry v8
jeremywiebe 0c8bdb3
Update KindErrorData integration to be compatible with Sentry v8
jeremywiebe 5773e97
docs(changeset): Update KindErrorData integration to be compatible wi…
jeremywiebe 252d5c2
Upgrade Sentry to v9
jeremywiebe d602916
Update filenames to match exported symbol
jeremywiebe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@khanacademy/wonder-stuff-sentry": major | ||
--- | ||
|
||
Migrate the `KindErrorData` integration to be compatible with @sentry/types@9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,5 @@ coverage | |
**/*.template | ||
**/package.json | ||
**/*.md | ||
docs/assets/main.js | ||
docs/** | ||
packages/eslint-plugin-khan/demo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
.../wonder-stuff-sentry/src/__tests__/__snapshots__/kind-error-data-integration.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`KindErrorData #constructor when not built for production should throw if options are invalid ({ | ||
kindTagName: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-kind', | ||
groupByTagName: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-group-by', | ||
concatenatedMessageTagName: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-concatenated-message' | ||
}) 1`] = `"Invalid options"`; | ||
|
||
exports[`KindErrorData #constructor when not built for production should throw if options are invalid ({ concatenatedMessageTagName: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' }) 1`] = `"Invalid options"`; | ||
|
||
exports[`KindErrorData #constructor when not built for production should throw if options are invalid ({ groupByTagName: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' }) 1`] = `"Invalid options"`; | ||
|
||
exports[`KindErrorData #constructor when not built for production should throw if options are invalid ({ kindTagName: 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' }) 1`] = `"Invalid options"`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
packages/wonder-stuff-sentry/src/kind-error-data-integration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import {Errors} from "@khanacademy/wonder-stuff-core"; | ||
import {Integration, Event, EventHint} from "@sentry/core"; | ||
import type {KindErrorDataOptions} from "./types"; | ||
|
||
import {collateSentryData} from "./collate-sentry-data"; | ||
import {DefaultKindErrorDataOptions} from "./default-kind-error-data-options"; | ||
import {isTagKeyValid} from "./is-tag-key-valid"; | ||
import {KindSentryError} from "./kind-sentry-error"; | ||
|
||
type InvalidTags = { | ||
invalidKindTag?: string; | ||
invalidGroupByTag?: string; | ||
invalidConcatenatedMessageTag?: string; | ||
}; | ||
|
||
const INTEGRATION_NAME = "KindErrorData"; | ||
|
||
function buildOptionsWithDefaults( | ||
options?: Partial<KindErrorDataOptions>, | ||
): KindErrorDataOptions { | ||
const _options = { | ||
...DefaultKindErrorDataOptions, | ||
...options, | ||
}; | ||
|
||
if (process.env.NODE_ENV !== "production") { | ||
// Let's make sure we got valid options. | ||
const invalidTagNames: InvalidTags = {}; | ||
if (!isTagKeyValid(_options.kindTagName)) { | ||
invalidTagNames.invalidKindTag = _options.kindTagName; | ||
} | ||
if (!isTagKeyValid(_options.groupByTagName)) { | ||
invalidTagNames.invalidGroupByTag = _options.groupByTagName; | ||
} | ||
if (!isTagKeyValid(_options.concatenatedMessageTagName)) { | ||
invalidTagNames.invalidConcatenatedMessageTag = | ||
_options.concatenatedMessageTagName; | ||
} | ||
if (Object.keys(invalidTagNames).length) { | ||
throw new KindSentryError("Invalid options", Errors.InvalidInput, { | ||
sentryData: { | ||
contexts: { | ||
invalidTagNames: { | ||
...invalidTagNames, | ||
}, | ||
}, | ||
}, | ||
}); | ||
} | ||
} | ||
|
||
return _options; | ||
} | ||
|
||
/** | ||
* Attaches extracted information from the Error object to extra field in the Event | ||
*/ | ||
function enhanceEventWithErrorData( | ||
options: KindErrorDataOptions, | ||
event: Event, | ||
hint?: EventHint, | ||
): Event { | ||
const maybeError = hint?.originalException; | ||
// We only enhance events of type error. | ||
if (!(maybeError instanceof Error)) { | ||
return event; | ||
} | ||
|
||
// Collate the data we want to collect. | ||
const {tags, contexts, fingerprint} = collateSentryData( | ||
options, | ||
maybeError, | ||
); | ||
|
||
// Now that we have data, we need to attach it to the event. | ||
/** | ||
* Tags help categorize things. | ||
*/ | ||
event.tags = { | ||
...event.tags, | ||
...tags, | ||
}; | ||
|
||
/** | ||
* Each context creates a new headed section in the sentry report. | ||
* Useful for grouping specific context together. | ||
* | ||
* We now output all the contexts to the scope. | ||
*/ | ||
const updatedContexts = { | ||
...event.contexts, | ||
...contexts, | ||
} as const; | ||
/** | ||
* NOTE: If you don't see Sentry serializing the right depth in your | ||
* contexts, increase the `normalizeDepth` option of the Sentry | ||
* configuration; it defaults to 3, which is not always enough. | ||
*/ | ||
event.contexts = updatedContexts; | ||
|
||
/** | ||
* Fingerprint helps group like messages that otherwise would not | ||
* get grouped. | ||
*/ | ||
event.fingerprint = [...(event.fingerprint ?? []), ...fingerprint]; | ||
|
||
return event; | ||
} | ||
|
||
export function kindErrorDataIntegration( | ||
options?: Partial<KindErrorDataOptions>, | ||
): Integration { | ||
const _options = buildOptionsWithDefaults(options); | ||
|
||
return { | ||
name: INTEGRATION_NAME, | ||
processEvent(event, hint, client) { | ||
return enhanceEventWithErrorData(_options, event, hint); | ||
}, | ||
}; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: I would expect this to be a moved file also? Is the other snapshot not deleted?