Skip to content

Commit 7201536

Browse files
committed
Revert sentry_scope_set_trace/transaction
> Transactions/spans do not make sense in this setup since they aren't > cloned and cannot be retrieved to create children.
1 parent 8d4df58 commit 7201536

File tree

9 files changed

+41
-263
lines changed

9 files changed

+41
-263
lines changed

examples/example.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,6 @@ main(int argc, char **argv)
417417
sentry_value_t event = sentry_value_new_message_event(
418418
SENTRY_LEVEL_INFO, NULL, "Hello Scope!");
419419

420-
sentry_scope_set_transaction(scope, "scoped-transaction");
421-
422420
sentry_value_t default_crumb
423421
= sentry_value_new_breadcrumb(NULL, "default level is info");
424422
sentry_scope_add_breadcrumb(scope, default_crumb);

include/sentry.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,22 +1678,13 @@ SENTRY_API void sentry_set_trace(
16781678
const char *trace_id, const char *parent_span_id);
16791679
SENTRY_API void sentry_set_trace_n(const char *trace_id, size_t trace_id_len,
16801680
const char *parent_span_id, size_t parent_span_id_len);
1681-
SENTRY_API void sentry_scope_set_trace(
1682-
sentry_scope_t *scope, const char *trace_id, const char *parent_span_id);
1683-
SENTRY_API void sentry_scope_set_trace_n(sentry_scope_t *scope,
1684-
const char *trace_id, size_t trace_id_len, const char *parent_span_id,
1685-
size_t parent_span_id_len);
16861681

16871682
/**
16881683
* Sets the transaction.
16891684
*/
16901685
SENTRY_API void sentry_set_transaction(const char *transaction);
16911686
SENTRY_API void sentry_set_transaction_n(
16921687
const char *transaction, size_t transaction_len);
1693-
SENTRY_API void sentry_scope_set_transaction(
1694-
sentry_scope_t *scope, const char *transaction);
1695-
SENTRY_API void sentry_scope_set_transaction_n(
1696-
sentry_scope_t *scope, const char *transaction, size_t transaction_len);
16971688

