Repository navigation
feat: add attach_stacktrace option - #2195
Conversation
Events captured without an exception or thread stack trace, like plain messages, carry no frames at all, so Sentry has nothing to group them by except the message text. Every other Sentry SDK solves this with an attach_stacktrace option; the Native SDK had no equivalent. With the option enabled, sentry__capture_event attaches the stack trace of the capturing thread as a thread entry before the scope is applied, so the frames are symbolized along with every other stack trace on the event when symbolize_stacktraces is on. Events that already carry an exception or a threads interface are left untouched, which keeps crash events as they are. Closes getsentry#1097
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2195 +/- ##
==========================================
+ Coverage 75.46% 75.53% +0.07%
==========================================
Files 103 103
Lines 28220 28242 +22
Branches 5170 5174 +4
==========================================
+ Hits 21297 21334 +37
+ Misses 5578 5559 -19
- Partials 1345 1349 +4 🚀 New features to boost your workflow:
|
|
Sorry, I've been a bit busy with the ongoing 1.0 activities. This looks good at first glance! The only thing I was wondering is whether it would be possible to have some simple integration tests?
Following the same conventions as what other SDKs already do is always a good choice 👍
I'd be fine either way. Since the same feature/option/API already exists in other SDKs, and it's an opt-in flag, it's highly unlikely to get us in trouble later... 🤔 |
Adds an attach-stacktrace flag to the integration fixture and three tests over it: the option attaches a symbolized thread stack trace to a plain message event, nothing is attached when the option is off, and an event that already carries an exception stack trace gets no threads entry. The fixture enables symbolize_stacktraces, so assert_stacktrace also covers the symbolization of the attached frames end to end.
|
No worries, and thanks for looking. Integration tests added. There's a new
The first one turned out to be worth more than I expected. The fixture already calls On the API: I'll leave it experimental for now, if that's alright. #2116 is already the path for promoting these, so experimental-then-promote fits what you're doing anyway, and it's the direction that's easy to reverse — the other way isn't. That said it's a one-line change, so just say the word and I'll flip it. |
jpnurmi
left a comment
There was a problem hiding this comment.
Nice! 💯 Thank you for yet another contribution! 🙏
On Switch, the platform integration supplies a release, enabling automatic session tracking. `sentry_close()` then sends a session envelope in addition to the event expected by the tests added in #2195. Their callback counts this envelope and replaces the saved `threads` with null, failing all three capture tests. Disable automatic session tracking in their shared setup, matching the neighboring capture tests. Introduced by: #2195 Failed CI job: https://github.com/getsentry/sentry-switch/actions/runs/38732357928/job/116426400577
Closes #1097.
A plain
sentry_capture_eventwith a message carries no frames at all, so Sentry has nothing to group those events by except the message text. Two completely different code paths logging "connection failed" end up in the same issue. Every other Sentry SDK hasattach_stacktracefor exactly this; the Native SDK was the one without it.What it does
sentry_options_set_attach_stacktrace(options, 1)makessentry__capture_eventattach the stack trace of the capturing thread as a thread entry on events that don't already have one. It is off by default, so nothing changes unless you ask for it.The attach happens just before
sentry__prepare_event, which is deliberate: the scope pass inside it runssentry__foreach_stacktrace(event, sentry__symbolize_stacktrace), so the new frames get symbolized along with every other stack trace on the event whensymbolize_stacktracesis on. I checked that locally — with symbolization enabled, every frame in the attached trace comes back with afunction.Events that already carry an
exceptionor athreadsinterface are skipped, so crash events keep the stack the backend captured. Transactions never reach this path, andsentry_capture_minidumpcallssentry__prepare_eventdirectly, so a minidump doesn't get the capturing thread's stack bolted onto it.Two things I'd like your call on
Which events. Right now it applies to every event without a stack trace, which is what the other SDKs do. The issue also floats fatal-only as an option. That's a one-line change if you prefer it — I went with the cross-SDK behaviour as the default rather than guess.
SENTRY_EXPERIMENTAL_API. I put it there rather thanSENTRY_APIbecause 1.0 is close and I'd rather not add to the stable surface right before a freeze. #2116 would pick it up later if you want it promoted. Happy to move it if you'd rather it land stable straight away.One thing worth knowing: the trace starts inside the SDK, so the first few frames are
sentry_capture_eventand friends. The existingsentry_value_new_stacktracehas the same characteristic and nothing in the tree trims SDK frames today, so I left it alone instead of inventing a trimming rule here.Tests
Three in
test_basic.c— the thread gets attached withcurrent/crashedset and a non-empty frame list, nothing is attached when the option is off, and an event that already has an exception is left alone — plus a set/get test intest_options.c.make test-unitis green at 613 tests (609 before), andclang-formatis clean.