Skip to content

Commit

Permalink
Test that transaction_sample_rate supports remote config
Browse files Browse the repository at this point in the history
  • Loading branch information
basepi committed Mar 27, 2020
1 parent 8595816 commit 49ce328
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/client/client_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,38 @@ def test_transaction_sampling(elasticapm_client, not_so_random):
assert transaction["sampled"] or not "context" in transaction


def test_transaction_sample_rate_dynamic(elasticapm_client, not_so_random):
elasticapm_client.config.update(version="1", transaction_sample_rate=0.4)
for i in range(10):
elasticapm_client.begin_transaction("test_type")
with elasticapm.capture_span("xyz"):
pass
elasticapm_client.end_transaction("test")

transactions = elasticapm_client.events[TRANSACTION]
spans_per_transaction = defaultdict(list)
for span in elasticapm_client.events[SPAN]:
spans_per_transaction[span["transaction_id"]].append(span)

# seed is fixed by not_so_random fixture
assert len([t for t in transactions if t["sampled"]]) == 3
for transaction in transactions:
assert transaction["sampled"] or not transaction["id"] in spans_per_transaction
assert transaction["sampled"] or not "context" in transaction

elasticapm_client.config.update(version="1", transaction_sample_rate=1.0)
for i in range(5):
elasticapm_client.begin_transaction("test_type")
with elasticapm.capture_span("xyz"):
pass
elasticapm_client.end_transaction("test")

transactions = elasticapm_client.events[TRANSACTION]

# seed is fixed by not_so_random fixture
assert len([t for t in transactions if t["sampled"]]) == 8


@pytest.mark.parametrize("elasticapm_client", [{"transaction_max_spans": 5}], indirect=True)
def test_transaction_max_spans(elasticapm_client):
elasticapm_client.begin_transaction("test_type")
Expand Down

0 comments on commit 49ce328

Please sign in to comment.