-
-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tracing): Only ever allow one active transaction, stuff transact…
…ion into scope
- Loading branch information
1 parent
3faf6c8
commit c339d4f
Showing
8 changed files
with
137 additions
and
42 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
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 |
---|---|---|
@@ -1,7 +1,12 @@ | ||
#include "sentry_scope.h" | ||
#include "sentry_testsupport.h" | ||
#include "sentry_tracing.h" | ||
#include "sentry_uuid.h" | ||
|
||
#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_value_t span = sentry_value_new_object(); | ||
|
@@ -116,19 +121,19 @@ SENTRY_TEST(basic_function_transport_transaction) | |
|
||
sentry_value_t transaction | ||
= sentry_value_new_transaction("How could you", "Don't capture this."); | ||
transaction = sentry_transaction_start(transaction); | ||
sentry_transaction_finish(transaction); | ||
sentry_transaction_start(transaction); | ||
sentry_transaction_finish(); | ||
sentry_user_consent_give(); | ||
|
||
transaction = sentry_value_new_transaction("honk", "beep"); | ||
transaction = sentry_transaction_start(transaction); | ||
sentry_transaction_finish(transaction); | ||
sentry_transaction_start(transaction); | ||
sentry_transaction_finish(); | ||
|
||
sentry_user_consent_revoke(); | ||
transaction = sentry_value_new_transaction( | ||
"How could you again", "Don't capture this either."); | ||
transaction = sentry_transaction_start(transaction); | ||
sentry_transaction_finish(transaction); | ||
sentry_transaction_start(transaction); | ||
sentry_transaction_finish(); | ||
|
||
sentry_close(); | ||
|
||
|
@@ -153,13 +158,13 @@ SENTRY_TEST(transport_sampling_transactions) | |
for (int i = 0; i < 100; i++) { | ||
sentry_value_t transaction | ||
= sentry_value_new_transaction("honk", "beep"); | ||
transaction = sentry_transaction_start(transaction); | ||
sentry_transaction_finish(transaction); | ||
sentry_transaction_start(transaction); | ||
sentry_transaction_finish(); | ||
} | ||
|
||
sentry_close(); | ||
|
||
// well, its random after all | ||
// exact value is nondeterministic because of rng | ||
TEST_CHECK(called_transport > 50 && called_transport < 100); | ||
} | ||
|
||
|
@@ -191,11 +196,59 @@ SENTRY_TEST(transactions_skip_before_send) | |
sentry_init(options); | ||
|
||
sentry_value_t transaction = sentry_value_new_transaction("honk", "beep"); | ||
transaction = sentry_transaction_start(transaction); | ||
sentry_transaction_finish(transaction); | ||
sentry_transaction_start(transaction); | ||
sentry_transaction_finish(); | ||
|
||
sentry_close(); | ||
|
||
TEST_CHECK_INT_EQUAL(called_transport, 1); | ||
TEST_CHECK_INT_EQUAL(called_beforesend, 0); | ||
} | ||
|
||
static void | ||
before_transport(sentry_envelope_t *envelope, void *data) | ||
{ | ||
uint64_t *called = data; | ||
*called += 1; | ||
|
||
sentry_envelope_free(envelope); | ||
} | ||
|
||
SENTRY_TEST(multiple_transactions) | ||
{ | ||
uint64_t called_transport = 0; | ||
|
||
sentry_options_t *options = sentry_options_new(); | ||
sentry_options_set_dsn(options, "https://[email protected]/42"); | ||
|
||
sentry_transport_t *transport = sentry_transport_new(before_transport); | ||
sentry_transport_set_state(transport, &called_transport); | ||
sentry_options_set_transport(options, transport); | ||
|
||
sentry_options_set_traces_sample_rate(options, 1.0); | ||
sentry_init(options); | ||
|
||
sentry_value_t tx_cxt = sentry_value_new_transaction("wow!", NULL); | ||
sentry_transaction_start(tx_cxt); | ||
|
||
sentry_value_t scope_tx = sentry__scope_get_span(); | ||
CHECK_STRING_PROPERTY(scope_tx, "transaction", "wow!"); | ||
|
||
sentry_transaction_finish(); | ||
scope_tx = sentry__scope_get_span(); | ||
TEST_CHECK(sentry_value_is_null(scope_tx)); | ||
|
||
tx_cxt = sentry_value_new_transaction("whoa!", NULL); | ||
sentry_transaction_start(tx_cxt); | ||
tx_cxt = sentry_value_new_transaction("wowee!", NULL); | ||
sentry_transaction_start(tx_cxt); | ||
scope_tx = sentry__scope_get_span(); | ||
CHECK_STRING_PROPERTY(scope_tx, "transaction", "wowee!"); | ||
sentry_transaction_finish(); | ||
|
||
sentry_close(); | ||
|
||
TEST_CHECK_INT_EQUAL(called_transport, 2); | ||
} | ||
|
||
#undef CHECK_STRING_PROPERTY |
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