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
10 changes: 6 additions & 4 deletions src/sentry_attachment.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,25 +262,27 @@ sentry__attachments_add_path(sentry_attachment_t **attachments_ptr,
return sentry__attachments_add(attachments_ptr, attachment);
}

void
bool
sentry__attachments_remove(
sentry_attachment_t **attachments_ptr, sentry_attachment_t *attachment)
{
if (!attachment) {
return;
return false;
}

sentry_attachment_t **next_ptr = attachments_ptr;

for (sentry_attachment_t *it = *attachments_ptr; it; it = it->next) {
if (it == attachment) {
*next_ptr = it->next;
sentry__attachment_free(it);
return;
it->next = NULL;
return true;
}

next_ptr = &it->next;
}

return false;
}

static sentry_attachment_t *
Expand Down
3 changes: 2 additions & 1 deletion src/sentry_attachment.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,9 @@ sentry_attachment_t *sentry__attachments_add_path(

/**
* Removes an attachment from the attachments list at `attachments_ptr`.
* Returns true if the attachment was found and removed.
*/
void sentry__attachments_remove(
bool sentry__attachments_remove(
sentry_attachment_t **attachments_ptr, sentry_attachment_t *attachment);

/**
Expand Down
73 changes: 58 additions & 15 deletions src/sentry_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,7 @@ sentry_set_release_n(const char *release, size_t release_len)
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, release, release_len);
}
}

Expand All @@ -917,6 +918,8 @@ sentry_set_environment_n(const char *environment, size_t environment_len)
= 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, environment, environment_len);
}
}

Expand Down Expand Up @@ -981,16 +984,15 @@ sentry_set_tag_n(
void
sentry_remove_tag(const char *key)
{
SENTRY_WITH_SCOPE_MUT (scope) {
sentry_value_remove_by_key(scope->tags, key);
}
sentry_remove_tag_n(key, sentry__guarded_strlen(key));
}

void
sentry_remove_tag_n(const char *key, size_t key_len)
{
SENTRY_WITH_SCOPE_MUT (scope) {
sentry_value_remove_by_key_n(scope->tags, key, key_len);
SENTRY_SCOPE_NOTIFY(scope, remove_tag, key, key_len);
}
}

Expand All @@ -1015,6 +1017,8 @@ sentry_remove_extra(const char *key)
{
SENTRY_WITH_SCOPE_MUT (scope) {
sentry_value_remove_by_key(scope->extra, key);
SENTRY_SCOPE_NOTIFY(
scope, remove_extra, key, sentry__guarded_strlen(key));
}
}

Expand All @@ -1023,6 +1027,7 @@ sentry_remove_extra_n(const char *key, size_t key_len)
{
SENTRY_WITH_SCOPE_MUT (scope) {
sentry_value_remove_by_key_n(scope->extra, key, key_len);
SENTRY_SCOPE_NOTIFY(scope, remove_extra, key, key_len);
}
}

Expand Down Expand Up @@ -1096,6 +1101,8 @@ sentry__set_propagation_context(const char *key, sentry_value_t value)
{
SENTRY_WITH_SCOPE_MUT (scope) {
sentry_value_set_by_key(scope->propagation_context, key, value);
SENTRY_SCOPE_NOTIFY(
scope, set_context, key, sentry__guarded_strlen(key), value);
}
}

Expand Down Expand Up @@ -1130,6 +1137,8 @@ sentry_remove_context(const char *key)
{
SENTRY_WITH_SCOPE_MUT (scope) {
sentry_value_remove_by_key(scope->contexts, key);
SENTRY_SCOPE_NOTIFY(
scope, remove_context, key, sentry__guarded_strlen(key));
}
}

Expand All @@ -1138,6 +1147,7 @@ sentry_remove_context_n(const char *key, size_t key_len)
{
SENTRY_WITH_SCOPE_MUT (scope) {
sentry_value_remove_by_key_n(scope->contexts, key, key_len);
SENTRY_SCOPE_NOTIFY(scope, remove_context, key, key_len);
}
}

Expand Down Expand Up @@ -1174,6 +1184,7 @@ sentry_remove_fingerprint(void)
SENTRY_WITH_SCOPE_MUT (scope) {
sentry_value_decref(scope->fingerprint);
scope->fingerprint = sentry_value_new_null();
SENTRY_SCOPE_NOTIFY(scope, set_fingerprint, scope->fingerprint);
}
}

Expand Down Expand Up @@ -1228,6 +1239,9 @@ sentry_regenerate_trace(void)
generate_propagation_context(scope->propagation_context);
scope->trace_managed = false;
sentry__scope_update_dsc(scope, options);
SENTRY_SCOPE_NOTIFY(scope, set_context, "trace",
sentry__guarded_strlen("trace"),
sentry_value_get_by_key(scope->propagation_context, "trace"));
Comment thread
sentry[bot] marked this conversation as resolved.
}
}
}
Expand All @@ -1242,6 +1256,8 @@ sentry_set_transaction(const char *transaction)
if (scope->transaction_object) {
sentry_transaction_set_name(scope->transaction_object, transaction);
}
SENTRY_SCOPE_NOTIFY(scope, set_transaction, transaction,
sentry__guarded_strlen(transaction));
}
}

Expand All @@ -1257,6 +1273,8 @@ sentry_set_transaction_n(const char *transaction, size_t transaction_len)
sentry_transaction_set_name_n(
scope->transaction_object, transaction, transaction_len);
}
SENTRY_SCOPE_NOTIFY(
scope, set_transaction, transaction, transaction_len);
Comment thread
cursor[bot] marked this conversation as resolved.
}
}

Expand Down Expand Up @@ -1329,6 +1347,10 @@ sentry_transaction_start_ts(sentry_transaction_context_t *opaque_tx_ctx,
sentry_value_remove_by_key(tx, "parent_span_id");
sentry_value_remove_by_key(tx, "sampled");
sentry__scope_update_dsc(scope, options);
SENTRY_SCOPE_NOTIFY(scope, set_context, "trace",
sentry__guarded_strlen("trace"),
sentry_value_get_by_key(
scope->propagation_context, "trace"));
}
}
}
Expand Down Expand Up @@ -1399,6 +1421,9 @@ sentry__transaction_finish_value(
if (sentry__string_eq(tx_id, scope_tx_id)) {
sentry__transaction_decref(scope->transaction_object);
scope->transaction_object = NULL;
if (!scope->trace_managed) {
sentry__scope_notify_trace_context(scope);
}
}
}
// if the SDK manages the trace (rather than the user or a downstream
Expand All @@ -1411,6 +1436,7 @@ sentry__transaction_finish_value(
sentry_value_set_by_key(
sentry_value_get_by_key(scope->propagation_context, "trace"),
"trace_id", txn_trace_id);
sentry__scope_notify_trace_context(scope);
}
}
// The sampling decision should already be made for transactions
Expand Down Expand Up @@ -1475,6 +1501,7 @@ sentry_set_transaction_object(sentry_transaction_t *tx)
sentry__transaction_decref(scope->transaction_object);
sentry__transaction_incref(tx);
scope->transaction_object = tx;
sentry__scope_notify_trace_context(scope);
}
}

Expand All @@ -1487,6 +1514,7 @@ sentry_set_span(sentry_span_t *span)
sentry__span_decref(scope->span);
sentry__span_incref(span);
scope->span = span;
sentry__scope_notify_trace_context(scope);
}
}

Expand Down Expand Up @@ -1648,6 +1676,7 @@ sentry_span_finish_ts(sentry_span_t *opaque_span, uint64_t timestamp)
if (sentry__string_eq(span_id, scope_span_id)) {
sentry__span_decref(scope->span);
scope->span = NULL;
sentry__scope_notify_trace_context(scope);
}
}
}
Expand Down Expand Up @@ -1903,13 +1932,17 @@ sentry_capture_minidump_n(const char *path, size_t path_len)
static sentry_attachment_t *
add_attachment(sentry_attachment_t *attachment)
{
if (!attachment) {
return NULL;
}

SENTRY_WITH_OPTIONS (options) {
if (options->backend && options->backend->add_attachment_func) {
options->backend->add_attachment_func(options->backend, attachment);
}
}
SENTRY_WITH_SCOPE_MUT (scope) {
attachment = sentry__attachments_add(&scope->attachments, attachment);
attachment = sentry__scope_add_attachment(scope, attachment);
}
return attachment;
}
Comment thread
sentry[bot] marked this conversation as resolved.
Expand Down Expand Up @@ -1947,31 +1980,41 @@ sentry_clear_attachments(void)
{
SENTRY_WITH_OPTIONS (options) {
SENTRY_WITH_SCOPE_MUT (scope) {
if (options->backend && options->backend->remove_attachment_func) {
for (sentry_attachment_t *it = scope->attachments; it;
it = it->next) {
sentry_attachment_t *attachments = scope->attachments;
scope->attachments = NULL;
for (sentry_attachment_t *it = attachments; it; it = it->next) {
if (options->backend
&& options->backend->remove_attachment_func) {
options->backend->remove_attachment_func(
options->backend, it);
}
SENTRY_SCOPE_NOTIFY(scope, remove_attachment, it);
Comment thread
cursor[bot] marked this conversation as resolved.
}
sentry__attachments_free(scope->attachments);
scope->attachments = NULL;
sentry__attachments_free(attachments);
}
}
}

void
sentry_remove_attachment(sentry_attachment_t *attachment)
{
if (!attachment) {
return;
}

SENTRY_WITH_OPTIONS (options) {
if (options->backend && options->backend->remove_attachment_func) {
options->backend->remove_attachment_func(
options->backend, attachment);
SENTRY_WITH_SCOPE_MUT (scope) {
if (sentry__attachments_remove(&scope->attachments, attachment)) {
if (options->backend
&& options->backend->remove_attachment_func) {
options->backend->remove_attachment_func(
options->backend, attachment);
}
SENTRY_SCOPE_NOTIFY(scope, remove_attachment, attachment);
sentry__attachment_free(attachment);
}
Comment thread
jpnurmi marked this conversation as resolved.
}
}
SENTRY_WITH_SCOPE_MUT (scope) {
sentry__attachments_remove(&scope->attachments, attachment);
}
}

#ifdef SENTRY_PLATFORM_WINDOWS
Expand Down
Loading
Loading