Skip to content

feat: RewriteFrames pluggable integration for Node#1611

Closed
kamilogorek wants to merge 3 commits intomasterfrom
rewrite-frames
Closed

feat: RewriteFrames pluggable integration for Node#1611
kamilogorek wants to merge 3 commits intomasterfrom
rewrite-frames

Conversation

@kamilogorek
Copy link
Copy Markdown
Contributor

So that users don't have to write this nasty snippet anymore – https://docs.sentry.io/clients/node/sourcemaps/#updating-raven-configuration-to-support-source-maps

Configurable through:

init({
  integrations: [new Sentry.Integrations.RewriteFrames({
    iteratee(frame) {
      // do whatever to frames. Integration extracts them and itterate over for you.
    }
  })]
})

Ref: getsentry/sentry#2632 (comment)

@getsentry-bot
Copy link
Copy Markdown
Contributor

getsentry-bot commented Oct 3, 2018

Messages
📖

✅ TSLint passed

📖

@sentry/browser gzip'ed minified size: 21.7666 kB

Generated by 🚫 dangerJS

@sheerun
Copy link
Copy Markdown
Contributor

sheerun commented Oct 3, 2018

All good but honestly I don't like the basename(frame.filename) part. Wouldn't better default be paths relative from project root? Especially they are uploaded this way by sentry-cli.

@kamilogorek
Copy link
Copy Markdown
Contributor Author

It's not that simple. I described it in here https://docs.sentry.io/clients/node/typescript/

@sheerun
Copy link
Copy Markdown
Contributor

sheerun commented Oct 3, 2018

You don't need to figure out root directory by yourself, it can be passed as a flag to @sentry/node. This would be additionally beneficial as this way of implementing this would be backward compatible (no root provided, no paths rewritten).

@sheerun
Copy link
Copy Markdown
Contributor

sheerun commented Oct 3, 2018

Another reason: bundling application into single file on node side practically never happens, usually application is executed without bundling anything

@kamilogorek
Copy link
Copy Markdown
Contributor Author

kamilogorek commented Oct 3, 2018

Another reason: bundling application into single file on node side practically never happens, usually application is executed without bundling anything

It happens a lot in serverless environments :)

Everything you want to do can be easily achieved with:

init({
  integrations: [new Sentry.Integrations.RewriteFrames({
    iteratee: (frame) => ({
      ..frame,
      filename: frame.filename.startsWith('/') ? `app:///${path.relative(root, frame.filename)}` : frame.filename;
    })
  })]
})

Using basename itself worked fine for us since we introduced support for node source maps, that's why I ported it here in the same way.

@sheerun
Copy link
Copy Markdown
Contributor

sheerun commented Oct 3, 2018

I guess this method it's fine if RewriteFrames is not enabled by default. Maybe little verbose and requires to import path and still write a bunch of code when almost always you mean to rewrite all paths relative to some dir. Maybe something like this would be better:

init({
  integrations: [new Sentry.Integrations.RewriteFrames({ root })]
})

(of course iteratee could stay for advanced use cases)

@kamilogorek
Copy link
Copy Markdown
Contributor Author

Agree with root part. I'll change that. Aand no, RewriteFrames is not enabled by default, it's a "pluggable" integration. Thanks for the suggestion

@sheerun
Copy link
Copy Markdown
Contributor

sheerun commented Oct 3, 2018

@kamilogorek Just one more question about decision to use app:/// prefix. It seems that sentry-cli upload-sourcemaps uploads files with ~/ prefix by default. Does Sentry treat these two on server side as equivalents? If not, isn't ~/ prefix a better default?

@kamilogorek
Copy link
Copy Markdown
Contributor Author

No, app:/// is mapped to ~/, but they are not equivalent, so we have to use app:///

@sheerun
Copy link
Copy Markdown
Contributor

sheerun commented Oct 4, 2018

maybe prefix option set by default to app:/// would be reasonable? this could be as well useful if uploaded sourcemaps need some directory prefix

init({
  integrations: [new Sentry.Integrations.RewriteFrames({ root, prefix })]
})

@kamilogorek
Copy link
Copy Markdown
Contributor Author

You can already achieve this using custom iteratee, I don't want to pile up more and more options.

@kamilogorek
Copy link
Copy Markdown
Contributor Author

Merged manually

@kamilogorek kamilogorek closed this Oct 8, 2018
@kamilogorek kamilogorek deleted the rewrite-frames branch October 8, 2018 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants