-
-
Notifications
You must be signed in to change notification settings - Fork 169
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(tracing): Groundwork to add tracing context to all events #617
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fd0e038
feat(tracing): Groundwork to add tracing context to all events
relaxolotl d5c202b
fix leaks
relaxolotl f61f237
forgot the implementation
relaxolotl 2b4b705
deal with unused param for now
relaxolotl def13ae
no need to free a null
relaxolotl 1751cdb
properly bookend #defines
relaxolotl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "sentry_sync.h" | ||
|
||
sentry_value_t | ||
sentry__span_get_trace_context(sentry_value_t span) | ||
{ | ||
if (sentry_value_is_null(span) | ||
|| sentry_value_is_null(sentry_value_get_by_key(span, "trace_id")) | ||
|| sentry_value_is_null(sentry_value_get_by_key(span, "span_id"))) { | ||
return sentry_value_new_null(); | ||
} | ||
|
||
sentry_value_t trace_context = sentry_value_new_object(); | ||
|
||
#define PLACE_VALUE(Key, Source) \ | ||
relaxolotl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
do { \ | ||
sentry_value_t src = sentry_value_get_by_key(Source, Key); \ | ||
if (!sentry_value_is_null(src)) { \ | ||
sentry_value_incref(src); \ | ||
sentry_value_set_by_key(trace_context, Key, src); \ | ||
} \ | ||
} while (0) | ||
|
||
PLACE_VALUE("trace_id", span); | ||
PLACE_VALUE("span_id", span); | ||
PLACE_VALUE("parent_span_id", span); | ||
PLACE_VALUE("op", span); | ||
PLACE_VALUE("description", span); | ||
PLACE_VALUE("status", span); | ||
|
||
return trace_context; | ||
|
||
#undef PLACE_VALUE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef SENTRY_TRACING_H_INCLUDED | ||
#define SENTRY_TRACING_H_INCLUDED | ||
|
||
#include "sentry_boot.h" | ||
#include "sentry_value.h" | ||
|
||
/** | ||
* Returns an object containing tracing information extracted from a | ||
* transaction (/span) which should be included in an event. | ||
* See https://develop.sentry.dev/sdk/event-payloads/transaction/#examples | ||
*/ | ||
sentry_value_t sentry__span_get_trace_context(sentry_value_t span); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#include "sentry_testsupport.h" | ||
#include "sentry_tracing.h" | ||
#include "sentry_uuid.h" | ||
|
||
SENTRY_TEST(basic_tracing_context) | ||
{ | ||
sentry_value_t span = sentry_value_new_object(); | ||
TEST_CHECK(sentry_value_is_null(sentry__span_get_trace_context(span))); | ||
|
||
sentry_value_set_by_key(span, "op", sentry_value_new_string("honk.beep")); | ||
TEST_CHECK(sentry_value_is_null(sentry__span_get_trace_context(span))); | ||
|
||
sentry_uuid_t trace_id = sentry_uuid_new_v4(); | ||
sentry_value_set_by_key( | ||
span, "trace_id", sentry__value_new_internal_uuid(&trace_id)); | ||
TEST_CHECK(sentry_value_is_null(sentry__span_get_trace_context(span))); | ||
|
||
sentry_uuid_t span_id = sentry_uuid_new_v4(); | ||
sentry_value_set_by_key( | ||
span, "span_id", sentry__value_new_span_uuid(&span_id)); | ||
|
||
sentry_value_t trace_context = sentry__span_get_trace_context(span); | ||
TEST_CHECK(!sentry_value_is_null(trace_context)); | ||
TEST_CHECK(!sentry_value_is_null( | ||
sentry_value_get_by_key(trace_context, "trace_id"))); | ||
TEST_CHECK(!sentry_value_is_null( | ||
sentry_value_get_by_key(trace_context, "span_id"))); | ||
|
||
const char *span_op | ||
= sentry_value_as_string(sentry_value_get_by_key(trace_context, "op")); | ||
TEST_CHECK_STRING_EQUAL(span_op, "honk.beep"); | ||
|
||
sentry_value_decref(trace_context); | ||
sentry_value_decref(span); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 description is very nice! Maybe name this
root_span
or something? Not sure what would make this less confusing.Also not sure if you want to save the innermost span somewhere as well?
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.
truth be told i'm actually not the biggest fan of calling these spans as there are subtle differences between a transaction and a span. the nice thing about using
span
here is mostly that it's consistent with the naming scheme used by other SDKs (see https://github.com/getsentry/sentry-python/blob/dd0efc08414ee2ef1a5f22d2cc4e243b54a1b455/sentry_sdk/scope.py#L81-L83).given that, i'm reluctant to use
root_span
because in theory, this "span" should be a transaction which means it actually should contain some sort of pointer to a span tree(s). there have been suggestions to call this something liketransaction_object
, which makes it less of a misnomer at the cost of giving up consistency. thoughts?i think the question you have about the innermost span might be indirectly answered by the second paragraph: the stored "span", aka the transaction should have enough info to find any given span that branches off of it if needed. i'll admit however that i don't have a very good vision of how span tree construction and management will look like yet, and i'm leaving that as a challenge to be solved a little later.
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.
+1 on
transaction_object
, why not. The comment can mention that other SDKs call this simplyspan
it is remains greppable.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's also a setter on scope that the spec explicitly requires to be named
set_span
: https://develop.sentry.dev/sdk/performance/#scope-changesgiven that this setter is meant to be internal and this suggested change's intent is to make things easier for us internally, i'd like to do this: i'm going to merge this as-is while it still uses the terminology as required by the spec and as used by all of the other SDKs. a follow-up PR can be opened up which introduces this rename of
span
totransaction_object
in the scope in addition to the introduction of aset_transaction_object()
helper to mirror the rename. we can then assess whether the rename works or makes sense or not in there.