Skip to content

Commit

Permalink
feat: add emitting of transaction data inside context trace data (#1075)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
JoshuaMoelans and supervacuus authored Nov 14, 2024
1 parent 34a9901 commit 67cc95c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
**Fixes**:

- 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))
- Emit `transaction.data` inside `context.trace.data`. ([#1075](https://github.com/getsentry/sentry-native/pull/1075))

**Thank you**:

Expand Down
4 changes: 4 additions & 0 deletions src/sentry_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,9 @@ 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(
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);

Expand All @@ -944,6 +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, "data");

sentry__transaction_decref(opaque_tx);

Expand Down
12 changes: 10 additions & 2 deletions src/sentry_scope.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/sentry_tracing.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/test_integration_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"})
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/test_tracing.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 67cc95c

Please sign in to comment.