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

Improve detection of minified source files

Open loewenheim opened this issue 2 years ago • 5 comments

The code that determines if a source file that has been added to a SourceMapProcessor is minified is here. It checks

  1. if the file name contains the substring ".min."
  2. if the file contains a debug id or source mapping URL
  3. a bunch of heuristics based on code shape and whatnot.

Another reason to consider a file minified might be if it has a sourcemap in the "obvious" location (i.e. a sibling file with same file name, but the extension .map). We already have logic for finding such a sourcemap in the form of the guess_sourcemap_reference function, but that function refers to the SourceMapProcessor's internal list of sourcemaps—something we can't rely on until we're finished with adding files.

loewenheim avatar Mar 13 '23 18:03 loewenheim

I think we might want to talk to the web folks to see what common filename patterns they see too. For instance chunk is a pretty common indicator now that something is transpiled.

mitsuhiko avatar Mar 13 '23 18:03 mitsuhiko

IMO flagging everything that has a corresponding source map as "minified" is a good idea. The name "minified" is a bit misleading, as it does not need to be "minified" at all, it just has to be a file that has a sourcemap because it was created from a different source file.

Swatinem avatar Mar 14 '23 09:03 Swatinem

We also have files like this: https://github.com/getsentry/sentry-cli/blob/master/tests/integration/_fixtures/inject/server/chunks/flight-server-css-manifest.js, which looks minified at a glance, having only a single long line. Is this a false negative in our detection?

loewenheim avatar Mar 14 '23 11:03 loewenheim

It is a single line, but it's too close looking to a legit code.

module.exports = { MAX_RETRIES: 5, BASE_URL: 'http://sentry.io' }

Heuristics look at things like line length, short variable names etc., end this file simply has none of those - https://docs.rs/might-be-minified/0.3.0/src/might_be_minified/lib.rs.html#221-232

kamilogorek avatar Mar 14 '23 14:03 kamilogorek

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 Apr 05 '23 00:04 github-actions[bot]

#1958 eliminates the distinction between minified and non-minified files at the location linked in the original comment (which we use for sourcemaps inject and sourcemaps upload).

So, I am going to close this issue for now.

szokeasaurusrex avatar Mar 19 '24 13:03 szokeasaurusrex