Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -23,6 +23,10 @@

- Marked deprecated functions with `SENTRY_DEPRECATED(msg)`. ([#1308](https://github.com/getsentry/sentry-native/pull/1308))

**Internal:**

- Crash events from Crashpad now have `event_id` defined similarly to other backends. This makes it possible to associate feedback at the time of crash. ([#1319](https://github.com/getsentry/sentry-native/pull/1319))

## 0.9.1

**Features**:
Expand Down
12 changes: 11 additions & 1 deletion src/backends/sentry_backend_crashpad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ extern "C" {
# include "sentry_unix_pageallocator.h"
#endif
#include "sentry_utils.h"
#include "sentry_uuid.h"
#include "transports/sentry_disk_transport.h"
}

Expand Down Expand Up @@ -117,6 +118,7 @@ typedef struct {
size_t num_breadcrumbs;
std::atomic<bool> crashed;
std::atomic<bool> scope_flush;
sentry_uuid_t crash_event_id;
} crashpad_state_t;

/**
Expand Down Expand Up @@ -234,6 +236,8 @@ crashpad_backend_flush_scope(
}

sentry_value_t event = sentry_value_new_object();
sentry_value_set_by_key(
event, "event_id", sentry__value_new_uuid(&data->crash_event_id));
// Since this will only be uploaded in case of a crash we must make this
// event fatal.
sentry_value_set_by_key(
Expand Down Expand Up @@ -281,7 +285,9 @@ sentry__crashpad_handler(int signum, siginfo_t *info, ucontext_t *user_context)
bool should_dump = true;

SENTRY_WITH_OPTIONS (options) {
sentry_value_t crash_event = sentry_value_new_event();
auto state = static_cast<crashpad_state_t *>(options->backend->data);
sentry_value_t crash_event
= sentry__value_new_event_with_id(&state->crash_event_id);
sentry_value_set_by_key(
crash_event, "level", sentry__value_new_level(SENTRY_LEVEL_FATAL));

Expand Down Expand Up @@ -418,6 +424,10 @@ crashpad_backend_startup(
sentry_path_t *current_run_folder = options->run->run_path;
auto *data = static_cast<crashpad_state_t *>(backend->data);

// pre-generate event ID for a potential future crash to be able to
// associate feedback with the crash event.
data->crash_event_id = sentry__new_event_id();

base::FilePath database(options->database_path->path);
base::FilePath handler(absolute_handler_path->path);

Expand Down
12 changes: 9 additions & 3 deletions src/sentry_value.c
Original file line number Diff line number Diff line change
Expand Up @@ -1128,12 +1128,11 @@ sentry__value_new_level(sentry_level_t level)
}

sentry_value_t
sentry_value_new_event(void)
sentry__value_new_event_with_id(const sentry_uuid_t *event_id)
{
sentry_value_t rv = sentry_value_new_object();

sentry_uuid_t uuid = sentry__new_event_id();
sentry_value_set_by_key(rv, "event_id", sentry__value_new_uuid(&uuid));
sentry_value_set_by_key(rv, "event_id", sentry__value_new_uuid(event_id));

sentry_value_set_by_key(rv, "timestamp",
sentry__value_new_string_owned(
Expand All @@ -1144,6 +1143,13 @@ sentry_value_new_event(void)
return rv;
}

sentry_value_t
sentry_value_new_event(void)
{
sentry_uuid_t event_id = sentry__new_event_id();
return sentry__value_new_event_with_id(&event_id);
}

sentry_value_t
sentry_value_new_message_event_n(sentry_level_t level, const char *logger,
size_t logger_len, const char *text, size_t text_len)
Expand Down
6 changes: 6 additions & 0 deletions src/sentry_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ sentry_value_t sentry__value_new_internal_uuid(const sentry_uuid_t *uuid);
*/
sentry_value_t sentry__value_new_uuid(const sentry_uuid_t *uuid);

/**
* Creates a new Event with the given `event_id`.
* Used by Crashpad to allow associating feedback with the crash event.
*/
sentry_value_t sentry__value_new_event_with_id(const sentry_uuid_t *event_id);

/**
* Creates a new String Value from the given `level`.
* This can be `debug`, `warning`, `error`, `fatal`, or `info`.
Expand Down
2 changes: 2 additions & 0 deletions tests/assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ def assert_event_meta(
transaction_data=None,
sdk_override=None,
):
assert event["event_id"]

extra = {
"extra stuff": "some value",
"…unicode key…": "őá…–🤮🚀¿ 한글 테스트",
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/test_value.c
Original file line number Diff line number Diff line change
Expand Up @@ -863,3 +863,23 @@ SENTRY_TEST(user_feedback_is_valid)

sentry_value_decref(user_feedback);
}

SENTRY_TEST(event_with_id)
{
sentry_uuid_t event_id
= sentry_uuid_from_string("ad59c6f8-eb88-4dca-b330-94dee9a46fe8");

sentry_value_t event = sentry__value_new_event_with_id(&event_id);

TEST_CHECK(!sentry_value_is_null(event));
TEST_CHECK_STRING_EQUAL(
sentry_value_as_string(sentry_value_get_by_key(event, "event_id")),
"ad59c6f8-eb88-4dca-b330-94dee9a46fe8");
TEST_CHECK(
!sentry_value_is_null(sentry_value_get_by_key(event, "timestamp")));
TEST_CHECK_STRING_EQUAL(
sentry_value_as_string(sentry_value_get_by_key(event, "platform")),
"native");

sentry_value_decref(event);
}
1 change: 1 addition & 0 deletions tests/unit/tests.inc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ XX(dsn_with_non_http_scheme_is_invalid)
XX(dsn_without_project_id_is_invalid)
XX(dsn_without_url_scheme_is_invalid)
XX(empty_transport)
XX(event_with_id)
XX(exception_without_type_or_value_still_valid)
XX(fuzz_json)
XX(init_failure)
Expand Down
Loading