Skip to content

Commit 835beac

Browse files
JoshuaMoelansantonpirker
authored andcommitted
feat(native): update before_send docs (#13984)
<!-- Use this checklist to make sure your PR is ready for merge. You may delete any sections you don't need. --> [Latest Vercel Preview](https://sentry-docs-git-joshua-nativebeforesenddocs.sentry.dev/platforms/native/configuration/filtering/#event-hints) ## DESCRIBE YOUR PR Fixes getsentry/sentry-native#1268 We fix some ancient docs which wrongly state that `before_send` uses the `hint` parameter in the Native SDK, by cleaning up the unnecessary 'Event Hints' section. We move the example snippet into the corresponding `before_send` and `on_crash` sections, better showcasing how to use the passed-in values. ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [x] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs)
1 parent 7ab2efc commit 835beac

File tree

3 files changed

+28
-59
lines changed

3 files changed

+28
-59
lines changed

docs/platforms/native/common/configuration/filtering.mdx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,6 @@ All Sentry SDKs support the <PlatformIdentifier name="before-send" /> callback m
2222

2323
Note also that breadcrumbs can be filtered, as discussed in [our Breadcrumbs documentation](/product/error-monitoring/breadcrumbs/).
2424

25-
#### Event Hints
26-
27-
The <PlatformIdentifier name="before-send" /> callback is passed both the `event` and a second argument, `hint`, that holds one or more hints.
28-
29-
Typically, a `hint` holds the original exception so that additional data can be extracted or grouping is affected. In this example, the fingerprint is forced to a common value if an exception of a certain type has been caught:
30-
31-
<PlatformContent includePath="configuration/before-send-hint" />
32-
33-
When the SDK creates an event or breadcrumb for transmission, that transmission is typically created from some sort of source object. For instance, an error event is typically created from a log record or exception instance. For better customization, SDKs send these objects to certain callbacks (<PlatformIdentifier name="before-send" />, <PlatformIdentifier name="before-breadcrumb" /> or the event processor system in the SDK).
34-
35-
3625
## Filtering Transaction Events
3726

3827
To prevent certain transactions from being reported to Sentry, use the <PlatformIdentifier name="traces-sampler" /> or <PlatformIdentifier name="before-send-transaction" /> configuration option, which allows you to provide a function to evaluate the current transaction and drop it if it's not one you want.

platform-includes/configuration/before-send-hint/native.mdx

Lines changed: 0 additions & 38 deletions
This file was deleted.

platform-includes/configuration/before-send/native.mdx

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
```c
22
#include <sentry.h>
33

4-
sentry_value_t strip_sensitive_data(sentry_value_t event, void *hint) {
5-
/* modify event here or return NULL to discard the event */
6-
return event;
4+
sentry_value_t strip_sensitive_data(sentry_value_t event, void *hint, void *user_data) {
5+
(void)hint; // unlike in other SDKs, `hint` currently contains no data.
6+
// to get more crash context into a callback, use the `on_crash` hook instead.
7+
8+
if (strcmp(sentry_value_as_string(sentry_value_get_by_key(event, "level")), "info") == 0) {
9+
// remove the user data from "info" level events
10+
sentry_value_remove_by_key(event, "user");
11+
// make our mark on the event
12+
sentry_value_t tags = sentry_value_get_by_key(event, "tags");
13+
if (!sentry_value_is_null(tags)) {
14+
sentry_value_set_by_key(tags, "info", sentry_value_new_string((char*) user_data));
15+
}
16+
}
17+
18+
// return the modified event, or discard it by freeing it and returning `null`
19+
// sentry_value_decref(event);
20+
// return sentry_value_new_null();
21+
return event;
722
}
823

924
int main(void) {
1025
sentry_options_t *options = sentry_options_new();
11-
sentry_options_set_before_send(options, strip_sensitive_data, NULL);
26+
sentry_options_set_before_send(options, strip_sensitive_data, "anonymized");
1227
sentry_init(options);
1328

1429
/* ... */
@@ -25,14 +40,17 @@ The `before_send` callback implementation in `sentry-native` makes it hard to di
2540
#include <sentry.h>
2641
2742
static sentry_value_t
28-
crash_cleanup(
43+
on_crash_callback(
2944
const sentry_ucontext_t *uctx, // provides the user-space context of the crash
30-
sentry_value_t event, // used the same way as in `before_send`
31-
void *closure // user-data that you can provide at configuration time
45+
sentry_value_t event, // used the same way as in `before_send`; mostly empty for minidump-generating backends (crashpad, breakpad)
46+
void *user_data // user-data that you can provide at configuration time
3247
)
3348
{
34-
// Do contextual clean-up before the crash is sent to sentry's backend infrastructure
35-
49+
// Enrich an event before the crash is sent to sentry's backend infrastructure
50+
sentry_value_t tags = sentry_value_get_by_key(event, "tags");
51+
if (!sentry_value_is_null(tags)) {
52+
sentry_value_set_by_key(tags, "crash_hook", sentry_value_new_string("invoked"));
53+
}
3654
/* ... */
3755
3856
// tell the backend to retain the event (+ dump)
@@ -44,7 +62,7 @@ crash_cleanup(
4462
4563
int main(void) {
4664
sentry_options_t *options = sentry_options_new();
47-
sentry_options_set_on_crash(options, crash_cleanup, NULL);
65+
sentry_options_set_on_crash(options, on_crash_callback, NULL);
4866
sentry_init(options);
4967
5068
/* ... */

0 commit comments

Comments
 (0)