-
-
Notifications
You must be signed in to change notification settings - Fork 171
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
18d60d0
commit ceddb01
Showing
8 changed files
with
147 additions
and
41 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(); | ||
|
@@ -128,23 +133,23 @@ SENTRY_TEST(basic_function_transport_transaction) | |
|
||
sentry_value_t transaction = sentry_value_new_transaction_context( | ||
"How could you", "Don't capture this."); | ||
transaction = sentry_transaction_start(transaction); | ||
sentry_uuid_t event_id = sentry_transaction_finish(transaction); | ||
sentry_transaction_start(transaction); | ||
sentry_uuid_t event_id = sentry_transaction_finish(); | ||
// TODO: `sentry_capture_event` acts as if the event was sent if user | ||
// consent was not given | ||
TEST_CHECK(!sentry_uuid_is_nil(&event_id)); | ||
sentry_user_consent_give(); | ||
|
||
transaction = sentry_value_new_transaction_context("honk", "beep"); | ||
transaction = sentry_transaction_start(transaction); | ||
event_id = sentry_transaction_finish(transaction); | ||
sentry_transaction_start(transaction); | ||
event_id = sentry_transaction_finish(); | ||
TEST_CHECK(!sentry_uuid_is_nil(&event_id)); | ||
|
||
sentry_user_consent_revoke(); | ||
transaction = sentry_value_new_transaction_context( | ||
"How could you again", "Don't capture this either."); | ||
transaction = sentry_transaction_start(transaction); | ||
event_id = sentry_transaction_finish(transaction); | ||
sentry_transaction_start(transaction); | ||
event_id = sentry_transaction_finish(); | ||
// TODO: `sentry_capture_event` acts as if the event was sent if user | ||
// consent was not given | ||
TEST_CHECK(!sentry_uuid_is_nil(&event_id)); | ||
|
@@ -173,16 +178,16 @@ SENTRY_TEST(transport_sampling_transactions) | |
for (int i = 0; i < 100; i++) { | ||
sentry_value_t transaction | ||
= sentry_value_new_transaction_context("honk", "beep"); | ||
transaction = sentry_transaction_start(transaction); | ||
sentry_uuid_t event_id = sentry_transaction_finish(transaction); | ||
sentry_transaction_start(transaction); | ||
sentry_uuid_t event_id = sentry_transaction_finish(); | ||
if (!sentry_uuid_is_nil(&event_id)) { | ||
sent_transactions += 1; | ||
} | ||
} | ||
|
||
sentry_close(); | ||
|
||
// well, its random after all | ||
// exact value is nondeterministic because of rng | ||
TEST_CHECK(called_transport > 50 && called_transport < 100); | ||
TEST_CHECK(called_transport == sent_transactions); | ||
} | ||
|
@@ -216,12 +221,62 @@ SENTRY_TEST(transactions_skip_before_send) | |
|
||
sentry_value_t transaction | ||
= sentry_value_new_transaction_context("honk", "beep"); | ||
transaction = sentry_transaction_start(transaction); | ||
sentry_uuid_t event_id = sentry_transaction_finish(transaction); | ||
sentry_transaction_start(transaction); | ||
sentry_uuid_t event_id = sentry_transaction_finish(); | ||
TEST_CHECK(!sentry_uuid_is_nil(&event_id)); | ||
|
||
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_context("wow!", NULL); | ||
sentry_transaction_start(tx_cxt); | ||
|
||
sentry_value_t scope_tx = sentry__scope_get_span(); | ||
CHECK_STRING_PROPERTY(scope_tx, "transaction", "wow!"); | ||
|
||
sentry_uuid_t event_id = sentry_transaction_finish(); | ||
scope_tx = sentry__scope_get_span(); | ||
TEST_CHECK(sentry_value_is_null(scope_tx)); | ||
TEST_CHECK(!sentry_uuid_is_nil(&event_id)); | ||
|
||
tx_cxt = sentry_value_new_transaction_context("whoa!", NULL); | ||
sentry_transaction_start(tx_cxt); | ||
tx_cxt = sentry_value_new_transaction_context("wowee!", NULL); | ||
sentry_transaction_start(tx_cxt); | ||
scope_tx = sentry__scope_get_span(); | ||
CHECK_STRING_PROPERTY(scope_tx, "transaction", "wowee!"); | ||
event_id = sentry_transaction_finish(); | ||
TEST_CHECK(!sentry_uuid_is_nil(&event_id)); | ||
|
||
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