Skip to content
Open
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

- Attachment APIs now use `sentry_value_t` and `sentry_uuid_t` instead of `sentry_attachment_t *` handles. Most attachment APIs, function names and arguments, are otherwise unchanged. ([#1974](https://github.com/getsentry/sentry-native/pull/1974))
- `sentry_init()` now consumes `<db>/last_crash` after caching its value, aligning crashed-last-run behavior with other Sentry SDKs. ([#2023](https://github.com/getsentry/sentry-native/pull/2023))
- Change the `hint` parameter of `before_send` callbacks (`sentry_event_function_t`) from `void *` to `sentry_hint_t *`. Update callbacks registered with `sentry_options_set_before_send` to use the new parameter type. ([#2099](https://github.com/getsentry/sentry-native/pull/2099))
- Add a `sentry_hint_t *hint` argument to `on_crash` callbacks. ([#2112](https://github.com/getsentry/sentry-native/pull/2112))
- Add a `sentry_hint_t *hint` argument to `sentry_scope_capture_event`. Pass `NULL` if no hint is needed. ([#2099](https://github.com/getsentry/sentry-native/pull/2099))
- Remove `sentry_options_get/set_enable_logs` and `sentry_options_get/set_enable_metrics`. ([#1980](https://github.com/getsentry/sentry-native/pull/1980))
> Structured logs and metrics have been enabled by default since `0.13`, and the options were deprecated and made no-ops in `0.16`.
>
Expand All @@ -16,10 +19,13 @@
- Add `sentry_attachment_from_file/bytes` (and their wide-string variants) for creating attachment values that can be fully configured before they are added. ([#2079](https://github.com/getsentry/sentry-native/pull/2079))
- Add `sentry_add_attachment`, `sentry_scope_add_attachment`, and `sentry_hint_add_attachment` for adding configured attachments to the global scope, a specific scope, or a hint. These functions consume and freeze the attachment value. ([#2079](https://github.com/getsentry/sentry-native/pull/2079), [#1974](https://github.com/getsentry/sentry-native/pull/1974))
- Add `sentry_start_new_trace()` as a clearer name for starting a new trace. ([#2095](https://github.com/getsentry/sentry-native/pull/2095))
- Add hint support to `sentry_scope_capture_event` to pass event-specific attachments. The hint is also passed to `before_send` and `on_crash`, which can modify attachments before the event is sent. ([#2099](https://github.com/getsentry/sentry-native/pull/2099), [#2112](https://github.com/getsentry/sentry-native/pull/2112))
- Add `sentry_hint_remove_attachment` and `sentry_hint_clear_attachments`. ([#2099](https://github.com/getsentry/sentry-native/pull/2099))

**Fixes**:

- Reduce lock contention for multi-threaded log and metric capture by allowing concurrent reads of scope data, and reusing a single options reference throughout each capture. ([#2091](https://github.com/getsentry/sentry-native/pull/2091), [#2094](https://github.com/getsentry/sentry-native/pull/2094))
- Apply scope data before invoking `on_crash` while preserving scope changes made by the callback. ([#2119](https://github.com/getsentry/sentry-native/pull/2119))

**Other changes**:

Expand Down
36 changes: 26 additions & 10 deletions examples/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,15 @@ traces_sampler_callback(const sentry_transaction_context_t *transaction_ctx,
}

static sentry_value_t
before_send_callback(sentry_value_t event, void *hint, void *user_data)
before_send_callback(sentry_value_t event, sentry_hint_t *hint, void *user_data)
{
(void)hint;
(void)user_data;

sentry_hint_clear_attachments(hint);
sentry_hint_add_attachment(hint,
sentry_attachment_from_bytes(
"before_send", strlen("before_send"), "callback.txt"));

// make our mark on the event
sentry_value_set_by_key(
event, "adapted_by", sentry_value_new_string("before_send"));
Expand All @@ -142,7 +146,7 @@ before_send_callback(sentry_value_t event, void *hint, void *user_data)

static sentry_value_t
discarding_before_send_callback(
sentry_value_t event, void *hint, void *user_data)
sentry_value_t event, sentry_hint_t *hint, void *user_data)
{
(void)hint;
(void)user_data;
Expand All @@ -153,10 +157,11 @@ discarding_before_send_callback(
}

static sentry_value_t
discarding_on_crash_callback(
const sentry_ucontext_t *uctx, sentry_value_t event, void *user_data)
discarding_on_crash_callback(const sentry_ucontext_t *uctx,
sentry_value_t event, sentry_hint_t *hint, void *user_data)
{
(void)uctx;
(void)hint;
(void)user_data;

// discard event and signal backend to stop further processing
Expand All @@ -165,12 +170,22 @@ discarding_on_crash_callback(
}

static sentry_value_t
on_crash_callback(
const sentry_ucontext_t *uctx, sentry_value_t event, void *user_data)
on_crash_callback(const sentry_ucontext_t *uctx, sentry_value_t event,
sentry_hint_t *hint, void *user_data)
{
(void)uctx;
(void)user_data;

sentry_hint_clear_attachments(hint);
sentry_hint_add_attachment(hint,
sentry_attachment_from_bytes(
"on_crash", strlen("on_crash"), "callback.txt"));

sentry_value_t tags = sentry_value_get_by_key(event, "tags");
sentry_value_set_by_key(event, "on_crash_scope_tag",
sentry_value_incref(sentry_value_get_by_key(tags, "expected-tag")));
sentry_set_tag("test.on-crash", "added-by-on-crash");

// tell the backend to retain the event
return event;
}
Expand Down Expand Up @@ -230,10 +245,11 @@ on_crashed_last_run_callback(const sentry_envelope_t *envelope, void *user_data)
}

static sentry_value_t
restart_on_crash(
const sentry_ucontext_t *uctx, sentry_value_t event, void *user_data)
restart_on_crash(const sentry_ucontext_t *uctx, sentry_value_t event,
sentry_hint_t *hint, void *user_data)
{
(void)uctx;
(void)hint;

#ifdef SENTRY_PLATFORM_WINDOWS
wchar_t **argv = user_data;
Expand Down Expand Up @@ -1247,7 +1263,7 @@ main(int argc, char **argv)
sentry_scope_add_attachment(scope, bytes);
}

sentry_scope_capture_event(scope, event);
sentry_scope_capture_event(scope, event, NULL);
}

if (has_arg(argc, argv, "capture-multiple")) {
Expand Down
56 changes: 39 additions & 17 deletions include/sentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,13 @@ SENTRY_API void sentry_options_set_send_default_pii(
sentry_options_t *opts, int value);
#endif

/**
* A hint that can be passed to capture functions to provide additional context,
* such as attachments.
*/
struct sentry_hint_s;
typedef struct sentry_hint_s sentry_hint_t;

/**
* Type of the `before_send` callback.
*
Expand All @@ -1486,6 +1493,9 @@ SENTRY_API void sentry_options_set_send_default_pii(
* call `sentry_value_decref` on the provided event and return a
* `sentry_value_new_null()` instead.
*
* The hint is always provided and can be used to modify attachments on the
* event.
*
* If you have set an `on_crash` callback (independent of whether it discards or
* retains the event), `before_send` will no longer be invoked for crash-events,
* which allows you to better distinguish between crashes and all other events
Expand All @@ -1510,7 +1520,7 @@ SENTRY_API void sentry_options_set_send_default_pii(
* though a crash report will be sent.
*/
typedef sentry_value_t (*sentry_event_function_t)(
sentry_value_t event, void *hint, void *user_data);
sentry_value_t event, sentry_hint_t *hint, void *user_data);

/**
* Sets the `before_send` callback.
Expand All @@ -1530,9 +1540,15 @@ SENTRY_API void sentry_options_set_before_send(
* `sentry_value_decref` on the provided event and return a
* `sentry_value_new_null()` instead.
*
* The hint is always provided and can be used to modify attachments on the
* event.
*
* The current scope is applied before invoking the callback. Scope changes made
* from inside the callback are also applied to the returned event.
*
* Only the `inproc` backend currently fills the passed-in event with crash
* meta-data. Since both `breakpad` and `crashpad` use minidumps to capture the
* crash state, the passed-in event is empty when using these backends. Changes
* crash state, their events contain scope data but no crash meta-data. Changes
* to the event from inside the hooks will be passed along, but in the case of
* the minidump backends these changes might get overwritten during server-side
* ingestion and processing. This primarily affects the exception payloads which
Expand Down Expand Up @@ -1570,8 +1586,8 @@ SENTRY_API void sentry_options_set_before_send(
* exception-handler, it will not be invoked when such a crash happened, even
* though a crash report will be sent.
*/
typedef sentry_value_t (*sentry_crash_function_t)(
const sentry_ucontext_t *uctx, sentry_value_t event, void *user_data);
typedef sentry_value_t (*sentry_crash_function_t)(const sentry_ucontext_t *uctx,
sentry_value_t event, sentry_hint_t *hint, void *user_data);

/**
* Sets the `on_crash` callback.
Expand Down Expand Up @@ -2592,15 +2608,18 @@ SENTRY_API sentry_uuid_t sentry_scope_get_last_event_id(
SENTRY_API sentry_uuid_t sentry_capture_event(sentry_value_t event);

/**
* Sends a sentry event with a scope.
* Sends a sentry event with a scope and a hint.
*
* This function takes ownership of the event and hint, which will be freed
* automatically. The hint may be NULL.
*
* If `scope` is a local scope (`sentry_local_scope_new`), this takes ownership
* of it and frees it. If `scope` is user-owned (`sentry_scope_new` or
* `sentry_scope_clone`), it is applied but not freed, so it can be reused; free
* it yourself with `sentry_scope_free`.
*/
SENTRY_API sentry_uuid_t sentry_scope_capture_event(
sentry_scope_t *scope, sentry_value_t event);
sentry_scope_t *scope, sentry_value_t event, sentry_hint_t *hint);

/**
* Deprecated alias for `sentry_scope_capture_event`. Note the reversed argument
Expand Down Expand Up @@ -4139,16 +4158,7 @@ SENTRY_API sentry_value_t sentry_value_new_feedback_n(const char *message,
SENTRY_API void sentry_capture_feedback(sentry_value_t user_feedback);

/**
* A hint that can be passed to capture functions to provide additional context,
* such as attachments.
*/
struct sentry_hint_s;
typedef struct sentry_hint_s sentry_hint_t;

/**
* Creates a new hint to be passed into
* - `sentry_capture_feedback_with_hint`
* - `sentry_scope_capture_feedback`
* Creates a new hint to be passed into capture functions.
*/
SENTRY_API sentry_hint_t *sentry_hint_new(void);

Expand Down Expand Up @@ -4202,6 +4212,17 @@ SENTRY_API sentry_uuid_t sentry_hint_attach_bytesw_n(sentry_hint_t *hint,
size_t filename_len);
#endif

/**
* Removes an attachment from the hint by its ID. Does not modify scopes.
*/
SENTRY_API void sentry_hint_remove_attachment(
sentry_hint_t *hint, sentry_uuid_t attachment_id);

/**
* Removes all attachments from the hint. Does not modify scopes.
*/
SENTRY_API void sentry_hint_clear_attachments(sentry_hint_t *hint);

/**
* Captures a manually created feedback with a hint and sends it to Sentry.
*
Expand Down Expand Up @@ -4237,7 +4258,8 @@ SENTRY_API sentry_uuid_t sentry_scope_capture_feedback(
* callback needs to call `sentry_value_decref` on the provided event and
* return a `sentry_value_new_null()` instead.
*
* The hint is always provided and can be used to add attachments to the event.
* The hint is always provided and can be used to modify attachments on the
* event.
*
* Feedback events do not go through the `before_send` callback.
*/
Expand Down
Loading
Loading