Provide a means for capturing stack trace for messages that are not errors
See original GitHub issue… without relying on the logging integration.
SDK v0.7.10
Currently, the only way to do this is via the logging integration and issuing a log at the configured level or higher with exc_info=True
. I don’t think this is a good substitute because:
- I don’t want to classify these events as errors (the end goal being errors should drive alerts)
- Sometimes there are interesting or unexpected events that I want to debug more and leveraging Sentry’s stack traces with locals helps in this regard
- I don’t want to lower our logging integration level to warning or similar, as that may spam our project with a lot of warnings/events that are not interesting or useful
Ideally, the Sentry SDK could add an additional argument to the and capture_message
APIs to make this simple from a user perspective:
sentry_sdk.capture_message("Unexpected event", level="warning", stack_trace=True)
I’m trying to get this working locally with the SDK, and it’s leading to incomplete event data (see picture) and also leading to pretty hairy code.
sentry_sdk.capture_event({"message": "oops 2", "level": "warning", "threads": [{"stacktrace": sentry_sdk.utils.current_stacktrace(with_locals=True), "crashed": False, "current": True}])
This was more or less copied from the code I see for adding stack traces in Client._prepare_event
.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:6
- Comments:25 (14 by maintainers)
Top Results From Across the Web
Understanding Error.captureStackTrace and stack trace ...
captureStackTrace returns a string that represents the location of that particular error in the call. It gives us a ...
Read more >What is a Java Stack Trace? How to Read & Analyze Traces
The stack trace includes information about program subroutines and can be used to debug or troubleshoot and is often used to create log...
Read more >JavaScript Errors and Stack Traces in Depth - Lucas F. Costa
Manipulating stack traces lets you clean up unuseful data and focus on what matters. Also, when understanding what exactly are Errors and their ......
Read more >Stack Trace: How to Debug Your Application With a Stack Trace
A stack trace is a valuable piece of information that can be used for debugging purposes. Whenever you encounter an error in your...
Read more >Understanding the Python Traceback
Python prints a traceback when an exception is raised in your code. The traceback output can be a bit overwhelming if you're seeing...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As it stands you’re the first one I know who both has a usecase like this and is sufficiently dissatisfied with the UX around it to want additional API surface. So you have to understand that this is not something we want to change right now, especially considering that this thread contains multiple workarounds that are not even fragile or rely on unstable API, instead they are just verbose.
The simplest suggestion with
before_send
, that I think I didn’t elaborate enough on, would look like this (untested):Admittedly I don’t really understand whether you can’t or don’t want to use the logging integration to do this. It seems to me like the above would work perfectly fine regardless of whether you use structlog besides it.
It would be useful if you could override this on single calls though. The use case I have is to have it enabled by default, because it provides more info (with logging in particular), but would like to avoid it with a custom
sentry_sdk.capture_message("Initialized Sentry")
(where/when logging is not configured yet, but also there it would not be possible to turn it off for a particular logging message anyway).