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: programatic minidump capture #1052

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

**Features**:

- Add ability to capture independently created minidumps ([#1052](https://github.com/getsentry/sentry-native/pull/1052))

**Fixes**:

- Reject invalid trace- and span-ids in context update from header ([#1046](https://github.com/getsentry/sentry-native/pull/1046))
Expand Down
6 changes: 6 additions & 0 deletions include/sentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,12 @@ SENTRY_API sentry_user_consent_t sentry_user_consent_get(void);
*/
SENTRY_API sentry_uuid_t sentry_capture_event(sentry_value_t event);

/**
* This function allows for independently created minidumps to be captured.
PlasmaDev5 marked this conversation as resolved.
Show resolved Hide resolved
*/
SENTRY_API void sentry_capture_minidump(
const char *dump_path, sentry_value_t event, int remove_dump_on_send);

/**
* Captures an exception to be handled by the backend.
*
Expand Down
2 changes: 1 addition & 1 deletion src/backends/sentry_backend_breakpad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ sentry__breakpad_backend_callback(
sentry_value_set_by_key(
event, "level", sentry__value_new_level(SENTRY_LEVEL_FATAL));

SENTRY_WITH_OPTIONS (options) {
SENTRY_WITH_OPTIONS (options) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: unnecessary whitespace.

sentry__write_crash_marker(options);

bool should_handle = true;
Expand Down
64 changes: 64 additions & 0 deletions src/sentry_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1169,3 +1169,67 @@ sentry_clear_crashed_last_run(void)
sentry__options_unlock();
return success ? 0 : 1;
}

void
sentry_capture_minidump(
const char *dump_path, sentry_value_t event, int remove_dump_on_send)
{
sentry_path_t *sentry_dump_path
= sentry__path_from_str_n(dump_path, strlen(dump_path));
supervacuus marked this conversation as resolved.
Show resolved Hide resolved

if (sentry_dump_path == NULL) {
SENTRY_WARN(
"'sentry_capture_minidump' Failed due to null path to minidump");
return;
}

SENTRY_WITH_OPTIONS (options) {
sentry__ensure_event_id(event, NULL);
sentry_envelope_t *envelope = sentry__envelope_new();
if (!envelope || !sentry__envelope_add_event(envelope, event)) {
sentry_envelope_free(envelope);
sentry_value_decref(event);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block must return and free the dump path.


SENTRY_TRACE("adding attachments to envelope");
for (sentry_attachment_t *attachment = options->attachments; attachment;
attachment = attachment->next) {
sentry_envelope_item_t *item = sentry__envelope_add_from_path(
envelope, attachment->path, "attachment");
if (!item) {
continue;
}
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(attachment->path)));
}
PlasmaDev5 marked this conversation as resolved.
Show resolved Hide resolved

sentry_envelope_item_t *item = sentry__envelope_add_from_path(
envelope, sentry_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(sentry_dump_path)));
}

sentry__capture_envelope(options->transport, envelope);

bool remove_dump_on_send_bool = remove_dump_on_send;
if (remove_dump_on_send_bool) {
PlasmaDev5 marked this conversation as resolved.
Show resolved Hide resolved
sentry__path_remove(sentry_dump_path);
}

sentry__path_free(sentry_dump_path);
}
}
Loading