Skip to content

Commit b49b057

Browse files
committed
ref: crashpad: generate event ID on the client side (#1319)
1 parent eae1feb commit b49b057

File tree

7 files changed

+52
-4
lines changed

7 files changed

+52
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323

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

26+
**Internal:**
27+
28+
- 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))
29+
2630
## 0.9.1
2731

2832
**Features**:

src/backends/sentry_backend_crashpad.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ extern "C" {
1919
# include "sentry_unix_pageallocator.h"
2020
#endif
2121
#include "sentry_utils.h"
22+
#include "sentry_uuid.h"
2223
#include "transports/sentry_disk_transport.h"
2324
}
2425

@@ -117,6 +118,7 @@ typedef struct {
117118
size_t num_breadcrumbs;
118119
std::atomic<bool> crashed;
119120
std::atomic<bool> scope_flush;
121+
sentry_uuid_t crash_event_id;
120122
} crashpad_state_t;
121123

122124
/**
@@ -234,6 +236,8 @@ crashpad_backend_flush_scope(
234236
}
235237

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

283287
SENTRY_WITH_OPTIONS (options) {
284-
sentry_value_t crash_event = sentry_value_new_event();
288+
auto state = static_cast<crashpad_state_t *>(options->backend->data);
289+
sentry_value_t crash_event
290+
= sentry__value_new_event_with_id(&state->crash_event_id);
285291
sentry_value_set_by_key(
286292
crash_event, "level", sentry__value_new_level(SENTRY_LEVEL_FATAL));
287293

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

427+
// pre-generate event ID for a potential future crash to be able to
428+
// associate feedback with the crash event.
429+
data->crash_event_id = sentry__new_event_id();
430+
421431
base::FilePath database(options->database_path->path);
422432
base::FilePath handler(absolute_handler_path->path);
423433

src/sentry_value.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,12 +1128,11 @@ sentry__value_new_level(sentry_level_t level)
11281128
}
11291129

11301130
sentry_value_t
1131-
sentry_value_new_event(void)
1131+
sentry__value_new_event_with_id(const sentry_uuid_t *event_id)
11321132
{
11331133
sentry_value_t rv = sentry_value_new_object();
11341134

1135-
sentry_uuid_t uuid = sentry__new_event_id();
1136-
sentry_value_set_by_key(rv, "event_id", sentry__value_new_uuid(&uuid));
1135+
sentry_value_set_by_key(rv, "event_id", sentry__value_new_uuid(event_id));
11371136

11381137
sentry_value_set_by_key(rv, "timestamp",
11391138
sentry__value_new_string_owned(
@@ -1144,6 +1143,13 @@ sentry_value_new_event(void)
11441143
return rv;
11451144
}
11461145

1146+
sentry_value_t
1147+
sentry_value_new_event(void)
1148+
{
1149+
sentry_uuid_t event_id = sentry__new_event_id();
1150+
return sentry__value_new_event_with_id(&event_id);
1151+
}
1152+
11471153
sentry_value_t
11481154
sentry_value_new_message_event_n(sentry_level_t level, const char *logger,
11491155
size_t logger_len, const char *text, size_t text_len)

src/sentry_value.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ sentry_value_t sentry__value_new_internal_uuid(const sentry_uuid_t *uuid);
4545
*/
4646
sentry_value_t sentry__value_new_uuid(const sentry_uuid_t *uuid);
4747

48+
/**
49+
* Creates a new Event with the given `event_id`.
50+
*/
51+
sentry_value_t sentry__value_new_event_with_id(const sentry_uuid_t *event_id);
52+
4853
/**
4954
* Creates a new String Value from the given `level`.
5055
* This can be `debug`, `warning`, `error`, `fatal`, or `info`.

tests/assertions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ def assert_event_meta(
8585
transaction_data=None,
8686
sdk_override=None,
8787
):
88+
assert event["event_id"]
89+
8890
extra = {
8991
"extra stuff": "some value",
9092
"…unicode key…": "őá…–🤮🚀¿ 한글 테스트",

tests/unit/test_value.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,3 +863,23 @@ SENTRY_TEST(user_feedback_is_valid)
863863

864864
sentry_value_decref(user_feedback);
865865
}
866+
867+
SENTRY_TEST(event_with_id)
868+
{
869+
sentry_uuid_t event_id
870+
= sentry_uuid_from_string("ad59c6f8-eb88-4dca-b330-94dee9a46fe8");
871+
872+
sentry_value_t event = sentry__value_new_event_with_id(&event_id);
873+
874+
TEST_CHECK(!sentry_value_is_null(event));
875+
TEST_CHECK_STRING_EQUAL(
876+
sentry_value_as_string(sentry_value_get_by_key(event, "event_id")),
877+
"ad59c6f8-eb88-4dca-b330-94dee9a46fe8");
878+
TEST_CHECK(
879+
!sentry_value_is_null(sentry_value_get_by_key(event, "timestamp")));
880+
TEST_CHECK_STRING_EQUAL(
881+
sentry_value_as_string(sentry_value_get_by_key(event, "platform")),
882+
"native");
883+
884+
sentry_value_decref(event);
885+
}

tests/unit/tests.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ XX(dsn_with_non_http_scheme_is_invalid)
6262
XX(dsn_without_project_id_is_invalid)
6363
XX(dsn_without_url_scheme_is_invalid)
6464
XX(empty_transport)
65+
XX(event_with_id)
6566
XX(exception_without_type_or_value_still_valid)
6667
XX(fuzz_json)
6768
XX(init_failure)

0 commit comments

Comments
 (0)