Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cleanup
Browse files Browse the repository at this point in the history
relaxolotl committed Dec 23, 2021
1 parent 953c509 commit 8969d44
Showing 2 changed files with 13 additions and 42 deletions.
49 changes: 10 additions & 39 deletions src/sentry_tracing.c
Original file line number Diff line number Diff line change
@@ -12,53 +12,24 @@ sentry__span_get_trace_context(sentry_value_t span)

sentry_value_t trace_context = sentry_value_new_object();

#define PLACE_CLONED_VALUE(Key, Source) \
#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_set_by_key( \
trace_context, Key, sentry__value_clone(src)); \
sentry_value_incref(src); \
sentry_value_set_by_key(trace_context, Key, src); \
} \
} while (0)

PLACE_CLONED_VALUE("trace_id", span);
PLACE_CLONED_VALUE("span_id", span);
PLACE_CLONED_VALUE("parent_span_id", span);
PLACE_CLONED_VALUE("op", span);
PLACE_CLONED_VALUE("description", span);
PLACE_CLONED_VALUE("status", span);
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);

// TODO: freeze this
return trace_context;

#undef PLACE_CLONED_VALUE
}

sentry_value_t
sentry__span_get_span_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 span_context = sentry_value_new_object();

#define PLACE_CLONED_VALUE(Key, Source) \
do { \
sentry_value_t src = sentry_value_get_by_key(Source, Key); \
if (!sentry_value_is_null(src)) { \
sentry_value_set_by_key( \
span_context, Key, sentry__value_clone(src)); \
} \
} while (0)

PLACE_CLONED_VALUE("trace_id", span);
PLACE_CLONED_VALUE("span_id", span);
PLACE_CLONED_VALUE("status", span);

return span_context;

#undef PLACE_CLONED_VALUE
#undef PLACE_VALUE
}
6 changes: 3 additions & 3 deletions tests/unit/test_tracing.c
Original file line number Diff line number Diff line change
@@ -3,13 +3,13 @@
#include "sentry_tracing.h"
#include "sentry_uuid.h"

#define IS_NULL(Src, Field)
sentry_value_is_null(sentry_value_get_by_key(Src, Field))
#define IS_NULL(Src, Field) \
sentry_value_is_null(sentry_value_get_by_key(Src, Field))
#define CHECK_STRING_PROPERTY(Src, Field, Expected) \
TEST_CHECK_STRING_EQUAL( \
sentry_value_as_string(sentry_value_get_by_key(Src, Field)), Expected)

SENTRY_TEST(basic_tracing_context)
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)));

0 comments on commit 8969d44

Please sign in to comment.