Skip to content

Commit bdf502c

Browse files
authored
test(dsc): add integration test for rate propagation across orgs (#4630)
Wrote this integration test while confirming my understanding of #4625. It confirms that when the DSC and envelope's org IDs disagree, the DSC is recreated but the original sample rate is propagated. I don't think this case is quite covered by existing integration tests.
1 parent bb0192b commit bdf502c

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

tests/integration/test_envelope.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,3 +478,44 @@ def get_project_config():
478478
envelopes.append(events_consumer.get_event(timeout=2))
479479
events_consumer.assert_empty()
480480
assert len(envelopes) == envelope_qty
481+
482+
483+
def test_sample_rate_propagates_across_orgs(
484+
mini_sentry,
485+
relay_with_processing,
486+
transactions_consumer,
487+
):
488+
events_consumer = transactions_consumer()
489+
490+
relay = relay_with_processing()
491+
492+
upstream_project_config = mini_sentry.add_full_project_config(
493+
42, extra={"organizationId": 2}
494+
)
495+
upstream_public_key = upstream_project_config["publicKeys"][0]["publicKey"]
496+
497+
downstream_project_id = 43
498+
downstream_project_config = mini_sentry.add_full_project_config(
499+
downstream_project_id
500+
)
501+
downstream_public_key = downstream_project_config["publicKeys"][0]["publicKey"]
502+
503+
transaction_item = generate_transaction_item()
504+
dsc = {
505+
"trace_id": transaction_item["contexts"]["trace"]["trace_id"],
506+
"public_key": upstream_public_key,
507+
"sample_rate": 0.1,
508+
"transaction": "upstream_transaction_name",
509+
"environment": "production",
510+
}
511+
envelope = Envelope(headers={"trace": dsc})
512+
envelope.add_transaction(transaction_item)
513+
relay.send_envelope(downstream_project_id, envelope)
514+
515+
event, _ = events_consumer.get_event()
516+
517+
# Because the organization IDs mismatch, the DSC should be regenerated
518+
assert event["_dsc"]["public_key"] == downstream_public_key
519+
assert event["_dsc"]["transaction"] == transaction_item["transaction"]
520+
# But, the given sample rate should be respected
521+
assert event["_dsc"]["sample_rate"] == "0.1"

0 commit comments

Comments
 (0)