diff --git a/src/sentry_tracing.c b/src/sentry_tracing.c index 42a3f3af7..3bf5f9e38 100644 --- a/src/sentry_tracing.c +++ b/src/sentry_tracing.c @@ -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 } diff --git a/tests/unit/test_tracing.c b/tests/unit/test_tracing.c index 2c7e638c0..9f030ed93 100644 --- a/tests/unit/test_tracing.c +++ b/tests/unit/test_tracing.c @@ -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)));