Skip to content

Commit 66ec2e8

Browse files
authored
fix: don't label upstream-unsampled transactions as backpressure (#5841)
* fix: don't label upstream-unsampled transactions as backpressure When StartTransaction runs without a TracesSampler and the sampling decision comes from the incoming trace (context.IsSampled is false), the discard reason was computed as backpressure whenever sampleRand < TracesSampleRate, even while the backpressure monitor was healthy (downsample factor 1). That comparison only implies downsampling for a decision the SDK makes itself; for an upstream decision it does not. Report such drops as sample_rate instead. * test: fold upstream-unsampled cases into backpressure theory Add an isSampledUpstream parameter to StartTransaction_Backpressure_SetsDiscardReason with two extra rows (sampler branch keeps backpressure on an upstream not-sampled decision; options branch reports sample_rate) and drop the now-redundant separate Fact. Signed-off-by: Vladimir Babin <vovababin@gmail.com> --------- Signed-off-by: Vladimir Babin <vovababin@gmail.com>
1 parent d4a1de1 commit 66ec2e8

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

‎src/Sentry/Internal/Hub.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ internal ITransactionTracer StartTransaction(
245245
{
246246
// If sampling out is only a result of the downsampling then we specify the reason as backpressure
247247
// management... otherwise the event would have been sampled out anyway, so it's just regular sampling.
248-
discardReason = sampleRand < optionsSampleRate ? DiscardReason.Backpressure : DiscardReason.SampleRate;
248+
discardReason = context.IsSampled is null && sampleRand < optionsSampleRate ? DiscardReason.Backpressure : DiscardReason.SampleRate;
249249
}
250250

251251
if (context.IsSampled is null && _options.TracesSampleRate is not null)

‎test/Sentry.Tests/HubTests.cs‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,14 +1033,16 @@ public void StartTransaction_Backpressure_Downsamples(bool usesTracesSampler)
10331033
}
10341034

10351035
[Theory]
1036-
[InlineData(true, 0.4f, "backpressure")]
1037-
[InlineData(true, 0.6f, "sample_rate")]
1038-
[InlineData(false, 0.4f, "backpressure")]
1039-
[InlineData(false, 0.6f, "sample_rate")]
1040-
public void StartTransaction_Backpressure_SetsDiscardReason(bool usesTracesSampler, double sampleRand, string discardReason)
1036+
[InlineData(true, null, 0.4f, "backpressure")]
1037+
[InlineData(true, null, 0.6f, "sample_rate")]
1038+
[InlineData(false, null, 0.4f, "backpressure")]
1039+
[InlineData(false, null, 0.6f, "sample_rate")]
1040+
[InlineData(true, false, 0.4f, "backpressure")]
1041+
[InlineData(false, false, 0.4f, "sample_rate")]
1042+
public void StartTransaction_Backpressure_SetsDiscardReason(bool usesTracesSampler, bool? isSampledUpstream, double sampleRand, string discardReason)
10411043
{
10421044
// Arrange
1043-
var transactionContext = new TransactionContext("name", "operation");
1045+
var transactionContext = new TransactionContext("name", "operation", isSampled: isSampledUpstream);
10441046

10451047
var clock = new MockClock(DateTimeOffset.UtcNow);
10461048
_fixture.SampleRandHelper = Substitute.For<ISampleRandHelper>();

0 commit comments

Comments
 (0)