getsentry / getsentry/sentry-dotnet
feat: Forcing a Sampling Decision
- Dominant language
- C#
- Stars
- 770
- Forks
- 248
- Avg merge
- 3d 4h
- Merged PRs (30d)
- 49
Description
### Description
We currently don't support a path where the user can (or is meant to), when starting a new transaction via `SentrySdk.StartTransaction()`, force a sampling decision, without involving `TracesSampler` nor `TracesSampleRate`.
See https://docs.sentry.io/platforms/dotnet/configuration/sampling/.
Also, in the docs we mention an API that does not exist:
```CSharp
// TransactionContext(string, string, bool) cannot be resolved
var transactionContext = new TransactionContext("GET /search", "http", true);
```
The existing `ITransactionContext.IsSampled` is intended to propagate sampling decision from upstream nodes (distributed tracing). See https://docs.sentry.io/concepts/key-terms/tracing/distributed-tracing/.
### Note
Consider: #4392
Consider: https://github.com/getsentry/sentry-dotnet/pull/4374#discussion_r2241130180
### Discussion
Hub.cs
```CSharp
if (isForcedByUserCode.HasValue)
{
sampleRate = isForcedByUserCode.GetValueOrDefault() ? 1.0 : 0.0;
isSampled = isForcedByUserCode.GetValueOrDefault();
}
else if (_options.TracesSampler is { } tracesSampler)
{
var samplingContext = new TransactionSamplingContext(
context,
customSamplingContext);
if (tracesSampler(samplingContext) is { } samplerSampleRate)
{
sampleRate = samplerSampleRate;
isSampled = SampleRandHelper.IsSampled(sampleRand, samplerSampleRate);
}
}
if (isSampled == null)
{
sampleRate = _options.TracesSampleRate ?? 0.0;
isSampled = SampleRandHelper.IsSampled(sampleRand, sampleRate.Value);
}
dynamicSamplingContext = dynamicSamplingContext?.WithSampleRate(sampleRate.Value);
```
---
Issue surfaced through #4374
Contributor guide
Assessment
This issue has not been assessed yet.