sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

Proper way to handle file:/// paths

Open irkinwork opened this issue 3 years ago • 15 comments

Environment

self-hosted (https://develop.sentry.dev/self-hosted/)

Version

22.5.0.dev0

Steps to Reproduce

I try to add Sentry sourcemaps on smarttv app. Sourcemaps are uploaded correctly. It works nice on PC, but not on smarttv, where paths to js files look like:

file:///media/developer/apps/usr/palm/applications/app/main.js And sourcemaps don’t work.

What I already tried:

Sentry.init({
	new RewriteFramesIntegration({
	  iteratee: frame => {
	    if (!frame.filename) {
	      return frame;
	    }
	    const [filename] = frame.filename.split('/').reverse();
	
	    return { ...frame, filename: `~/${filename}` };
	  },
	}),
}
Sentry.init({
	new RewriteFramesIntegration({
	  iteratee: frame => {
	    if (!frame.filename) {
	      return frame;
	    }
	    const [filename] = frame.filename.split('/').reverse();
	
	    return { ...frame, filename };
	  },
	}),
}
Sentry.init({
	new RewriteFramesIntegration({
	  iteratee: frame => {
	    if (!frame.filename) {
	      return frame;
	    }
	    const [filename] = frame.filename.split('/').reverse();
	
	    return { ...frame, filename: `app:///${filename}` };
	  },
	}),
}
new SentryWebpackPlugin({
		urlPrefix: '/media/developer/apps/usr/palm/applications/app/',
}),
new SentryWebpackPlugin({
		urlPrefix: 'file:///media/developer/apps/usr/palm/applications/app/',
}),

What is a proper solution to handle this case?

Expected Result

Sourcemaps work

Actual Result

No sourcemaps

irkinwork avatar Apr 20 '22 12:04 irkinwork

Routing to @getsentry/owners-ingest for triage. ⏲️

getsentry-release avatar Apr 20 '22 13:04 getsentry-release

Routing to @getsentry/team-web-sdk-frontend for triage. ⏲️

getsentry-release avatar Apr 20 '22 17:04 getsentry-release

Routing to @getsentry/team-web-sdk-frontend for triage. ⏲️

getsentry-release avatar Apr 20 '22 17:04 getsentry-release

Hi @irkinwork, thanks for writing in. Can you let us know more about your setup? What do the source map files look like (especially the comment line at the bottom)?

lforst avatar Apr 25 '22 21:04 lforst

@lforst Thank for your response.

Comment line at the bottom looks like:

//# sourceMappingURL=32-3e6aa3.js.map

As I mentioned before I have no problem when I host them on PC.

irkinwork avatar Apr 26 '22 10:04 irkinwork

Is the code on the smart tv running through node or some sort of browser?

lforst avatar Apr 26 '22 11:04 lforst

@lforst App on smarttv running through Chrome like browser.

irkinwork avatar Apr 26 '22 17:04 irkinwork

@irkinwork Sorry for the delay, would it be possible for you to provide screenshots of your artifacts in the UI? The name/path of the artifacts is important.

Basically what we need to do is to match the stack frame filename up with the uploaded file.

lforst avatar May 03 '22 15:05 lforst

Names are matched.

image image

irkinwork avatar May 04 '22 16:05 irkinwork

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

github-actions[bot] avatar May 26 '22 00:05 github-actions[bot]

Hi, sorry for not getting back to you sooner. Could you resolve the issue?

If not, here's what I would check. For sentry to pick up your source maps, the comment at the bottom of your minified file (e.g. //# sourceMappingURL=foobar.js.map) needs to match the path of the uploaded artifacts in the sentry interface (e.g. ~/foobar.js.map). Both the minified file, and the source map need to be uploaded.

lforst avatar May 30 '22 11:05 lforst

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

github-actions[bot] avatar Jun 21 '22 00:06 github-actions[bot]

@lforst thank for your reply. No, I couldn't solve this issue. But everything is matched.

irkinwork avatar Aug 05 '22 15:08 irkinwork

@irkinwork Not long ago we shipped an update to the Sentry CLI which helps you troubleshoot why your sourcemaps aren't applied. It's called sourcemaps explain and you can read more about it here: https://docs.sentry.io/platforms/javascript/sourcemaps/troubleshooting_js/

Maybe this will help in finding the culprit.

lforst avatar Aug 08 '22 10:08 lforst

@irkinwork, I notice from your screenshot that your names do not in fact match.

If the script that errors is at, say, file:///a/b/c/script.js, and in script.js the sourceMappingURL is script.map.js (meaning the file lives at /a/b/c/script.map.js, since sourceMappingURL is a relative path), then the files need to be uploaded as either file:///a/b/c/script.js and file:///a/b/c/script.map.js or ~/a/b/c/script.js and ~/a/b/c/script.map.js. If that were your only case, you could use sentry-cli to get either of those using urlPrefix and not use RewriteFrames at all. But since you have another case, you'll have to use RewriteFrames.

It's not clear from what you've said what part differs between your two cases, but is it possible to distinguish your files by basename alone? (In other words, you don't have c/script.js living alongside d/script.js, both of which might be in your stacktrace.) If that's the case, then upload your files as you have (so they come out as ~/script.js and ~/script.map.js) and use RewriteFrames with the default iteratee, which will change the script name in the stacktrace to be app:///script.js. (~ matches any scheme (in this case app://) and hostname (in this case the empty string between the second and third slashes).)

If that's not true, use urlPrefix in sentry-cli to upload your files as ~/c/script.js and ~/d/script.js (or however much of the path is necessary to distinguish the files). Then use RewriteFrames with a custom iteratee to cut your filenames down to either ~/c/script.js and ~/d/script.js or app:///c/script.js and app:///d/script.js.

lobsterkatie avatar Aug 09 '22 21:08 lobsterkatie

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀

github-actions[bot] avatar Sep 01 '22 00:09 github-actions[bot]