From 1ba43ccdbb6d67da5793de45a366243d57e2aaff Mon Sep 17 00:00:00 2001 From: JoshuaMoelans <60878493+JoshuaMoelans@users.noreply.github.com> Date: Wed, 6 Nov 2024 15:54:49 +0100 Subject: [PATCH 1/9] add emitting of transaction data inside context trace data --- src/sentry_core.c | 3 +++ tests/unit/test_tracing.c | 12 ++++++++++++ tests/unit/tests.inc | 1 + 3 files changed, 16 insertions(+) diff --git a/src/sentry_core.c b/src/sentry_core.c index ebd8ec7a9..d626d5dd8 100644 --- a/src/sentry_core.c +++ b/src/sentry_core.c @@ -934,6 +934,8 @@ sentry_transaction_finish(sentry_transaction_t *opaque_tx) sentry_value_t trace_context = sentry__value_get_trace_context(opaque_tx->inner); sentry_value_t contexts = sentry_value_new_object(); + sentry_value_set_by_key(contexts, "data", + sentry_value_get_by_key(tx, "extra")); sentry_value_set_by_key(contexts, "trace", trace_context); sentry_value_set_by_key(tx, "contexts", contexts); @@ -944,6 +946,7 @@ sentry_transaction_finish(sentry_transaction_t *opaque_tx) sentry_value_remove_by_key(tx, "op"); sentry_value_remove_by_key(tx, "description"); sentry_value_remove_by_key(tx, "status"); + sentry_value_remove_by_key(tx, "extra"); sentry__transaction_decref(opaque_tx); diff --git a/tests/unit/test_tracing.c b/tests/unit/test_tracing.c index 5d86ee48a..b4b06b812 100644 --- a/tests/unit/test_tracing.c +++ b/tests/unit/test_tracing.c @@ -1097,6 +1097,18 @@ SENTRY_TEST(txn_data) sentry__transaction_decref(txn); } +SENTRY_TEST(ctx_trace_data) +{ + sentry_transaction_t *txn + = sentry__transaction_new(sentry_value_new_object()); + + sentry_transaction_set_data(txn, "os.name", sentry_value_new_string("Linux")); + check_after_set(txn->inner, "extra", "os.name", "Linux"); + sentry_value_set_by_key(txn->inner, "sampled", sentry_value_new_bool(true)); + + sentry_transaction_finish(txn); +} + SENTRY_TEST(span_data) { sentry_transaction_t *txn diff --git a/tests/unit/tests.inc b/tests/unit/tests.inc index e81c34205..7b0052d66 100644 --- a/tests/unit/tests.inc +++ b/tests/unit/tests.inc @@ -24,6 +24,7 @@ XX(concurrent_uninit) XX(count_sampled_events) XX(crash_marker) XX(crashed_last_run) +XX(ctx_data) XX(custom_logger) XX(discarding_before_send) XX(distributed_headers) From 30ab79ccdef71b1014e3e0254ae620d730df2667 Mon Sep 17 00:00:00 2001 From: JoshuaMoelans <60878493+JoshuaMoelans@users.noreply.github.com> Date: Wed, 6 Nov 2024 15:57:07 +0100 Subject: [PATCH 2/9] format --- src/sentry_core.c | 4 ++-- tests/unit/test_tracing.c | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/sentry_core.c b/src/sentry_core.c index d626d5dd8..f9724d830 100644 --- a/src/sentry_core.c +++ b/src/sentry_core.c @@ -934,8 +934,8 @@ sentry_transaction_finish(sentry_transaction_t *opaque_tx) sentry_value_t trace_context = sentry__value_get_trace_context(opaque_tx->inner); sentry_value_t contexts = sentry_value_new_object(); - sentry_value_set_by_key(contexts, "data", - sentry_value_get_by_key(tx, "extra")); + sentry_value_set_by_key( + contexts, "data", sentry_value_get_by_key(tx, "extra")); sentry_value_set_by_key(contexts, "trace", trace_context); sentry_value_set_by_key(tx, "contexts", contexts); diff --git a/tests/unit/test_tracing.c b/tests/unit/test_tracing.c index b4b06b812..35870486e 100644 --- a/tests/unit/test_tracing.c +++ b/tests/unit/test_tracing.c @@ -1100,9 +1100,10 @@ SENTRY_TEST(txn_data) SENTRY_TEST(ctx_trace_data) { sentry_transaction_t *txn - = sentry__transaction_new(sentry_value_new_object()); + = sentry__transaction_new(sentry_value_new_object()); - sentry_transaction_set_data(txn, "os.name", sentry_value_new_string("Linux")); + sentry_transaction_set_data( + txn, "os.name", sentry_value_new_string("Linux")); check_after_set(txn->inner, "extra", "os.name", "Linux"); sentry_value_set_by_key(txn->inner, "sampled", sentry_value_new_bool(true)); From 4894aaa4d88f84f53b88cf20811308dcd8d505c7 Mon Sep 17 00:00:00 2001 From: JoshuaMoelans <60878493+JoshuaMoelans@users.noreply.github.com> Date: Wed, 6 Nov 2024 16:03:23 +0100 Subject: [PATCH 3/9] fix test name --- tests/unit/tests.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/tests.inc b/tests/unit/tests.inc index 7b0052d66..09c566332 100644 --- a/tests/unit/tests.inc +++ b/tests/unit/tests.inc @@ -24,7 +24,7 @@ XX(concurrent_uninit) XX(count_sampled_events) XX(crash_marker) XX(crashed_last_run) -XX(ctx_data) +XX(ctx_trace_data) XX(custom_logger) XX(discarding_before_send) XX(distributed_headers) From a6eafed2b190ccd3c1afbac74666b63f8c4ca5ff Mon Sep 17 00:00:00 2001 From: JoshuaMoelans <60878493+JoshuaMoelans@users.noreply.github.com> Date: Thu, 7 Nov 2024 09:50:51 +0100 Subject: [PATCH 4/9] update test + proper data store --- src/sentry_core.c | 3 ++- tests/test_integration_http.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/sentry_core.c b/src/sentry_core.c index f9724d830..9911e2a2c 100644 --- a/src/sentry_core.c +++ b/src/sentry_core.c @@ -935,7 +935,8 @@ sentry_transaction_finish(sentry_transaction_t *opaque_tx) = sentry__value_get_trace_context(opaque_tx->inner); sentry_value_t contexts = sentry_value_new_object(); sentry_value_set_by_key( - contexts, "data", sentry_value_get_by_key(tx, "extra")); + trace_context, "data", sentry_value_get_by_key(tx, "extra")); + sentry_value_incref(sentry_value_get_by_key(tx, "extra")); sentry_value_set_by_key(contexts, "trace", trace_context); sentry_value_set_by_key(tx, "contexts", contexts); diff --git a/tests/test_integration_http.py b/tests/test_integration_http.py index 1ef549f16..255ec3464 100644 --- a/tests/test_integration_http.py +++ b/tests/test_integration_http.py @@ -544,7 +544,6 @@ def test_transaction_only(cmake, httpserver, build_args): assert_meta( envelope, transaction="little.teapot", - transaction_data={"url": "https://example.com"}, ) # Extract the one-and-only-item @@ -575,6 +574,8 @@ def test_transaction_only(cmake, httpserver, build_args): timestamp = time.strptime(payload["timestamp"], RFC3339_FORMAT) assert timestamp >= start_timestamp + assert trace_context["data"] == {"url": "https://example.com"} + def test_capture_minidump(cmake, httpserver): tmp_path = cmake(["sentry_example"], {"SENTRY_BACKEND": "none"}) From c8ba4a8b1f44fd758d4079bd6994ce65a3a34247 Mon Sep 17 00:00:00 2001 From: JoshuaMoelans <60878493+JoshuaMoelans@users.noreply.github.com> Date: Thu, 7 Nov 2024 09:51:47 +0100 Subject: [PATCH 5/9] remove unnecessary test --- tests/unit/test_tracing.c | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/tests/unit/test_tracing.c b/tests/unit/test_tracing.c index 35870486e..5d86ee48a 100644 --- a/tests/unit/test_tracing.c +++ b/tests/unit/test_tracing.c @@ -1097,19 +1097,6 @@ SENTRY_TEST(txn_data) sentry__transaction_decref(txn); } -SENTRY_TEST(ctx_trace_data) -{ - sentry_transaction_t *txn - = sentry__transaction_new(sentry_value_new_object()); - - sentry_transaction_set_data( - txn, "os.name", sentry_value_new_string("Linux")); - check_after_set(txn->inner, "extra", "os.name", "Linux"); - sentry_value_set_by_key(txn->inner, "sampled", sentry_value_new_bool(true)); - - sentry_transaction_finish(txn); -} - SENTRY_TEST(span_data) { sentry_transaction_t *txn From 0e63492962aaa2a240c8bb93d68e713996466d8b Mon Sep 17 00:00:00 2001 From: JoshuaMoelans <60878493+JoshuaMoelans@users.noreply.github.com> Date: Thu, 7 Nov 2024 09:57:34 +0100 Subject: [PATCH 6/9] remove unnecessary test from tests.inc --- tests/unit/tests.inc | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/unit/tests.inc b/tests/unit/tests.inc index 09c566332..e81c34205 100644 --- a/tests/unit/tests.inc +++ b/tests/unit/tests.inc @@ -24,7 +24,6 @@ XX(concurrent_uninit) XX(count_sampled_events) XX(crash_marker) XX(crashed_last_run) -XX(ctx_trace_data) XX(custom_logger) XX(discarding_before_send) XX(distributed_headers) From 42c8114e493a4fae17e8c435ba37c411d8a7aa4c Mon Sep 17 00:00:00 2001 From: JoshuaMoelans <60878493+JoshuaMoelans@users.noreply.github.com> Date: Thu, 7 Nov 2024 10:33:56 +0100 Subject: [PATCH 7/9] update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec6e85354..e2eb96ace 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +**Fixes**: + +- Emit `transaction.data` inside `context.trace.data` ([#1075](https://github.com/getsentry/sentry-native/pull/1075)) + ## 0.7.12 **Features**: From 0623fe6224f55e42ed8c107bedeff90b82c69186 Mon Sep 17 00:00:00 2001 From: JoshuaMoelans <60878493+JoshuaMoelans@users.noreply.github.com> Date: Thu, 7 Nov 2024 11:10:24 +0100 Subject: [PATCH 8/9] renamed transaction.extra -> transaction.data --- src/sentry_core.c | 6 +++--- src/sentry_tracing.c | 2 +- tests/unit/test_tracing.c | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/sentry_core.c b/src/sentry_core.c index 9911e2a2c..cedce7847 100644 --- a/src/sentry_core.c +++ b/src/sentry_core.c @@ -935,8 +935,8 @@ sentry_transaction_finish(sentry_transaction_t *opaque_tx) = sentry__value_get_trace_context(opaque_tx->inner); sentry_value_t contexts = sentry_value_new_object(); sentry_value_set_by_key( - trace_context, "data", sentry_value_get_by_key(tx, "extra")); - sentry_value_incref(sentry_value_get_by_key(tx, "extra")); + trace_context, "data", sentry_value_get_by_key(tx, "data")); + sentry_value_incref(sentry_value_get_by_key(tx, "data")); sentry_value_set_by_key(contexts, "trace", trace_context); sentry_value_set_by_key(tx, "contexts", contexts); @@ -947,7 +947,7 @@ sentry_transaction_finish(sentry_transaction_t *opaque_tx) sentry_value_remove_by_key(tx, "op"); sentry_value_remove_by_key(tx, "description"); sentry_value_remove_by_key(tx, "status"); - sentry_value_remove_by_key(tx, "extra"); + sentry_value_remove_by_key(tx, "data"); sentry__transaction_decref(opaque_tx); diff --git a/src/sentry_tracing.c b/src/sentry_tracing.c index 2a63511ce..e42599f48 100644 --- a/src/sentry_tracing.c +++ b/src/sentry_tracing.c @@ -578,7 +578,7 @@ sentry_transaction_set_data( } } -static const char txn_data_key[] = "extra"; +static const char txn_data_key[] = "data"; static const size_t txn_data_key_len = sizeof(txn_data_key) - 1; void diff --git a/tests/unit/test_tracing.c b/tests/unit/test_tracing.c index 5d86ee48a..6650410dd 100644 --- a/tests/unit/test_tracing.c +++ b/tests/unit/test_tracing.c @@ -1089,10 +1089,10 @@ SENTRY_TEST(txn_data) sentry_transaction_set_data( txn, "os.name", sentry_value_new_string("Linux")); - check_after_set(txn->inner, "extra", "os.name", "Linux"); + check_after_set(txn->inner, "data", "os.name", "Linux"); sentry_transaction_remove_data(txn, "os.name"); - check_after_remove(txn->inner, "extra", "os.name"); + check_after_remove(txn->inner, "data", "os.name"); sentry__transaction_decref(txn); } @@ -1139,10 +1139,10 @@ SENTRY_TEST(txn_data_n) sentry_value_t data_value = sentry_value_new_string_n(data_v, sizeof(data_v)); sentry_transaction_set_data_n(txn, data_k, sizeof(data_k), data_value); - check_after_set(txn->inner, "extra", "os.name", "Linux"); + check_after_set(txn->inner, "data", "os.name", "Linux"); sentry_transaction_remove_data_n(txn, data_k, sizeof(data_k)); - check_after_remove(txn->inner, "extra", "os.name"); + check_after_remove(txn->inner, "data", "os.name"); sentry__transaction_decref(txn); } From 65c4373657a4ed3dd4323851f3fd3e521fae8e6d Mon Sep 17 00:00:00 2001 From: JoshuaMoelans <60878493+JoshuaMoelans@users.noreply.github.com> Date: Thu, 7 Nov 2024 13:08:17 +0100 Subject: [PATCH 9/9] apply scoped transaction/span data to every in-scope event --- src/sentry_scope.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/sentry_scope.c b/src/sentry_scope.c index 1e7f15e06..78fc084df 100644 --- a/src/sentry_scope.c +++ b/src/sentry_scope.c @@ -318,12 +318,20 @@ sentry__scope_apply_to_event(const sentry_scope_t *scope, // prep contexts sourced from scope; data about transaction on scope needs // to be extracted and inserted - sentry_value_t scope_trace = sentry__value_get_trace_context( - sentry__get_span_or_transaction(scope)); + sentry_value_t scoped_txn_or_span = sentry__get_span_or_transaction(scope); + sentry_value_t scope_trace + = sentry__value_get_trace_context(scoped_txn_or_span); if (!sentry_value_is_null(scope_trace)) { if (sentry_value_is_null(contexts)) { contexts = sentry_value_new_object(); } + sentry_value_t scoped_txn_or_span_data + = sentry_value_get_by_key(scoped_txn_or_span, "data"); + if (!sentry_value_is_null(scoped_txn_or_span_data)) { + sentry_value_incref(scoped_txn_or_span_data); + sentry_value_set_by_key( + scope_trace, "data", scoped_txn_or_span_data); + } sentry_value_set_by_key(contexts, "trace", scope_trace); }