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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Add `sentry_set_tags` and `sentry_scope_set_tags` for updating multiple tags with a single scope flush, improving bulk-update performance. ([#1993](https://github.com/getsentry/sentry-native/pull/1993))
- Add `sentry_get_last_event_id` and `sentry_scope_get_last_event_id` for retrieving the last event ID captured with the global or given scope, respectively. ([#1992](https://github.com/getsentry/sentry-native/pull/1992))
- Native/Unix: The native crash daemon now loads `libcurl` dynamically at runtime by default when `SENTRY_LINK_CURL=AUTO`, avoiding `libcurl` linker work during process startup and significantly speeding up startup time. Explicitly set `SENTRY_LINK_CURL=ON` to link it directly. ([#1955](https://github.com/getsentry/sentry-native/pull/1955))
- Add missing public scope mutators: `set_release`, `set_environment`, `set_transaction`, `remove_tag`, `remove_extra`, `remove_context`, and `remove_attachment`. ([#2011](https://github.com/getsentry/sentry-native/pull/2011))

**Deprecations**:

Expand Down
31 changes: 29 additions & 2 deletions include/sentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -2540,6 +2540,10 @@ SENTRY_API void sentry_remove_user(void);
*/
SENTRY_API void sentry_set_release(const char *release);
SENTRY_API void sentry_set_release_n(const char *release, size_t release_len);
SENTRY_API void sentry_scope_set_release(
sentry_scope_t *scope, const char *release);
SENTRY_API void sentry_scope_set_release_n(
sentry_scope_t *scope, const char *release, size_t release_len);

/**
* Sets the environment after the SDK has been initialized. To apply the new
Expand All @@ -2548,6 +2552,10 @@ SENTRY_API void sentry_set_release_n(const char *release, size_t release_len);
SENTRY_API void sentry_set_environment(const char *environment);
SENTRY_API void sentry_set_environment_n(
const char *environment, size_t environment_len);
SENTRY_API void sentry_scope_set_environment(
sentry_scope_t *scope, const char *environment);
SENTRY_API void sentry_scope_set_environment_n(
sentry_scope_t *scope, const char *environment, size_t environment_len);

/**
* Sets a tag.
Expand Down Expand Up @@ -2575,6 +2583,9 @@ SENTRY_API void sentry_scope_set_tags(
*/
SENTRY_API void sentry_remove_tag(const char *key);
SENTRY_API void sentry_remove_tag_n(const char *key, size_t key_len);
SENTRY_API void sentry_scope_remove_tag(sentry_scope_t *scope, const char *key);
SENTRY_API void sentry_scope_remove_tag_n(
sentry_scope_t *scope, const char *key, size_t key_len);

/**
* Sets extra information.
Expand All @@ -2592,6 +2603,10 @@ SENTRY_API void sentry_scope_set_extra_n(sentry_scope_t *scope, const char *key,
*/
SENTRY_API void sentry_remove_extra(const char *key);
SENTRY_API void sentry_remove_extra_n(const char *key, size_t key_len);
SENTRY_API void sentry_scope_remove_extra(
sentry_scope_t *scope, const char *key);
SENTRY_API void sentry_scope_remove_extra_n(
sentry_scope_t *scope, const char *key, size_t key_len);

/**
* Sets attributes created with `sentry_value_new_attribute` to be applied to
Expand Down Expand Up @@ -2649,6 +2664,10 @@ SENTRY_API void sentry_scope_update_context_n(sentry_scope_t *scope,
*/
SENTRY_API void sentry_remove_context(const char *key);
SENTRY_API void sentry_remove_context_n(const char *key, size_t key_len);
SENTRY_API void sentry_scope_remove_context(
sentry_scope_t *scope, const char *key);
SENTRY_API void sentry_scope_remove_context_n(
sentry_scope_t *scope, const char *key, size_t key_len);

/**
* Sets the event fingerprint.
Expand Down Expand Up @@ -2712,6 +2731,10 @@ SENTRY_EXPERIMENTAL_API void sentry_regenerate_trace(void);
SENTRY_API void sentry_set_transaction(const char *transaction);
SENTRY_API void sentry_set_transaction_n(
const char *transaction, size_t transaction_len);
SENTRY_API void sentry_scope_set_transaction(
sentry_scope_t *scope, const char *transaction);
SENTRY_API void sentry_scope_set_transaction_n(
sentry_scope_t *scope, const char *transaction, size_t transaction_len);

/**
* Sets the event level.
Expand Down Expand Up @@ -3242,7 +3265,8 @@ typedef struct sentry_attachment_s sentry_attachment_t;
*
* The returned `sentry_attachment_t` is owned by the SDK and will remain valid
* until the attachment is removed with `sentry_remove_attachment` or
* `sentry_close` is called.
* `sentry_scope_remove_attachment`, or its owning scope is freed with
* `sentry_scope_free` or `sentry_close`.
*
* See the NOTE on attachments above for restrictions of this API.
*/
Expand Down Expand Up @@ -3274,7 +3298,8 @@ SENTRY_API sentry_attachment_t *sentry_scope_attach_file_n(
*
* The returned `sentry_attachment_t` is owned by the SDK and will remain valid
* until the attachment is removed with `sentry_remove_attachment` or
* `sentry_close` is called.
* `sentry_scope_remove_attachment`, or its owning scope is freed with
* `sentry_scope_free` or `sentry_close`.
*
* See the NOTE on attachments above for restrictions of this API.
*/
Expand All @@ -3299,6 +3324,8 @@ SENTRY_API void sentry_clear_attachments(void);
* See the NOTE on attachments above for restrictions of this API.
*/
SENTRY_API void sentry_remove_attachment(sentry_attachment_t *attachment);
SENTRY_API void sentry_scope_remove_attachment(
sentry_scope_t *scope, sentry_attachment_t *attachment);

#ifdef SENTRY_PLATFORM_WINDOWS
/**
Expand Down
56 changes: 9 additions & 47 deletions src/sentry_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -983,11 +983,7 @@ void
sentry_set_release_n(const char *release, size_t release_len)
{
SENTRY_WITH_SCOPE_MUT (scope) {
sentry_free(scope->release);
scope->release = sentry__string_clone_n(release, release_len);
sentry_value_set_by_key(scope->dynamic_sampling_context, "release",
sentry_value_new_string(scope->release));
SENTRY_SCOPE_NOTIFY(scope, set_release, scope->release);
sentry_scope_set_release_n(scope, release, release_len);
}
}

Expand All @@ -1001,12 +997,7 @@ void
sentry_set_environment_n(const char *environment, size_t environment_len)
{
SENTRY_WITH_SCOPE_MUT (scope) {
sentry_free(scope->environment);
scope->environment
= sentry__string_clone_n(environment, environment_len);
sentry_value_set_by_key(scope->dynamic_sampling_context, "environment",
sentry_value_new_string(scope->environment));
SENTRY_SCOPE_NOTIFY(scope, set_environment, scope->environment);
sentry_scope_set_environment_n(scope, environment, environment_len);
}
}

Expand Down Expand Up @@ -1086,22 +1077,15 @@ void
sentry_remove_tag(const char *key)
{
SENTRY_WITH_SCOPE_MUT (scope) {
if (sentry_value_remove_by_key(scope->tags, key) == 0) {
SENTRY_SCOPE_NOTIFY(scope, remove_tag, key);
}
sentry_scope_remove_tag(scope, key);
}
}

void
sentry_remove_tag_n(const char *key, size_t key_len)
{
SENTRY_WITH_SCOPE_MUT (scope) {
char *k
= sentry__value_remove_and_take_key_n(scope->tags, key, key_len);
if (k) {
SENTRY_SCOPE_NOTIFY(scope, remove_tag, k);
}
sentry_free(k);
sentry_scope_remove_tag_n(scope, key, key_len);
}
}

Expand All @@ -1125,22 +1109,15 @@ void
sentry_remove_extra(const char *key)
{
SENTRY_WITH_SCOPE_MUT (scope) {
if (sentry_value_remove_by_key(scope->extra, key) == 0) {
SENTRY_SCOPE_NOTIFY(scope, remove_extra, key);
}
sentry_scope_remove_extra(scope, key);
}
}

void
sentry_remove_extra_n(const char *key, size_t key_len)
{
SENTRY_WITH_SCOPE_MUT (scope) {
char *k
= sentry__value_remove_and_take_key_n(scope->extra, key, key_len);
if (k) {
SENTRY_SCOPE_NOTIFY(scope, remove_extra, k);
}
sentry_free(k);
sentry_scope_remove_extra_n(scope, key, key_len);
}
}

Expand Down Expand Up @@ -1241,22 +1218,15 @@ void
sentry_remove_context(const char *key)
{
SENTRY_WITH_SCOPE_MUT (scope) {
if (sentry_value_remove_by_key(scope->contexts, key) == 0) {
SENTRY_SCOPE_NOTIFY(scope, remove_context, key);
}
sentry_scope_remove_context(scope, key);
}
}

void
sentry_remove_context_n(const char *key, size_t key_len)
{
SENTRY_WITH_SCOPE_MUT (scope) {
char *k = sentry__value_remove_and_take_key_n(
scope->contexts, key, key_len);
if (k) {
SENTRY_SCOPE_NOTIFY(scope, remove_context, k);
}
sentry_free(k);
sentry_scope_remove_context_n(scope, key, key_len);
}
}

Expand Down Expand Up @@ -1360,15 +1330,7 @@ void
sentry_set_transaction_n(const char *transaction, size_t transaction_len)
{
SENTRY_WITH_SCOPE_MUT (scope) {
sentry_free(scope->transaction);
scope->transaction
= sentry__string_clone_n(transaction, transaction_len);

if (scope->transaction_object) {
sentry_transaction_set_name_n(
scope->transaction_object, transaction, transaction_len);
}
SENTRY_SCOPE_NOTIFY(scope, set_transaction, scope->transaction);
sentry_scope_set_transaction_n(scope, transaction, transaction_len);
}
}

Expand Down
125 changes: 125 additions & 0 deletions src/sentry_scope.c
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,25 @@ sentry_scope_set_tags(sentry_scope_t *scope, sentry_value_t tags)
sentry_value_decref(tags);
}

void
sentry_scope_remove_tag(sentry_scope_t *scope, const char *key)
{
if (sentry_value_remove_by_key(scope->tags, key) == 0) {
SENTRY_SCOPE_NOTIFY(scope, remove_tag, key);
}
}

void
sentry_scope_remove_tag_n(
sentry_scope_t *scope, const char *key, size_t key_len)
{
char *k = sentry__value_remove_and_take_key_n(scope->tags, key, key_len);
if (k) {
SENTRY_SCOPE_NOTIFY(scope, remove_tag, k);
}
sentry_free(k);
}

void
sentry_scope_set_extra(
sentry_scope_t *scope, const char *key, sentry_value_t value)
Expand All @@ -825,6 +844,25 @@ sentry_scope_set_extra_n(sentry_scope_t *scope, const char *key, size_t key_len,
}
}

void
sentry_scope_remove_extra(sentry_scope_t *scope, const char *key)
{
if (sentry_value_remove_by_key(scope->extra, key) == 0) {
SENTRY_SCOPE_NOTIFY(scope, remove_extra, key);
}
}

void
sentry_scope_remove_extra_n(
sentry_scope_t *scope, const char *key, size_t key_len)
{
char *k = sentry__value_remove_and_take_key_n(scope->extra, key, key_len);
if (k) {
SENTRY_SCOPE_NOTIFY(scope, remove_extra, k);
}
sentry_free(k);
}

void
sentry_scope_set_attribute(
sentry_scope_t *scope, const char *key, sentry_value_t attribute)
Expand Down Expand Up @@ -879,6 +917,26 @@ sentry_scope_set_context_n(sentry_scope_t *scope, const char *key,
}
}

void
sentry_scope_remove_context(sentry_scope_t *scope, const char *key)
{
if (sentry_value_remove_by_key(scope->contexts, key) == 0) {
SENTRY_SCOPE_NOTIFY(scope, remove_context, key);
}
}

void
sentry_scope_remove_context_n(
sentry_scope_t *scope, const char *key, size_t key_len)
{
char *k
= sentry__value_remove_and_take_key_n(scope->contexts, key, key_len);
if (k) {
SENTRY_SCOPE_NOTIFY(scope, remove_context, k);
}
sentry_free(k);
}

void
sentry_scope_update_context(
sentry_scope_t *scope, const char *key, sentry_value_t value)
Expand Down Expand Up @@ -909,6 +967,62 @@ sentry_scope_update_context_n(sentry_scope_t *scope, const char *key,
SENTRY_SCOPE_NOTIFY(scope, set_context, k, value);
}

void
sentry_scope_set_release_n(
sentry_scope_t *scope, const char *release, size_t release_len)
{
sentry_free(scope->release);
scope->release = sentry__string_clone_n(release, release_len);
sentry_value_set_by_key(scope->dynamic_sampling_context, "release",
sentry_value_new_string(scope->release));
SENTRY_SCOPE_NOTIFY(scope, set_release, scope->release);
}

void
sentry_scope_set_release(sentry_scope_t *scope, const char *release)
{
sentry_scope_set_release_n(scope, release, sentry__guarded_strlen(release));
}

void
sentry_scope_set_environment_n(
sentry_scope_t *scope, const char *environment, size_t environment_len)
{
sentry_free(scope->environment);
scope->environment = sentry__string_clone_n(environment, environment_len);
sentry_value_set_by_key(scope->dynamic_sampling_context, "environment",
sentry_value_new_string(scope->environment));
SENTRY_SCOPE_NOTIFY(scope, set_environment, scope->environment);
}

void
sentry_scope_set_environment(sentry_scope_t *scope, const char *environment)
{
sentry_scope_set_environment_n(
scope, environment, sentry__guarded_strlen(environment));
}

void
sentry_scope_set_transaction_n(
sentry_scope_t *scope, const char *transaction, size_t transaction_len)
{
sentry_free(scope->transaction);
scope->transaction = sentry__string_clone_n(transaction, transaction_len);

if (scope->transaction_object) {
sentry_transaction_set_name_n(
scope->transaction_object, transaction, transaction_len);
}
SENTRY_SCOPE_NOTIFY(scope, set_transaction, scope->transaction);
}

void
sentry_scope_set_transaction(sentry_scope_t *scope, const char *transaction)
{
sentry_scope_set_transaction_n(
scope, transaction, sentry__guarded_strlen(transaction));
}

void
sentry__scope_set_fingerprint_va(
sentry_scope_t *scope, const char *fingerprint, va_list va)
Expand Down Expand Up @@ -1033,6 +1147,17 @@ sentry__scope_add_attachment(
return added;
}

void
sentry_scope_remove_attachment(
sentry_scope_t *scope, sentry_attachment_t *attachment)
{
if (attachment
&& sentry__attachments_remove(&scope->attachments, attachment)) {
SENTRY_SCOPE_NOTIFY(scope, remove_attachment, attachment);
sentry__attachment_free(attachment);
}
}

sentry_attachment_t *
sentry_scope_attach_file(sentry_scope_t *scope, const char *path)
{
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/test_attachments.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,16 @@ SENTRY_TEST(attachments_add_dedupe)

SENTRY_TEST(attachments_add_remove)
{
sentry_scope_t *scope = sentry_scope_new();
sentry_attachment_t *scoped_attachment
= sentry_scope_attach_bytes(scope, "payload", 7, "file.bin");
TEST_CHECK(scoped_attachment != NULL);
TEST_CHECK(scope->attachments != NULL);
sentry_scope_remove_attachment(scope, scoped_attachment);
TEST_CHECK(scope->attachments == NULL);
sentry_scope_remove_attachment(scope, NULL);
sentry_scope_free(scope);

SENTRY_TEST_OPTIONS_NEW(options);
sentry_options_add_attachment(options, SENTRY_TEST_PATH_PREFIX ".a.txt");
sentry_options_add_attachment(options, SENTRY_TEST_PATH_PREFIX ".c.txt");
Expand Down
Loading
Loading