Skip to content

capturing a message with stack trace using @sentry/browser #1666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
5 of 8 tasks
samuelcolvin opened this issue Oct 22, 2018 · 7 comments
Closed
5 of 8 tasks

capturing a message with stack trace using @sentry/browser #1666

samuelcolvin opened this issue Oct 22, 2018 · 7 comments

Comments

@samuelcolvin
Copy link

Package + Version

  • @sentry/browser
  • @sentry/node
  • raven-js
  • raven-node (raven for node)
  • other:

Version:

raven-js:        3.26.4
@sentry/browser: 4.1.1

Description

I'm switching from raven-js to @sentry/browser.

In raven-js I could do

Raven.captureMessage('whatever', {
    stacktrace: true, level: 'warning', extra: extra_info
})

However with @sentry/browser captureMessage only takes a level argument. To add extra I can use

Sentry.captureEvent({
    message: 'whatever',
    level: 'warning',
    extra: extra_info
})

(which is arguably uglier), but the real problem is that there's no way to add stacktrace: true, instead the stacktrace argument requires an actual stack trace. I tried settings stacktrace: true but I got "Discarded invalid value for parameter 'stacktrace'".

It doesn't seem to be possible to log a message with a stack using @sentry/browser.

@HazAT
Copy link
Member

HazAT commented Oct 22, 2018

There is an option called attachStacktrace for init see: https://docs.sentry.io/learn/configuration/?platform=browser#attach-stacktrace

After that you call captureMessage and you will get a stacktrace.

@samuelcolvin
Copy link
Author

samuelcolvin commented Oct 22, 2018 via email

@HazAT
Copy link
Member

HazAT commented Oct 22, 2018

While attaching a stack seems simple, it actually adds a overhead to performance and payload.
In regards to capturing any extra data with an event, you can do it either by using configureScope or withScope see: https://docs.sentry.io/learn/scopes/?platform=browser

Also if this seems not to be enough you can write your own integration.

@samuelcolvin
Copy link
Author

Thanks for the response, I'll close this however IMHO it still seems like a step back from the raven-js interface.

@kajirikajiri
Copy link

https://docs.sentry.io/platforms/javascript/configuration/options/#attach-stacktrace

This issue appears at the top of a Google search for sentry capturemessage stacktrace.
Since the reference link is Page Not Found, the latest attachStackTrace link is included.

There is an option called attachStacktrace for init see: https://docs.sentry.io/learn/configuration/?platform=browser#attach-stacktrace

After that you call captureMessage and you will get a stacktrace.

@adrian-skybaker
Copy link

There is an option called attachStacktrace for init

Not ideal as this doesn't let you include for just some messages, and the overhead involved means it's likely undesirable to enable it for all messages.

@mydea
Copy link
Member

mydea commented Apr 30, 2024

If you only want it for specific messages, I'd suggest to just use Sentry.captureException(new Error('my message with stack'), { level: 'info' }), or something along these lines.

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

No branches or pull requests

5 participants