-
-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tracing): Groundwork to add tracing context to all events (#617)
This adds the appropriate stubs and fields to start storing spans on the (universal) scope. No actual logic has been added to actually support setting spans on the scope itself. The focus of this is to begin including tracing info in the context on all events if there is a transaction set on the scope. It does this fairly naively right now as the tooling to merge `sentry_value_t`s are basically nonexistent.
- Loading branch information
1 parent
aaad0e8
commit f2d1d4b
Showing
8 changed files
with
122 additions
and
3 deletions.
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) \ | ||
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