16981689
/**
16991690
* Sets the event level.

src/sentry_core.c

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,14 @@ 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+
861869
void
862870
sentry_remove_context(const char *key)
863871
{
@@ -913,34 +921,58 @@ sentry_remove_fingerprint(void)
913921
void
914922
sentry_set_trace(const char *trace_id, const char *parent_span_id)
915923
{
916-
SENTRY_WITH_SCOPE_MUT (scope) {
917-
sentry_scope_set_trace(scope, trace_id, parent_span_id);
918-
}
924+
sentry_set_trace_n(trace_id, sentry__guarded_strlen(trace_id),
925+
parent_span_id, sentry__guarded_strlen(parent_span_id));
919926
}
920927

921928
void
922929
sentry_set_trace_n(const char *trace_id, size_t trace_id_len,
923930
const char *parent_span_id, size_t parent_span_id_len)
924931
{
925932
SENTRY_WITH_SCOPE_MUT (scope) {
926-
sentry_scope_set_trace_n(
927-
scope, trace_id, trace_id_len, parent_span_id, parent_span_id_len);
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);
928948
}
929949
}
930950

931951
void
932952
sentry_set_transaction(const char *transaction)
933953
{
934954
SENTRY_WITH_SCOPE_MUT (scope) {
935-
sentry_scope_set_transaction(scope, transaction);
955+
sentry_free(scope->transaction);
956+
scope->transaction = sentry__string_clone(transaction);
957+
958+
if (scope->transaction_object) {
959+
sentry_transaction_set_name(scope->transaction_object, transaction);
960+
}
936961
}
937962
}
938963

939964
void
940965
sentry_set_transaction_n(const char *transaction, size_t transaction_len)
941966
{
942967
SENTRY_WITH_SCOPE_MUT (scope) {
943-
sentry_scope_set_transaction_n(scope, transaction, transaction_len);
968+
sentry_free(scope->transaction);
969+
scope->transaction
970+
= sentry__string_clone_n(transaction, transaction_len);
971+
972+
if (scope->transaction_object) {
973+
sentry_transaction_set_name_n(
974+
scope->transaction_object, transaction, transaction_len);
975+
}
944976
}
945977
}
946978

src/sentry_core.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ 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+
123125
#define SENTRY_WITH_OPTIONS(Options) \
124126
for (const sentry_options_t *Options = sentry__options_getref(); Options; \
125127
sentry_options_free((sentry_options_t *)Options), Options = NULL)

src/sentry_scope.c

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -636,65 +636,6 @@ sentry_scope_set_fingerprints(
636636
scope->fingerprint = fingerprints;
637637
}
638638

639-
void
640-
sentry__scope_set_propagation_context(
641-
sentry_scope_t *scope, const char *key, sentry_value_t value)
642-
{
643-
sentry_value_set_by_key(scope->propagation_context, key, value);
644-
}
645-
646-
void
647-
sentry_scope_set_trace(
648-
sentry_scope_t *scope, const char *trace_id, const char *parent_span_id)
649-
{
650-
sentry_scope_set_trace_n(scope, trace_id, sentry__guarded_strlen(trace_id),
651-
parent_span_id, sentry__guarded_strlen(parent_span_id));
652-
}
653-
654-
void
655-
sentry_scope_set_trace_n(sentry_scope_t *scope, const char *trace_id,
656-
size_t trace_id_len, const char *parent_span_id, size_t parent_span_id_len)
657-
{
658-
sentry_value_t context = sentry_value_new_object();
659-
660-
sentry_value_set_by_key(context, "type", sentry_value_new_string("trace"));
661-
662-
sentry_value_set_by_key(
663-
context, "trace_id", sentry_value_new_string_n(trace_id, trace_id_len));
664-
sentry_value_set_by_key(context, "parent_span_id",
665-
sentry_value_new_string_n(parent_span_id, parent_span_id_len));
666-
667-
sentry_uuid_t span_id = sentry_uuid_new_v4();
668-
sentry_value_set_by_key(
669-
context, "span_id", sentry__value_new_span_uuid(&span_id));
670-
671-
sentry__scope_set_propagation_context(scope, "trace", context);
672-
}
673-
674-
void
675-
sentry_scope_set_transaction(sentry_scope_t *scope, const char *transaction)
676-
{
677-
sentry_free(scope->transaction);
678-
scope->transaction = sentry__string_clone(transaction);
679-
680-
if (scope->transaction_object) {
681-
sentry_transaction_set_name(scope->transaction_object, transaction);
682-
}
683-
}
684-
685-
void
686-
sentry_scope_set_transaction_n(
687-
sentry_scope_t *scope, const char *transaction, size_t transaction_len)
688-
{
689-
sentry_free(scope->transaction);
690-
scope->transaction = sentry__string_clone_n(transaction, transaction_len);
691-
692-
if (scope->transaction_object) {
693-
sentry_transaction_set_name_n(
694-
scope->transaction_object, transaction, transaction_len);
695-
}
696-
}
697-
698639
void
699640
sentry_scope_set_level(sentry_scope_t *scope, sentry_level_t level)
700641
{

src/sentry_scope.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ 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);
9088

9189
/**
9290
* These are convenience macros to automatically lock/unlock the global scope

tests/test_integration_http.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,5 +1187,3 @@ def test_capture_with_scope(cmake, httpserver):
11871187

11881188
assert_breadcrumb(envelope, "scoped crumb")
11891189
assert_attachment(envelope)
1190-
1191-
assert_meta(envelope, transaction="scoped-transaction")

tests/unit/test_scope.c

Lines changed: 0 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -420,76 +420,6 @@ SENTRY_TEST(scope_user)
420420
sentry_close();
421421
}
422422

423-
SENTRY_TEST(scope_transaction)
424-
{
425-
SENTRY_TEST_OPTIONS_NEW(options);
426-
sentry_init(options);
427-
428-
#define TEST_CHECK_TRANSACTION_EQUAL(event, value) \
429-
do { \
430-
sentry_value_t transaction \
431-
= sentry_value_get_by_key(event, "transaction"); \
432-
TEST_CHECK_STRING_EQUAL(sentry_value_as_string(transaction), value); \
433-
} while (0)
434-
435-
// global: "global"
436-
sentry_set_transaction("global");
437-
438-
SENTRY_WITH_SCOPE (global_scope) {
439-
// event: null
440-
sentry_value_t event = sentry_value_new_object();
441-
442-
// event <- global: "global"
443-
sentry__scope_apply_to_event(
444-
global_scope, options, event, SENTRY_SCOPE_NONE);
445-
TEST_CHECK_TRANSACTION_EQUAL(event, "global");
446-
447-
sentry_value_decref(event);
448-
}
449-
450-
SENTRY_WITH_SCOPE (global_scope) {
451-
// event: "event"
452-
sentry_value_t event = sentry_value_new_object();
453-
sentry_value_set_by_key(
454-
event, "transaction", sentry_value_new_string("event"));
455-
456-
// event <- global: "event"
457-
sentry__scope_apply_to_event(
458-
global_scope, options, event, SENTRY_SCOPE_NONE);
459-
TEST_CHECK_TRANSACTION_EQUAL(event, "event");
460-
461-
sentry_value_decref(event);
462-
}
463-
464-
SENTRY_WITH_SCOPE (global_scope) {
465-
// local: "local"
466-
sentry_scope_t *local_scope = sentry_local_scope_new();
467-
sentry_scope_set_transaction(local_scope, "local");
468-
469-
// event: "event"
470-
sentry_value_t event = sentry_value_new_object();
471-
sentry_value_set_by_key(
472-
event, "transaction", sentry_value_new_string("event"));
473-
474-
// event <- local: "event"
475-
sentry__scope_apply_to_event(
476-
local_scope, options, event, SENTRY_SCOPE_NONE);
477-
TEST_CHECK_TRANSACTION_EQUAL(event, "event");
478-
479-
// event <- global: "event"
480-
sentry__scope_apply_to_event(
481-
local_scope, options, event, SENTRY_SCOPE_NONE);
482-
TEST_CHECK_TRANSACTION_EQUAL(event, "event");
483-
484-
sentry_scope_free(local_scope);
485-
sentry_value_decref(event);
486-
}
487-
488-
#undef TEST_CHECK_TRANSACTION_EQUAL
489-
490-
sentry_close();
491-
}
492-
493423
SENTRY_TEST(scope_level)
494424
{
495425
SENTRY_TEST_OPTIONS_NEW(options);
@@ -672,113 +602,3 @@ SENTRY_TEST(scope_breadcrumbs)
672602

673603
sentry_close();
674604
}
675-
676-
static sentry_value_t
677-
event_with_trace(const char *trace_id, const char *parent_span_id)
678-
{
679-
sentry_value_t event = sentry_value_new_object();
680-
sentry_value_t trace = sentry_value_new_object();
681-
sentry_value_set_by_key(
682-
trace, "trace_id", sentry_value_new_string(trace_id));
683-
sentry_value_set_by_key(
684-
trace, "parent_span_id", sentry_value_new_string(parent_span_id));
685-
686-
sentry_value_t contexts = sentry_value_new_object();
687-
sentry_value_set_by_key(contexts, "trace", trace);
688-
sentry_value_set_by_key(event, "contexts", contexts);
689-
return event;
690-
}
691-
692-
SENTRY_TEST(scope_trace)
693-
{
694-
SENTRY_TEST_OPTIONS_NEW(options);
695-
sentry_init(options);
696-
697-
#define TEST_CHECK_TRACE_EQUAL(event, trace_id, parent_span_id) \
698-
do { \
699-
sentry_value_t contexts = sentry_value_get_by_key(event, "contexts"); \
700-
sentry_value_t trace = sentry_value_get_by_key(contexts, "trace"); \
701-
TEST_CHECK_STRING_EQUAL( \
702-
sentry_value_as_string( \
703-
sentry_value_get_by_key(trace, "trace_id")), \
704-
trace_id); \
705-
TEST_CHECK_STRING_EQUAL( \
706-
sentry_value_as_string( \
707-
sentry_value_get_by_key(trace, "parent_span_id")), \
708-
parent_span_id); \
709-
} while (0)
710-
711-
// global: "global-xid"
712-
sentry_set_trace("global-tid", "global-psid");
713-
714-
SENTRY_WITH_SCOPE (global_scope) {
715-
// event: null
716-
sentry_value_t event = sentry_value_new_object();
717-
718-
// event <- global: "global-xid"
719-
sentry__scope_apply_to_event(
720-
global_scope, options, event, SENTRY_SCOPE_NONE);
721-
TEST_CHECK_TRACE_EQUAL(event, "global-tid", "global-psid");
722-
723-
sentry_value_decref(event);
724-
}
725-
726-
SENTRY_WITH_SCOPE (global_scope) {
727-
// event: "event-xid"
728-
sentry_value_t event = event_with_trace("event-tid", "event-psid");
729-
730-
// event <- global: "event-xid"
731-
sentry__scope_apply_to_event(
732-
global_scope, options, event, SENTRY_SCOPE_NONE);
733-
TEST_CHECK_TRACE_EQUAL(event, "event-tid", "event-psid");
734-
735-
sentry_value_decref(event);
736-
}
737-
738-
SENTRY_WITH_SCOPE (global_scope) {
739-
// local: null
740-
sentry_scope_t *local_scope = sentry_local_scope_new();
741-
742-
// event: null
743-
sentry_value_t event = sentry_value_new_object();
744-
745-
// event <- local: ""
746-
sentry__scope_apply_to_event(
747-
local_scope, options, event, SENTRY_SCOPE_NONE);
748-
TEST_CHECK_TRACE_EQUAL(event, "", "");
749-
750-
// event <- global: ""
751-
sentry__scope_apply_to_event(
752-
global_scope, options, event, SENTRY_SCOPE_NONE);
753-
TEST_CHECK_TRACE_EQUAL(event, "", "");
754-
755-
sentry_scope_free(local_scope);
756-
sentry_value_decref(event);
757-
}
758-
759-
SENTRY_WITH_SCOPE (global_scope) {
760-
// local: "local-xid"
761-
sentry_scope_t *local_scope = sentry_local_scope_new();
762-
sentry_scope_set_trace(local_scope, "local-tid", "local-psid");
763-
764-
// event: "event-xid"
765-
sentry_value_t event = event_with_trace("event-tid", "event-psid");
766-
767-
// event <- local: "event-xid"
768-
sentry__scope_apply_to_event(
769-
local_scope, options, event, SENTRY_SCOPE_NONE);
770-
TEST_CHECK_TRACE_EQUAL(event, "event-tid", "event-psid");
771-
772-
// event <- global: "event-xid"
773-
sentry__scope_apply_to_event(
774-
local_scope, options, event, SENTRY_SCOPE_NONE);
775-
TEST_CHECK_TRACE_EQUAL(event, "event-tid", "event-psid");
776-
777-
sentry_scope_free(local_scope);
778-
sentry_value_decref(event);
779-
}
780-
781-
#undef TEST_CHECK_TRACE_EQUAL
782-
783-
sentry_close();
784-
}

0 commit comments

Comments
 (0)