aws-observability / aws-rum-web

Amazon CloudWatch RUM Web Client
Apache License 2.0
114 stars 65 forks source link

[231] Add Source Map support #565

Open andy-root opened 1 week ago

andy-root commented 1 week ago

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

andy-root commented 1 week ago

RUM Source Maps

andy-root commented 1 week ago

Apply source maps to error stacks. Enabling this feature will make fetch calls for javascript source and map files. If these files are cross domain then CORS headers must be included in their responses. If credentials or other headers are required then an optional fetch function is included.

Error events will get handled by plugins that handle errors, these include Fetch, Error and Xhr. Before each plugin records an event it will convert the Error Event to a JS Error Event. This error processing is were the Rum Event is created and the error stack is truncated. This makes for a good location to process the error stack. If the RUM client config has sourceMapsEnabled then the error's stack will be parsed and replaced with a stack written from source maps.

williazz commented 6 days ago

Thanks so much for the awesome PR! I left a few high level questions and can definitely help close the gaps.

williazz commented 6 days ago

Of the three fatures:

  1. Enhance all JSErrors with stacktrace-js - this seems very close to mergable. We need better documentation on the expected diff and value add. Also we need to validate things such as package size increase; and how large JSErrors will become with the additional info since there are hard backend limits.
  2. Apply local source maps - I don't understand if this is supported out of the box. If it is, then I have the same feedback as (1).
  3. Fetch remote source maps - This needs more design based on the above comments, and probably should be a separate PR
andy-root commented 5 days ago

Comments on the Three features

For questions about local vs remote source maps, do you mean linked vs. inline? Minified js files will usually have source maps either linked at the end of the js file or the source map content will be included at the end of the js file. You either have 2 files, file.js and file.js.map or 1 larger js file that contains both the source and maps. In either case the change in size of the error stack will be the same.

FYI, I have our production apps using a similar design for applying sourcemaps with RUM and I increased our stacktraces from the default 1000 to 2000 through the RUM config.