Skip to content

Commit 67cc95c

Browse files
feat: add emitting of transaction data inside context trace data (#1075)
* add emitting of transaction data inside context trace data * format * fix test name * update test + proper data store * remove unnecessary test * remove unnecessary test from tests.inc * update CHANGELOG.md * renamed transaction.extra -> transaction.data * apply scoped transaction/span data to every in-scope event --------- Co-authored-by: Mischan Toosarani-Hausberger <mischan@abovevacant.com>
1 parent 34a9901 commit 67cc95c

File tree

6 files changed

+22
-8
lines changed

6 files changed

+22
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
**Fixes**:
1010

1111
- Correct the timeout specified for the upload-task awaiting `dispatch_semaphore_wait()` when using an HTTP-proxy on macOS. ([#1077](https://github.com/getsentry/sentry-native/pull/1077), [crashpad#111](https://github.com/getsentry/crashpad/pull/111))
12+
- Emit `transaction.data` inside `context.trace.data`. ([#1075](https://github.com/getsentry/sentry-native/pull/1075))
1213

1314
**Thank you**:
1415

src/sentry_core.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,9 @@ sentry_transaction_finish(sentry_transaction_t *opaque_tx)
934934
sentry_value_t trace_context
935935
= sentry__value_get_trace_context(opaque_tx->inner);
936936
sentry_value_t contexts = sentry_value_new_object();
937+
sentry_value_set_by_key(
938+
trace_context, "data", sentry_value_get_by_key(tx, "data"));
939+
sentry_value_incref(sentry_value_get_by_key(tx, "data"));
937940
sentry_value_set_by_key(contexts, "trace", trace_context);
938941
sentry_value_set_by_key(tx, "contexts", contexts);
939942

@@ -944,6 +947,7 @@ sentry_transaction_finish(sentry_transaction_t *opaque_tx)
944947
sentry_value_remove_by_key(tx, "op");
945948
sentry_value_remove_by_key(tx, "description");
946949
sentry_value_remove_by_key(tx, "status");
950+
sentry_value_remove_by_key(tx, "data");
947951

948952
sentry__transaction_decref(opaque_tx);
949953

src/sentry_scope.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,12 +318,20 @@ sentry__scope_apply_to_event(const sentry_scope_t *scope,
318318

319319
// prep contexts sourced from scope; data about transaction on scope needs
320320
// to be extracted and inserted
321-
sentry_value_t scope_trace = sentry__value_get_trace_context(
322-
sentry__get_span_or_transaction(scope));
321+
sentry_value_t scoped_txn_or_span = sentry__get_span_or_transaction(scope);
322+
sentry_value_t scope_trace
323+
= sentry__value_get_trace_context(scoped_txn_or_span);
323324
if (!sentry_value_is_null(scope_trace)) {
324325
if (sentry_value_is_null(contexts)) {
325326
contexts = sentry_value_new_object();
326327
}
328+
sentry_value_t scoped_txn_or_span_data
329+
= sentry_value_get_by_key(scoped_txn_or_span, "data");
330+
if (!sentry_value_is_null(scoped_txn_or_span_data)) {
331+
sentry_value_incref(scoped_txn_or_span_data);
332+
sentry_value_set_by_key(
333+
scope_trace, "data", scoped_txn_or_span_data);
334+
}
327335
sentry_value_set_by_key(contexts, "trace", scope_trace);
328336
}
329337

src/sentry_tracing.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ sentry_transaction_set_data(
578578
}
579579
}
580580

581-
static const char txn_data_key[] = "extra";
581+
static const char txn_data_key[] = "data";
582582
static const size_t txn_data_key_len = sizeof(txn_data_key) - 1;
583583

584584
void

tests/test_integration_http.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,6 @@ def test_transaction_only(cmake, httpserver, build_args):
544544
assert_meta(
545545
envelope,
546546
transaction="little.teapot",
547-
transaction_data={"url": "https://example.com"},
548547
)
549548

550549
# Extract the one-and-only-item
@@ -575,6 +574,8 @@ def test_transaction_only(cmake, httpserver, build_args):
575574
timestamp = time.strptime(payload["timestamp"], RFC3339_FORMAT)
576575
assert timestamp >= start_timestamp
577576

577+
assert trace_context["data"] == {"url": "https://example.com"}
578+
578579

579580
def test_capture_minidump(cmake, httpserver):
580581
tmp_path = cmake(["sentry_example"], {"SENTRY_BACKEND": "none"})

tests/unit/test_tracing.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,10 +1089,10 @@ SENTRY_TEST(txn_data)
10891089

10901090
sentry_transaction_set_data(
10911091
txn, "os.name", sentry_value_new_string("Linux"));
1092-
check_after_set(txn->inner, "extra", "os.name", "Linux");
1092+
check_after_set(txn->inner, "data", "os.name", "Linux");
10931093

10941094
sentry_transaction_remove_data(txn, "os.name");
1095-
check_after_remove(txn->inner, "extra", "os.name");
1095+
check_after_remove(txn->inner, "data", "os.name");
10961096

10971097
sentry__transaction_decref(txn);
10981098
}
@@ -1139,10 +1139,10 @@ SENTRY_TEST(txn_data_n)
11391139
sentry_value_t data_value
11401140
= sentry_value_new_string_n(data_v, sizeof(data_v));
11411141
sentry_transaction_set_data_n(txn, data_k, sizeof(data_k), data_value);
1142-
check_after_set(txn->inner, "extra", "os.name", "Linux");
1142+
check_after_set(txn->inner, "data", "os.name", "Linux");
11431143

11441144
sentry_transaction_remove_data_n(txn, data_k, sizeof(data_k));
1145-
check_after_remove(txn->inner, "extra", "os.name");
1145+
check_after_remove(txn->inner, "data", "os.name");
11461146

11471147
sentry__transaction_decref(txn);
11481148
}

0 commit comments

Comments
 (0)