Skip to content
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

feat: Allow ending a session with a different status code #801

Merged
merged 2 commits into from
Feb 2, 2023

Conversation

ShawnCZek
Copy link
Contributor

As of right now, the status code of the session cannot be modified through this SDK. This is a problem when errors or crashes are handled manually. Such sessions are then marked as "crash-free". This is especially problematic when the on_crash callback is used, which may discard processing the event further. This is a snippet from the inproc backend:

if (options->on_crash_func) {
SENTRY_TRACE("invoking `on_crash` hook");
event = options->on_crash_func(uctx, event, options->on_crash_data);
should_handle = !sentry_value_is_null(event);
}
if (should_handle) {
sentry_envelope_t *envelope = sentry__prepare_event(
options, event, NULL, !options->on_crash_func);
// TODO(tracing): Revisit when investigating transaction flushing
// during hard crashes.
sentry_session_t *session = sentry__end_current_session_with_status(
SENTRY_SESSION_STATUS_CRASHED);
sentry__envelope_add_session(envelope, session);
// capture the envelope with the disk transport
sentry_transport_t *disk_transport
= sentry_new_disk_transport(options->run);
sentry__capture_envelope(disk_transport, envelope);
sentry__transport_dump_queue(disk_transport, options->run);
sentry_transport_free(disk_transport);
} else {
SENTRY_TRACE("event was discarded by the `on_crash` hook");
sentry_value_decref(event);
}

This is the only place where the session may be marked with the crashed status code.

Because of these reasons, I propose making the session status a part of the public API and an option to end the session using that custom status code. Another possibility is making the session structure public like in other Sentry SDKs. However, that would be a greater change to support it properly in all places.

@loewenheim
Copy link
Contributor

LGTM, but I would like a second opinion on this.

@codecov
Copy link

codecov bot commented Feb 2, 2023

Codecov Report

Merging #801 (9438186) into master (19df84a) will decrease coverage by 0.02%.
The diff coverage is 86.66%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #801      +/-   ##
==========================================
- Coverage   81.19%   81.18%   -0.02%     
==========================================
  Files          53       53              
  Lines        6936     6947      +11     
  Branches     1111     1112       +1     
==========================================
+ Hits         5632     5640       +8     
- Misses       1194     1196       +2     
- Partials      110      111       +1     

@loewenheim loewenheim merged commit a11a107 into getsentry:master Feb 2, 2023
@ShawnCZek ShawnCZek deleted the end_session_with_status branch February 2, 2023 14:45
@supervacuus
Copy link
Collaborator

CC: @markushi, @bitsandfoxes

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.

None yet

4 participants