Skip to content

Commit

Permalink
docs: provide example for breadcrumb data property (#951)
Browse files Browse the repository at this point in the history
  • Loading branch information
supervacuus authored Feb 15, 2024
1 parent 5596cbb commit 0043edf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**:
Expand Down
19 changes: 19 additions & 0 deletions examples/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef NDEBUG
# undef NDEBUG
#endif

#include <assert.h>

#ifdef SENTRY_PLATFORM_WINDOWS
# include <synchapi.h>
# define sleep_s(SECONDS) Sleep((SECONDS)*1000)
#else

# include <signal.h>
# include <unistd.h>

# define sleep_s(SECONDS) sleep(SECONDS)
#endif

Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tests/assertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand Down

0 comments on commit 0043edf

Please sign in to comment.