Skip to content

Commit

Permalink
feat: programmatic minidump capture
Browse files Browse the repository at this point in the history
This provides a new function that will allow for independently created minidumps to be captured by sentry

Resolves: #1050
  • Loading branch information
PlasmaDev5 authored and PlasmaDev5 committed Oct 11, 2024
1 parent 21c6d0a commit d6e922d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 29 deletions.
30 changes: 1 addition & 29 deletions src/backends/sentry_backend_breakpad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,35 +119,7 @@ sentry__breakpad_backend_callback(
}

if (should_handle) {
sentry_envelope_t *envelope = sentry__prepare_event(
options, event, nullptr, !options->on_crash_func);
sentry_session_t *session = sentry__end_current_session_with_status(
SENTRY_SESSION_STATUS_CRASHED);
sentry__envelope_add_session(envelope, session);

// the minidump is added as an attachment,
// with type `event.minidump`
sentry_envelope_item_t *item = sentry__envelope_add_from_path(
envelope, dump_path, "attachment");
if (item) {
sentry__envelope_item_set_header(item, "attachment_type",
sentry_value_new_string("event.minidump"));

sentry__envelope_item_set_header(item, "filename",
#ifdef SENTRY_PLATFORM_WINDOWS
sentry__value_new_string_from_wstr(
#else
sentry_value_new_string(
#endif
sentry__path_filename(dump_path)));
}

// 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);
sentry__capture_minidump(dump_path, event, options);

// now that the envelope was written, we can remove the temporary
// minidump file
Expand Down
26 changes: 26 additions & 0 deletions src/sentry_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1169,3 +1169,29 @@ sentry_clear_crashed_last_run(void)
sentry__options_unlock();
return success ? 0 : 1;
}

void sentry__capture_minidump(sentry_path_t *dump_path, sentry_value_t event,
const sentry_options_t *options)
{
sentry_envelope_t *envelope = sentry__prepare_event(
options, event, NULL, !options->on_crash_func);
sentry_session_t *session = sentry__end_current_session_with_status(
SENTRY_SESSION_STATUS_CRASHED);
sentry__envelope_add_session(envelope, session);

sentry_envelope_item_t *item = sentry__envelope_add_from_path(
envelope, dump_path, "attachment");
if (item) {
sentry__envelope_item_set_header(item, "attachment_type",
sentry_value_new_string("event.minidump"));

sentry__envelope_item_set_header(item, "filename",
#ifdef SENTRY_PLATFORM_WINDOWS
sentry__value_new_string_from_wstr(
#else
sentry_value_new_string(
#endif
sentry__path_filename(dump_path)));
}
sentry__capture_envelope(options->transport, envelope);
}
5 changes: 5 additions & 0 deletions src/sentry_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ sentry_options_t *sentry__options_lock(void);
*/
void sentry__options_unlock(void);

/**
*
*/
void sentry__capture_minidump(sentry_path_t *dump_path, sentry_value_t event, const sentry_options_t *options);

#define SENTRY_WITH_OPTIONS(Options) \
for (const sentry_options_t *Options = sentry__options_getref(); Options; \
sentry_options_free((sentry_options_t *)Options), Options = NULL)
Expand Down

0 comments on commit d6e922d

Please sign in to comment.