Athol Birtley
06/05/2022, 3:57 AMNODE_OPTIONS: '--enable-source-maps'
, and have notified Sentry that there is a release (using the git SHA as the release name). I have also connected Sentry and Gitlab using the official integration. When I force an error from a lambda function, Sentry associates it with the right release, and the release has the full commit history since the previous commit. Source maps are also semi-working, because Sentry tells me the error is in /backend/services/error.ts
at line 16:9
, instead of /backend/services/error.js
at line 1928379128:1928391823
or whatever. But despite the typescript path being the exact same path as the source file in my gitlab repository, Sentry isn’t showing any source (beyond the stack trace).
I have tried uploading source maps manually to sentry, but the source maps are for /backend/services/error.js
(note the js
extension) whereas with source maps enabled, the error reports itself as coming from /backend/services/error.ts
, so my manually uploaded source maps don’t get picked up.
I have also tried turning off --enable-source-maps
, and just uploading the source maps to sentry, but that also doesn’t work. (Sentry complains that it can’t find the .js
file in my gitlab repository).
Having the correct filename and line numbers is much better than nothing, I was just wondering if anyone’s managed to get the source code to display in Sentry as well.Sam Hulick
06/05/2022, 7:24 PMSam Hulick
06/05/2022, 7:26 PMconfig/esbuild.js
(attached)Sam Hulick
06/05/2022, 7:27 PMapp.setDefaultFunctionProps({
bundle: {
esbuildConfig: {
plugins: 'config/esbuild.js'
}
}
})
Sam Hulick
06/05/2022, 7:29 PM.build/sourcemaps
. you can publish those however you wish, but for Sentry, you want to do something like:
#!/bin/sh
set -ex
export SENTRY_RELEASE=$(git rev-parse --short HEAD)
yarn sst deploy $*
yarn sentry-cli releases --org myorg --project myproj files $SENTRY_RELEASE upload-sourcemaps .build/sourcemaps
Sam Hulick
06/05/2022, 7:29 PMAthol Birtley
06/05/2022, 10:03 PMAthol Birtley
06/06/2022, 12:46 AMNODE_OPTIONS: '--enable-source-maps'
from my default function properties environment settings, so that errors are thrown using the transpiled and minified filenames (eg error.js not error.ts)
3. Use the Sentry RewriteFrames plugin to strip the /var/task
path from the stack traces, so that the stack frames match up with the filenames in the source maps. (Note - when uploading source maps to sentry, you can add a /var/task
prefix to your source maps, but this won’t help, because the source maps themselves don’t make any mention of /var/task
)
Sentry.init({
dsn: 'https://***.<http://ingest.sentry.io/***|ingest.sentry.io/***>',
integrations: [
new RewriteFrames({
root: '/var/task',
}),
],
I still get a bunch of ../../../
in my source paths when the errors appear in Sentry, which might be fixable by following these instructions, but honestly that is noise I can live with for now 😅Frank
Sam Hulick
06/06/2022, 3:16 PMconst lambdaPathPattern = /^(?:async\s+)?\/var\/task\//;
[...]
new RewriteFrames({
iteratee: frame => {
if (lambdaPathPattern.test(frame.filename!)) {
frame.filename = frame.filename!.replace(
lambdaPathPattern,
'app:///'
);
}
return frame;
},
}),
[...]
Sam Hulick
06/06/2022, 3:19 PMMischa Spiegelmock
06/07/2022, 2:26 AMNODE_OPTIONS: "--enable-source-maps
Athol Birtley
06/07/2022, 3:23 AM/backend/services/myendpoint.ts:10
) but that it did not display the source code where the error occurred, because the source map was for a .js
file, ie /backend/services/myendpoint.js.map
But my bigger question is how is your source map data making its way to Sentry? Are you uploading them as part of the build process (and if so what are you naming them)? Does Sentry have the ability to “peek inside” a deployed lambda function? Or can the stack trace data be somehow augmented with the source map context (eg the stack frame line plus five lines either side)?
My understanding - which could well be mistaken - was that Sentry needed a copy of the source map file in order to display the code where the error occurred.Mischa Spiegelmock
06/07/2022, 3:27 AMAthol Birtley
06/07/2022, 3:29 AMNODE_OPTIONS: "--enable-source-maps
works well. But if you are lazy and also want the source code from that line (and surrounding lines) shown to you inside Sentry, then I think you need to go through the steps Sam has outlined above.Mischa Spiegelmock
06/07/2022, 2:39 PMSam Hulick
06/07/2022, 2:48 PMthdxr
06/07/2022, 6:43 PMthdxr
06/07/2022, 6:43 PMSam Hulick
06/07/2022, 7:17 PMSam Hulick
06/07/2022, 7:18 PMthdxr
06/07/2022, 7:36 PMSam Hulick
06/07/2022, 7:36 PMthdxr
06/07/2022, 7:37 PMSam Hulick
06/07/2022, 7:39 PMsourcemapOutputDir
is not defined, it just gets included in the Lambda zip filesMischa Spiegelmock
06/07/2022, 8:32 PMMischa Spiegelmock
06/07/2022, 8:32 PMAthol Birtley
06/08/2022, 1:17 AMMischa Spiegelmock
06/08/2022, 4:01 AM