Skip to content

Commit 0435b5e

Browse files
committed
add sentry_scope_set_trace + _n
1 parent 3d6b340 commit 0435b5e

File tree

5 files changed

+47
-27
lines changed

5 files changed

+47
-27
lines changed

include/sentry.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,6 +1670,11 @@ SENTRY_API void sentry_set_trace(
16701670
const char *trace_id, const char *parent_span_id);
16711671
SENTRY_API void sentry_set_trace_n(const char *trace_id, size_t trace_id_len,
16721672
const char *parent_span_id, size_t parent_span_id_len);
1673+
SENTRY_API void sentry_scope_set_trace(
1674+
sentry_scope_t *scope, const char *trace_id, const char *parent_span_id);
1675+
SENTRY_API void sentry_scope_set_trace_n(sentry_scope_t *scope,
1676+
const char *trace_id, size_t trace_id_len, const char *parent_span_id,
1677+
size_t parent_span_id_len);
16731678

16741679
/**
16751680
* Sets the transaction.

src/sentry_core.c

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -858,14 +858,6 @@ sentry_set_context_n(const char *key, size_t key_len, sentry_value_t value)
858858
}
859859
}
860860

861-
void
862-
sentry__set_propagation_context(const char *key, sentry_value_t value)
863-
{
864-
SENTRY_WITH_SCOPE_MUT (scope) {
865-
sentry_value_set_by_key(scope->propagation_context, key, value);
866-
}
867-
}
868-
869861
void
870862
sentry_remove_context(const char *key)
871863
{
@@ -921,30 +913,18 @@ sentry_remove_fingerprint(void)
921913
void
922914
sentry_set_trace(const char *trace_id, const char *parent_span_id)
923915
{
924-
sentry_set_trace_n(trace_id, sentry__guarded_strlen(trace_id),
925-
parent_span_id, sentry__guarded_strlen(parent_span_id));
916+
SENTRY_WITH_SCOPE_MUT (scope) {
917+
sentry_scope_set_trace(scope, trace_id, parent_span_id);
918+
}
926919
}
927920

928921
void
929922
sentry_set_trace_n(const char *trace_id, size_t trace_id_len,
930923
const char *parent_span_id, size_t parent_span_id_len)
931924
{
932925
SENTRY_WITH_SCOPE_MUT (scope) {
933-
sentry_value_t context = sentry_value_new_object();
934-
935-
sentry_value_set_by_key(
936-
context, "type", sentry_value_new_string("trace"));
937-
938-
sentry_value_set_by_key(context, "trace_id",
939-
sentry_value_new_string_n(trace_id, trace_id_len));
940-
sentry_value_set_by_key(context, "parent_span_id",
941-
sentry_value_new_string_n(parent_span_id, parent_span_id_len));
942-
943-
sentry_uuid_t span_id = sentry_uuid_new_v4();
944-
sentry_value_set_by_key(
945-
context, "span_id", sentry__value_new_span_uuid(&span_id));
946-
947-
sentry__set_propagation_context("trace", context);
926+
sentry_scope_set_trace_n(
927+
scope, trace_id, trace_id_len, parent_span_id, parent_span_id_len);
948928
}
949929
}
950930

src/sentry_core.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ sentry_options_t *sentry__options_lock(void);
120120
*/
121121
void sentry__options_unlock(void);
122122

123-
void sentry__set_propagation_context(const char *key, sentry_value_t value);
124-
125123
#define SENTRY_WITH_OPTIONS(Options) \
126124
for (const sentry_options_t *Options = sentry__options_getref(); Options; \
127125
sentry_options_free((sentry_options_t *)Options), Options = NULL)

src/sentry_scope.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,41 @@ sentry_scope_set_fingerprint_n(
624624
va_end(va);
625625
}
626626

627+
void
628+
sentry__scope_set_propagation_context(
629+
sentry_scope_t *scope, const char *key, sentry_value_t value)
630+
{
631+
sentry_value_set_by_key(scope->propagation_context, key, value);
632+
}
633+
634+
void
635+
sentry_scope_set_trace(
636+
sentry_scope_t *scope, const char *trace_id, const char *parent_span_id)
637+
{
638+
sentry_scope_set_trace_n(scope, trace_id, sentry__guarded_strlen(trace_id),
639+
parent_span_id, sentry__guarded_strlen(parent_span_id));
640+
}
641+
642+
void
643+
sentry_scope_set_trace_n(sentry_scope_t *scope, const char *trace_id,
644+
size_t trace_id_len, const char *parent_span_id, size_t parent_span_id_len)
645+
{
646+
sentry_value_t context = sentry_value_new_object();
647+
648+
sentry_value_set_by_key(context, "type", sentry_value_new_string("trace"));
649+
650+
sentry_value_set_by_key(
651+
context, "trace_id", sentry_value_new_string_n(trace_id, trace_id_len));
652+
sentry_value_set_by_key(context, "parent_span_id",
653+
sentry_value_new_string_n(parent_span_id, parent_span_id_len));
654+
655+
sentry_uuid_t span_id = sentry_uuid_new_v4();
656+
sentry_value_set_by_key(
657+
context, "span_id", sentry__value_new_span_uuid(&span_id));
658+
659+
sentry__scope_set_propagation_context(scope, "trace", context);
660+
}
661+
627662
void
628663
sentry_scope_set_transaction(sentry_scope_t *scope, const char *transaction)
629664
{

src/sentry_scope.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ void sentry__scope_set_fingerprint_va(
8585
sentry_scope_t *scope, const char *fingerprint, va_list va);
8686
void sentry__scope_set_fingerprint_nva(sentry_scope_t *scope,
8787
const char *fingerprint, size_t fingerprint_len, va_list va);
88+
void sentry__scope_set_propagation_context(
89+
sentry_scope_t *scope, const char *type, sentry_value_t context);
8890

8991
/**
9092
* These are convenience macros to automatically lock/unlock the global scope

0 commit comments

Comments
 (0)