-
-
Notifications
You must be signed in to change notification settings - Fork 170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add emitting of transaction data inside context trace data #1075
feat: add emitting of transaction data inside context trace data #1075
Conversation
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1075 +/- ##
==========================================
- Coverage 82.67% 82.55% -0.12%
==========================================
Files 53 53
Lines 7717 7729 +12
Branches 1213 1214 +1
==========================================
+ Hits 6380 6381 +1
- Misses 1225 1235 +10
- Partials 112 113 +1 |
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")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is one missing piece left (added a todo to the PR description): we should apply the currently scoped transaction/span "data" to every event sent inside that transaction/span here:
sentry-native/src/sentry_scope.c
Lines 321 to 328 in ffdf6ed
sentry_value_t scope_trace = sentry__value_get_trace_context( | |
sentry__get_span_or_transaction(scope)); | |
if (!sentry_value_is_null(scope_trace)) { | |
if (sentry_value_is_null(contexts)) { | |
contexts = sentry_value_new_object(); | |
} | |
sentry_value_set_by_key(contexts, "trace", scope_trace); | |
} |
If the scope_trace
isn't a null object, we can also read the "data" item of that scoped transaction/span and place it in the events trace context. Again, you must use incref
here because it will be decref
ed when sending the envelope, meaning it would be freed and no longer accessible to the transaction/span.
Removal is unnecessary since the transaction/span will continue to exist beyond the lifetime of the event.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The data item should only be added to the event if it isn't a null object in the scoped transaction/span. It doesn't make a difference in the backend (null object == non-existent key, most of the time), but there is no need to send data over the wire that signifies non-existent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a correct implementation of what you asked for? (i.e. when a transaction object exists inside the scope, we get its "data" key item and put it at the scope_trace "data" key)
sentry_value_t scope_trace = sentry__value_get_trace_context(
sentry__get_span_or_transaction(scope));
if (!sentry_value_is_null(scope_trace)) {
if (sentry_value_is_null(contexts)) {
contexts = sentry_value_new_object();
}
if (scope->transaction_object) {
sentry_value_set_by_key(scope_trace, "data",
sentry_value_get_by_key(
scope->transaction_object->inner, "data"));
sentry_value_incref(sentry_value_get_by_key(
scope->transaction_object->inner, "data"));
}
sentry_value_set_by_key(contexts, "trace", scope_trace);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use either span
or transaction
as returned from sentry__get_span_or_transaction(scope)
and don't have to retrieve the transaction specifically. Both can have data
items, and they should apply theirs to the event. If, for instance, a span should inherit its data
from the transaction, then that should happen at span creation.
@markushi, do you also apply data
when you apply the trace context to events from your scope transaction/spans? If so, do you take it solely from the transaction or also from spans?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To clarify, I would probably do something like this:
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);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@supervacuus @JoshuaMoelans Yes, we do the same but we solely take the context from the transaction:
https://github.com/getsentry/sentry-java/blob/28a11a7925b8e45bec38684f2002192787f13477/sentry/src/main/java/io/sentry/SentryClient.java#L216-L229
It's worth mentioning that at least in sentry-java
a span doesn't really have it's own trace context, it simply returns the top level txn context (see https://github.com/getsentry/sentry-java/blob/2e90ac7733c6c9b941e7c64175f3d097d1d15a37/sentry/src/main/java/io/sentry/Span.java#L170)
…t-data_joshua # Conflicts: # CHANGELOG.md
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can merge this because transaction data
is now handled as expected.
However this:
It's worth mentioning that at least in sentry-java a span doesn't really have it's own trace context, it simply returns the top level txn context (see https://github.com/getsentry/sentry-java/blob/2e90ac7733c6c9b941e7c64175f3d097d1d15a37/sentry/src/main/java/io/sentry/Span.java#L170)
is worth further inspection because we deviate quite a bit, and the current implementation of how the trace context is created (and maintained over transaction and span life cycles is insufficient).
I had a deeper look into our implementation and the one in sentry-java. I could imagine anything from only fixing the retrieval function (to choose either the scoped transaction or the transaction linked to from the scoped span) to a more involved rewrite of how we carry around and maintain the trace context. Either way, this won't happen in this PR.
fixes #1074
related to getsentry/team-sdks#95
ToDo: