From 0043edf8d97459635da36a2aad1a779d1f704521 Mon Sep 17 00:00:00 2001 From: Mischan Toosarani-Hausberger Date: Thu, 15 Feb 2024 09:48:46 +0100 Subject: [PATCH] docs: provide example for breadcrumb data property (#951) --- CHANGELOG.md | 4 ++++ examples/example.c | 19 +++++++++++++++++++ tests/assertions.py | 6 ++++++ 3 files changed, 29 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b785c79d..50bed07b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ - Remove the `CRASHPAD_WER_ENABLED` build flag. The WER module is now built for all supported Windows targets, and registration is conditional on runtime Windows version checks. ([#950](https://github.com/getsentry/sentry-native/pull/950), [crashpad#96](https://github.com/getsentry/crashpad/pull/96)) +**Docs**: + +- Add usage of the breadcrumb `data` property to the example. [#951](https://github.com/getsentry/sentry-native/pull/951) + ## 0.7.0 **Breaking changes**: diff --git a/examples/example.c b/examples/example.c index 28f535504..6abe54eae 100644 --- a/examples/example.c +++ b/examples/example.c @@ -9,17 +9,21 @@ #include #include #include + #ifdef NDEBUG # undef NDEBUG #endif + #include #ifdef SENTRY_PLATFORM_WINDOWS # include # define sleep_s(SECONDS) Sleep((SECONDS)*1000) #else + # include # include + # define sleep_s(SECONDS) sleep(SECONDS) #endif @@ -260,6 +264,21 @@ main(int argc, char **argv) debug_crumb, "category", sentry_value_new_string("example!")); sentry_value_set_by_key( debug_crumb, "level", sentry_value_new_string("debug")); + + // extend the `http` crumb with (optional) data properties as documented + // here: + // https://develop.sentry.dev/sdk/event-payloads/breadcrumbs/#breadcrumb-types + sentry_value_t http_data = sentry_value_new_object(); + sentry_value_set_by_key(http_data, "url", + sentry_value_new_string("https://example.com/api/1.0/users")); + sentry_value_set_by_key( + http_data, "method", sentry_value_new_string("GET")); + sentry_value_set_by_key( + http_data, "status_code", sentry_value_new_int32(200)); + sentry_value_set_by_key( + http_data, "reason", sentry_value_new_string("OK")); + sentry_value_set_by_key(debug_crumb, "data", http_data); + sentry_add_breadcrumb(debug_crumb); sentry_value_t nl_crumb diff --git a/tests/assertions.py b/tests/assertions.py index f12ec9972..63b126ded 100644 --- a/tests/assertions.py +++ b/tests/assertions.py @@ -142,6 +142,12 @@ def assert_breadcrumb(envelope): "message": "debug crumb", "category": "example!", "level": "debug", + "data": { + "url": "https://example.com/api/1.0/users", + "method": "GET", + "status_code": 200, + "reason": "OK", + }, } assert any(matches(b, expected) for b in event["breadcrumbs"])