diff --git a/include/sentry.h b/include/sentry.h index e83fb9006d..f8867c7048 100644 --- a/include/sentry.h +++ b/include/sentry.h @@ -1387,6 +1387,59 @@ SENTRY_EXPERIMENTAL_API sentry_value_t sentry_span_start_child( */ SENTRY_EXPERIMENTAL_API void sentry_span_finish( sentry_value_t root_transaction, sentry_value_t span); + +/** + * Sets a tag on a transaction to the given string value. + * + * Tags longer than 200 bytes will be truncated. + */ +SENTRY_EXPERIMENTAL_API void sentry_transaction_set_tag( + sentry_value_t transaction, const char *tag, const char *value); + +/** + * Removes a tag from a transaction. + */ +SENTRY_EXPERIMENTAL_API void sentry_transaction_remove_tag( + sentry_value_t transaction, const char *tag); + +/** + * Sets the given key in a transaction's "data" section to the given value. + */ +SENTRY_EXPERIMENTAL_API void sentry_transaction_set_data( + sentry_value_t transaction, const char *key, sentry_value_t value); + +/** + * Removes a key from a transaction's "data" section. + */ +SENTRY_EXPERIMENTAL_API void sentry_transaction_remove_data( + sentry_value_t transaction, const char *key); + +/** + * Sets a tag on a span to the given string value. + * + * Tags longer than 200 bytes will be truncated. + */ +SENTRY_EXPERIMENTAL_API void sentry_span_set_tag( + sentry_value_t span, const char *tag, const char *value); + +/** + * Removes a tag from a span. + */ +SENTRY_EXPERIMENTAL_API void sentry_span_remove_tag( + sentry_value_t span, const char *tag); + +/** + * Sets the given key in a span's "data" section to the given value. + */ +SENTRY_EXPERIMENTAL_API void sentry_span_set_data( + sentry_value_t span, const char *key, sentry_value_t value); + +/** + * Removes a key from a span's "data" section. + */ +SENTRY_EXPERIMENTAL_API void sentry_span_remove_data( + sentry_value_t span, const char *key); + #endif #ifdef __cplusplus diff --git a/src/sentry_value.c b/src/sentry_value.c index f4bf51f3db..7a22b91f94 100644 --- a/src/sentry_value.c +++ b/src/sentry_value.c @@ -1254,3 +1254,75 @@ sentry_event_value_add_stacktrace(sentry_value_t event, void **ips, size_t len) sentry_event_add_thread(event, thread); } + +void +sentry_span_set_tag(sentry_value_t span, const char *tag, const char *value) +{ + sentry_value_t tags = sentry_value_get_by_key(span, "tags"); + if (sentry_value_is_null(tags)) { + tags = sentry_value_new_object(); + sentry_value_set_by_key(span, "tags", tags); + } + + char *s = sentry__string_clonen(value, 200); + if (s) { + sentry_value_set_by_key(tags, tag, sentry__value_new_string_owned(s)); + } else { + sentry_value_set_by_key(tags, tag, sentry_value_new_null()); + } +} + +void +sentry_span_remove_tag(sentry_value_t span, const char *tag) +{ + sentry_value_t tags = sentry_value_get_by_key(span, "tags"); + if (!sentry_value_is_null(tags)) { + sentry_value_remove_by_key(tags, tag); + } +} + +void +sentry_span_set_data(sentry_value_t span, const char *key, sentry_value_t value) +{ + sentry_value_t data = sentry_value_get_by_key(span, "data"); + if (sentry_value_is_null(data)) { + data = sentry_value_new_object(); + sentry_value_set_by_key(span, "data", data); + } + sentry_value_set_by_key(data, key, value); +} + +void +sentry_span_remove_data(sentry_value_t span, const char *key) +{ + sentry_value_t data = sentry_value_get_by_key(span, "data"); + if (!sentry_value_is_null(data)) { + sentry_value_remove_by_key(data, key); + } +} + +void +sentry_transaction_set_tag( + sentry_value_t transaction, const char *tag, const char *value) +{ + sentry_span_set_tag(transaction, tag, value); +} + +void +sentry_transaction_remove_tag(sentry_value_t transaction, const char *tag) +{ + sentry_span_remove_tag(transaction, tag); +} + +void +sentry_transaction_set_data( + sentry_value_t transaction, const char *key, sentry_value_t value) +{ + sentry_span_set_data(transaction, key, value); +} + +void +sentry_transaction_remove_data(sentry_value_t transaction, const char *key) +{ + sentry_span_remove_data(transaction, key); +}