From c3ef98035a42124e3b99757e40a79e80e41f94a2 Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Tue, 14 Dec 2021 15:10:25 +0100 Subject: [PATCH 01/12] tracing: Add transaction tag methods --- include/sentry.h | 9 +++++++++ src/sentry_value.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/include/sentry.h b/include/sentry.h index 274169a4f..f2ba565b0 100644 --- a/include/sentry.h +++ b/include/sentry.h @@ -1275,6 +1275,15 @@ SENTRY_EXPERIMENTAL_API void sentry_transaction_set_sampled( SENTRY_EXPERIMENTAL_API void sentry_transaction_remove_sampled( sentry_value_t transaction); +SENTRY_EXPERIMENTAL_API void sentry_transaction_set_tag( + sentry_value_t transaction, const char *tag, const char *value); + +SENTRY_EXPERIMENTAL_API void sentry_transaction_remove_tag( + sentry_value_t transaction, const char *tag); + +SENTRY_EXPERIMENTAL_API void sentry_transaction_set_data( + sentry_value_t transaction, const char *key, sentry_value_t value); + #ifdef __cplusplus } #endif diff --git a/src/sentry_value.c b/src/sentry_value.c index c71c68ecf..cbf4c555f 100644 --- a/src/sentry_value.c +++ b/src/sentry_value.c @@ -1219,3 +1219,35 @@ sentry_event_value_add_stacktrace(sentry_value_t event, void **ips, size_t len) sentry_event_add_thread(event, thread); } + +void +sentry_transaction_set_tag(sentry_value_t transaction, const char *tag, const char *value) +{ + sentry_value_t tags = sentry_value_get_by_key(transaction, "tags"); + if (sentry_value_is_null(tags)) { + tags = sentry_value_new_object(); + sentry_value_set_by_key(transaction, "tags", tags); + } + sentry_value_t value_str = sentry_value_new_string(value); + sentry_value_set_by_key(tags, tag, value_str); +} + +void +sentry_transaction_remove_tag(sentry_value_t transaction, const char *tag) +{ + sentry_value_t tags = sentry_value_get_by_key(transaction, "tags"); + if (!sentry_value_is_null(tags)) { + sentry_value_remove_by_key(tags, tag); + } +} + +void +sentry_transaction_set_data(sentry_value_t transaction, const char *key, sentry_value_t value) +{ + sentry_value_t data = sentry_value_get_by_key(transaction, "data"); + if (sentry_value_is_null(data)) { + data = sentry_value_new_object(); + sentry_value_set_by_key(transaction, "data", data); + } + sentry_value_set_by_key(data, key, value); +} From 53783ce935cb6700df22744605eacbf561c6ae86 Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Wed, 15 Dec 2021 11:30:58 +0100 Subject: [PATCH 02/12] Add remove_data method --- include/sentry.h | 5 ++++- src/sentry_value.c | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/include/sentry.h b/include/sentry.h index f2ba565b0..6f1ad1ef4 100644 --- a/include/sentry.h +++ b/include/sentry.h @@ -1278,12 +1278,15 @@ SENTRY_EXPERIMENTAL_API void sentry_transaction_remove_sampled( SENTRY_EXPERIMENTAL_API void sentry_transaction_set_tag( sentry_value_t transaction, const char *tag, const char *value); -SENTRY_EXPERIMENTAL_API void sentry_transaction_remove_tag( +SENTRY_EXPERIMENTAL_API int sentry_transaction_remove_tag( sentry_value_t transaction, const char *tag); SENTRY_EXPERIMENTAL_API void sentry_transaction_set_data( sentry_value_t transaction, const char *key, sentry_value_t value); +SENTRY_EXPERIMENTAL_API int sentry_transaction_remove_data( + sentry_value_t transaction, const char *key); + #ifdef __cplusplus } #endif diff --git a/src/sentry_value.c b/src/sentry_value.c index cbf4c555f..afda3d18b 100644 --- a/src/sentry_value.c +++ b/src/sentry_value.c @@ -1232,13 +1232,15 @@ sentry_transaction_set_tag(sentry_value_t transaction, const char *tag, const ch sentry_value_set_by_key(tags, tag, value_str); } -void +int sentry_transaction_remove_tag(sentry_value_t transaction, const char *tag) { sentry_value_t tags = sentry_value_get_by_key(transaction, "tags"); if (!sentry_value_is_null(tags)) { - sentry_value_remove_by_key(tags, tag); + return sentry_value_remove_by_key(tags, tag); } + + return 1; } void @@ -1251,3 +1253,14 @@ sentry_transaction_set_data(sentry_value_t transaction, const char *key, sentry_ } sentry_value_set_by_key(data, key, value); } + +int +sentry_transaction_remove_data(sentry_value_t transaction, const char *key) +{ + sentry_value_t data = sentry_value_get_by_key(transaction, "data"); + if (!sentry_value_is_null(data)) { + return sentry_value_remove_by_key(data, key); + } + + return 1; +} From 88fa66681ea26fa315f8aa34daf41df359aa2eed Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Wed, 15 Dec 2021 17:01:57 +0100 Subject: [PATCH 03/12] Add docs --- include/sentry.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/sentry.h b/include/sentry.h index 6f1ad1ef4..18df5f6c1 100644 --- a/include/sentry.h +++ b/include/sentry.h @@ -1275,15 +1275,29 @@ SENTRY_EXPERIMENTAL_API void sentry_transaction_set_sampled( SENTRY_EXPERIMENTAL_API void sentry_transaction_remove_sampled( sentry_value_t transaction); +/** + * Sets a tag on a transaction to the given string value. + */ SENTRY_EXPERIMENTAL_API void sentry_transaction_set_tag( sentry_value_t transaction, const char *tag, const char *value); +/** + * Removes a tag from a transaction. Returns 0 if the tag was successfully + * removed, 1 otherwise. + */ SENTRY_EXPERIMENTAL_API int 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. Returns 0 if the key was successfully + * removed, 1 otherwise. + */ SENTRY_EXPERIMENTAL_API int sentry_transaction_remove_data( sentry_value_t transaction, const char *key); From 6521807560736d9b692f3ea2d5b6a693233bf90c Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Fri, 17 Dec 2021 11:23:45 +0100 Subject: [PATCH 04/12] Change remove method signatures --- include/sentry.h | 4 ++-- src/sentry_value.c | 12 ++++-------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/include/sentry.h b/include/sentry.h index 18df5f6c1..e68576d93 100644 --- a/include/sentry.h +++ b/include/sentry.h @@ -1285,7 +1285,7 @@ SENTRY_EXPERIMENTAL_API void sentry_transaction_set_tag( * Removes a tag from a transaction. Returns 0 if the tag was successfully * removed, 1 otherwise. */ -SENTRY_EXPERIMENTAL_API int sentry_transaction_remove_tag( +SENTRY_EXPERIMENTAL_API void sentry_transaction_remove_tag( sentry_value_t transaction, const char *tag); /** @@ -1298,7 +1298,7 @@ SENTRY_EXPERIMENTAL_API void sentry_transaction_set_data( * Removes a key from a transaction's "data" section. Returns 0 if the key was successfully * removed, 1 otherwise. */ -SENTRY_EXPERIMENTAL_API int sentry_transaction_remove_data( +SENTRY_EXPERIMENTAL_API void sentry_transaction_remove_data( sentry_value_t transaction, const char *key); #ifdef __cplusplus diff --git a/src/sentry_value.c b/src/sentry_value.c index afda3d18b..2e7dd8334 100644 --- a/src/sentry_value.c +++ b/src/sentry_value.c @@ -1232,15 +1232,13 @@ sentry_transaction_set_tag(sentry_value_t transaction, const char *tag, const ch sentry_value_set_by_key(tags, tag, value_str); } -int +void sentry_transaction_remove_tag(sentry_value_t transaction, const char *tag) { sentry_value_t tags = sentry_value_get_by_key(transaction, "tags"); if (!sentry_value_is_null(tags)) { - return sentry_value_remove_by_key(tags, tag); + sentry_value_remove_by_key(tags, tag); } - - return 1; } void @@ -1254,13 +1252,11 @@ sentry_transaction_set_data(sentry_value_t transaction, const char *key, sentry_ sentry_value_set_by_key(data, key, value); } -int +void sentry_transaction_remove_data(sentry_value_t transaction, const char *key) { sentry_value_t data = sentry_value_get_by_key(transaction, "data"); if (!sentry_value_is_null(data)) { - return sentry_value_remove_by_key(data, key); + sentry_value_remove_by_key(data, key); } - - return 1; } From 87d627d14575a451cd24568a7870dbe17cacadc1 Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Fri, 17 Dec 2021 11:25:43 +0100 Subject: [PATCH 05/12] Fix docs --- include/sentry.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/include/sentry.h b/include/sentry.h index e68576d93..bb76728db 100644 --- a/include/sentry.h +++ b/include/sentry.h @@ -1282,8 +1282,7 @@ SENTRY_EXPERIMENTAL_API void sentry_transaction_set_tag( sentry_value_t transaction, const char *tag, const char *value); /** - * Removes a tag from a transaction. Returns 0 if the tag was successfully - * removed, 1 otherwise. + * Removes a tag from a transaction. */ SENTRY_EXPERIMENTAL_API void sentry_transaction_remove_tag( sentry_value_t transaction, const char *tag); @@ -1295,8 +1294,7 @@ 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. Returns 0 if the key was successfully - * removed, 1 otherwise. + * Removes a key from a transaction's "data" section. */ SENTRY_EXPERIMENTAL_API void sentry_transaction_remove_data( sentry_value_t transaction, const char *key); From b6c6f22457d22ed8a208220a296386a75717b26b Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Fri, 17 Dec 2021 11:31:41 +0100 Subject: [PATCH 06/12] Fix formatting --- src/sentry_value.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/sentry_value.c b/src/sentry_value.c index 2e7dd8334..41fe1e8af 100644 --- a/src/sentry_value.c +++ b/src/sentry_value.c @@ -1221,7 +1221,8 @@ sentry_event_value_add_stacktrace(sentry_value_t event, void **ips, size_t len) } void -sentry_transaction_set_tag(sentry_value_t transaction, const char *tag, const char *value) +sentry_transaction_set_tag( + sentry_value_t transaction, const char *tag, const char *value) { sentry_value_t tags = sentry_value_get_by_key(transaction, "tags"); if (sentry_value_is_null(tags)) { @@ -1242,7 +1243,8 @@ sentry_transaction_remove_tag(sentry_value_t transaction, const char *tag) } void -sentry_transaction_set_data(sentry_value_t transaction, const char *key, sentry_value_t value) +sentry_transaction_set_data( + sentry_value_t transaction, const char *key, sentry_value_t value) { sentry_value_t data = sentry_value_get_by_key(transaction, "data"); if (sentry_value_is_null(data)) { From 9bd0985854b4b42d398f6299b501730674a4d3a1 Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Tue, 11 Jan 2022 11:43:07 +0100 Subject: [PATCH 07/12] Separate functions for spans and transactions --- include/sentry.h | 24 ++++++++++++++++++++++ src/sentry_value.c | 50 +++++++++++++++++++++++++++++++++++----------- 2 files changed, 62 insertions(+), 12 deletions(-) diff --git a/include/sentry.h b/include/sentry.h index 5e7a78d92..036265e65 100644 --- a/include/sentry.h +++ b/include/sentry.h @@ -1412,6 +1412,30 @@ SENTRY_EXPERIMENTAL_API void sentry_transaction_set_data( 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. + */ +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 9df97aa4b..b71fe4027 100644 --- a/src/sentry_value.c +++ b/src/sentry_value.c @@ -1256,44 +1256,70 @@ sentry_event_value_add_stacktrace(sentry_value_t event, void **ips, size_t len) } void -sentry_transaction_set_tag( - sentry_value_t transaction, const char *tag, const char *value) +sentry_span_set_tag( + sentry_value_t span, const char *tag, const char *value) { - sentry_value_t tags = sentry_value_get_by_key(transaction, "tags"); + 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(transaction, "tags", tags); + sentry_value_set_by_key(span, "tags", tags); } sentry_value_t value_str = sentry_value_new_string(value); sentry_value_set_by_key(tags, tag, value_str); } void -sentry_transaction_remove_tag(sentry_value_t transaction, const char *tag) +sentry_span_remove_tag(sentry_value_t span, const char *tag) { - sentry_value_t tags = sentry_value_get_by_key(transaction, "tags"); + 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_transaction_set_data( - sentry_value_t transaction, const char *key, sentry_value_t value) +sentry_span_set_data( + sentry_value_t span, const char *key, sentry_value_t value) { - sentry_value_t data = sentry_value_get_by_key(transaction, "data"); + 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(transaction, "data", data); + sentry_value_set_by_key(span, "data", data); } sentry_value_set_by_key(data, key, value); } void -sentry_transaction_remove_data(sentry_value_t transaction, const char *key) +sentry_span_remove_data(sentry_value_t span, const char *key) { - sentry_value_t data = sentry_value_get_by_key(transaction, "data"); + 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); +} From 3881e0561444b944f528f649599c340e0d4e5e44 Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Tue, 11 Jan 2022 12:41:59 +0100 Subject: [PATCH 08/12] Limit tags to 200 bytes --- include/sentry.h | 4 ++++ src/sentry_value.c | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/include/sentry.h b/include/sentry.h index 036265e65..f8867c704 100644 --- a/include/sentry.h +++ b/include/sentry.h @@ -1390,6 +1390,8 @@ SENTRY_EXPERIMENTAL_API void sentry_span_finish( /** * 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); @@ -1414,6 +1416,8 @@ SENTRY_EXPERIMENTAL_API void sentry_transaction_remove_data( /** * 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); diff --git a/src/sentry_value.c b/src/sentry_value.c index b71fe4027..19d923d5b 100644 --- a/src/sentry_value.c +++ b/src/sentry_value.c @@ -1264,8 +1264,13 @@ sentry_span_set_tag( tags = sentry_value_new_object(); sentry_value_set_by_key(span, "tags", tags); } - sentry_value_t value_str = sentry_value_new_string(value); - sentry_value_set_by_key(tags, tag, value_str); + + char *s = sentry__string_clonen(value, 200); + if (s) { + sentry_value_set_by_key(tags, tag, sentry__value_new_string_owned(value)); + } else { + sentry_value_set_by_key(tags, tag, sentry_value_new_null()) + } } void From d81854465c614d059093e7e5fe0212abbc08dbac Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Tue, 11 Jan 2022 13:20:01 +0100 Subject: [PATCH 09/12] Formatting --- src/sentry_value.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/sentry_value.c b/src/sentry_value.c index 19d923d5b..3a7435d4b 100644 --- a/src/sentry_value.c +++ b/src/sentry_value.c @@ -1256,8 +1256,7 @@ sentry_event_value_add_stacktrace(sentry_value_t event, void **ips, size_t len) } void -sentry_span_set_tag( - sentry_value_t span, const char *tag, const char *value) +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)) { @@ -1267,7 +1266,8 @@ sentry_span_set_tag( char *s = sentry__string_clonen(value, 200); if (s) { - sentry_value_set_by_key(tags, tag, sentry__value_new_string_owned(value)); + sentry_value_set_by_key( + tags, tag, sentry__value_new_string_owned(value)); } else { sentry_value_set_by_key(tags, tag, sentry_value_new_null()) } @@ -1283,8 +1283,7 @@ sentry_span_remove_tag(sentry_value_t span, const char *tag) } void -sentry_span_set_data( - sentry_value_t span, const char *key, sentry_value_t value) +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)) { From fb5cf03143a51c58e23e5e3f13129da15b7ca5f6 Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Tue, 11 Jan 2022 13:21:39 +0100 Subject: [PATCH 10/12] Typo --- src/sentry_value.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sentry_value.c b/src/sentry_value.c index 3a7435d4b..026a9570b 100644 --- a/src/sentry_value.c +++ b/src/sentry_value.c @@ -1269,7 +1269,7 @@ sentry_span_set_tag(sentry_value_t span, const char *tag, const char *value) sentry_value_set_by_key( tags, tag, sentry__value_new_string_owned(value)); } else { - sentry_value_set_by_key(tags, tag, sentry_value_new_null()) + sentry_value_set_by_key(tags, tag, sentry_value_new_null()); } } From 7ee71a9089e85c103439586cae5a41a7ff779fa2 Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Tue, 11 Jan 2022 13:29:10 +0100 Subject: [PATCH 11/12] Bugfix --- src/sentry_value.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sentry_value.c b/src/sentry_value.c index 026a9570b..0f81b8568 100644 --- a/src/sentry_value.c +++ b/src/sentry_value.c @@ -1267,7 +1267,7 @@ sentry_span_set_tag(sentry_value_t span, const char *tag, const char *value) char *s = sentry__string_clonen(value, 200); if (s) { sentry_value_set_by_key( - tags, tag, sentry__value_new_string_owned(value)); + tags, tag, sentry__value_new_string_owned(s)); } else { sentry_value_set_by_key(tags, tag, sentry_value_new_null()); } From 5786c5f986a7af1c6f19fbbebd59000f903eb9c8 Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Tue, 11 Jan 2022 13:31:27 +0100 Subject: [PATCH 12/12] formatting --- src/sentry_value.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/sentry_value.c b/src/sentry_value.c index 0f81b8568..7a22b91f9 100644 --- a/src/sentry_value.c +++ b/src/sentry_value.c @@ -1266,8 +1266,7 @@ sentry_span_set_tag(sentry_value_t span, const char *tag, const char *value) char *s = sentry__string_clonen(value, 200); if (s) { - sentry_value_set_by_key( - tags, tag, sentry__value_new_string_owned(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()); }