-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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: Add source map images to debug_meta
#7168
Merged
Merged
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
a189b19
feat: Put `abs_path` into stack frame object
lforst 5ce6d8c
feat: Add source map images to `debug_meta`
lforst 6097d8c
Merge branch 'develop' into lforst-put-abspath-in-stackframe
lforst 0b0220d
Merge branch 'lforst-put-abspath-in-stackframe' into lforst-sourcemap…
lforst 9c406da
.
lforst e2f6f9c
Merge branch 'lforst-put-abspath-in-stackframe' into lforst-sourcemap…
lforst df4a3b2
lint
lforst b3c336b
Merge branch 'develop' into lforst-sourcemap-debug-meta
lforst 81c326e
Code file
lforst 2da12d1
Add test
lforst 8578a89
Merge branch 'develop' into lforst-sourcemap-debug-meta
lforst 2186c67
.
lforst 89eb55b
Early return
lforst 485b981
Add comment explaining sentry debug ids
lforst d88199d
try catch
lforst 2fa925c
Use reduce
lforst File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import type { ClientOptions, Event, EventHint } from '@sentry/types'; | ||
import { dateTimestampInSeconds, normalize, resolvedSyncPromise, truncate, uuid4 } from '@sentry/utils'; | ||
import type { ClientOptions, Event, EventHint, StackParser } from '@sentry/types'; | ||
import { dateTimestampInSeconds, GLOBAL_OBJ, normalize, resolvedSyncPromise, truncate, uuid4 } from '@sentry/utils'; | ||
|
||
import { Scope } from '../scope'; | ||
|
||
|
@@ -36,6 +36,7 @@ export function prepareEvent( | |
|
||
applyClientOptions(prepared, options); | ||
applyIntegrationsMetadata(prepared, integrations); | ||
applyDebugMetadata(prepared, options.stackParser); | ||
|
||
// If we have scope given to us, use it as the base for further modifications. | ||
// This allows us to prevent unnecessary copying of data if `captureContext` is not provided. | ||
|
@@ -112,6 +113,57 @@ function applyClientOptions(event: Event, options: ClientOptions): void { | |
} | ||
} | ||
|
||
/** | ||
* Applies debug metadata images to the event in order to apply source maps by looking up their debug ID. | ||
*/ | ||
export function applyDebugMetadata(event: Event, stackParser: StackParser): void { | ||
const debugIdMap = GLOBAL_OBJ._sentryDebugIds; | ||
|
||
if (!debugIdMap) { | ||
return; | ||
} | ||
|
||
// Build a map of abs_path -> debug_id | ||
const absPathDebugIdMap: Record<string, string> = {}; | ||
Object.keys(debugIdMap).forEach(debugIdStackTrace => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. l: Can this just be a single reduce call? |
||
const parsedStack = stackParser(debugIdStackTrace); | ||
for (const stackFrame of parsedStack) { | ||
if (stackFrame.abs_path) { | ||
absPathDebugIdMap[stackFrame.abs_path] = debugIdMap[debugIdStackTrace]; | ||
break; | ||
} | ||
} | ||
}); | ||
|
||
// Get a Set of abs_paths in the stack trace | ||
const errorAbsPaths = new Set<string>(); | ||
if (event && event.exception && event.exception.values) { | ||
event.exception.values.forEach(exception => { | ||
if (exception.stacktrace && exception.stacktrace.frames) { | ||
exception.stacktrace.frames.forEach(frame => { | ||
if (frame.abs_path) { | ||
errorAbsPaths.add(frame.abs_path); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. l: if we try catch this we can get rid of all the undefined checks ^^ |
||
|
||
// Fill debug_meta information | ||
event.debug_meta = event.debug_meta || {}; | ||
event.debug_meta.images = event.debug_meta.images || []; | ||
const images = event.debug_meta.images; | ||
errorAbsPaths.forEach(absPath => { | ||
if (absPathDebugIdMap[absPath]) { | ||
images.push({ | ||
type: 'sourcemap', | ||
code_file: absPath, | ||
debug_id: absPathDebugIdMap[absPath], | ||
}); | ||
} | ||
}); | ||
} | ||
|
||
/** | ||
* This function adds all used integrations to the SDK info in the event. | ||
* @param event The event that will be filled with all integrations. | ||
|
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,68 @@ | ||
import type { Event } from '@sentry/types'; | ||
import { createStackParser, GLOBAL_OBJ } from '@sentry/utils'; | ||
|
||
import { applyDebugMetadata } from '../../src/utils/prepareEvent'; | ||
|
||
describe('applyDebugMetadata', () => { | ||
afterEach(() => { | ||
GLOBAL_OBJ._sentryDebugIds = undefined; | ||
}); | ||
|
||
it('should put debug source map images in debug_meta field', () => { | ||
GLOBAL_OBJ._sentryDebugIds = { | ||
'filename1.js\nfilename1.js': 'aaaaaaaa-aaaa-4aaa-aaaa-aaaaaaaaaa', | ||
'filename2.js\nfilename2.js': 'bbbbbbbb-bbbb-4bbb-bbbb-bbbbbbbbbb', | ||
'filename4.js\nfilename4.js': 'cccccccc-cccc-4ccc-cccc-cccccccccc', | ||
}; | ||
|
||
const stackParser = createStackParser([0, line => ({ filename: line, abs_path: line })]); | ||
|
||
const event: Event = { | ||
exception: { | ||
values: [ | ||
{ | ||
stacktrace: { | ||
frames: [ | ||
{ abs_path: 'filename1.js', filename: 'filename1.js' }, | ||
{ abs_path: 'filename2.js', filename: 'filename2.js' }, | ||
{ abs_path: 'filename1.js', filename: 'filename1.js' }, | ||
{ abs_path: 'filename3.js', filename: 'filename3.js' }, | ||
], | ||
}, | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
applyDebugMetadata(event, stackParser); | ||
|
||
expect(event.debug_meta?.images).toContainEqual({ | ||
type: 'sourcemap', | ||
code_file: 'filename1.js', | ||
debug_id: 'aaaaaaaa-aaaa-4aaa-aaaa-aaaaaaaaaa', | ||
}); | ||
|
||
expect(event.debug_meta?.images).toContainEqual({ | ||
type: 'sourcemap', | ||
code_file: 'filename2.js', | ||
debug_id: 'bbbbbbbb-bbbb-4bbb-bbbb-bbbbbbbbbb', | ||
}); | ||
|
||
// expect not to contain an image for the stack frame that doesn't have a corresponding debug id | ||
expect(event.debug_meta?.images).not.toContainEqual( | ||
expect.objectContaining({ | ||
type: 'sourcemap', | ||
code_file: 'filename3.js', | ||
}), | ||
); | ||
|
||
// expect not to contain an image for the debug id mapping that isn't contained in the stack trace | ||
expect(event.debug_meta?.images).not.toContainEqual( | ||
expect.objectContaining({ | ||
type: 'sourcemap', | ||
code_file: 'filename4.js', | ||
debug_id: 'cccccccc-cccc-4ccc-cccc-cccccccccc', | ||
}), | ||
); | ||
}); | ||
}); |
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
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
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
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
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.
Where is this
_sentryDebugIds
actually set? Can't find it anywhere in the codebase...?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.
Oh I should definitely add a comment explaining this --> 485b981