Skip to content

Commit d59203c

Browse files
update url reference (#5286)
1 parent d3193f5 commit d59203c

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
```csharp
2+
using Sentry;
3+
4+
// Add this to the SDK initialization callback
5+
// To set a uniform sample rate
6+
options.TracesSampleRate = 1.0;
7+
8+
// OR: Determine traces sample rate based on the sampling context
9+
options.TracesSampler = context =>
10+
{
11+
// If this is the continuation of a trace, just use that decision (rate controlled by the caller)
12+
if (context.TransactionContext.IsParentSampled is not null)
13+
{
14+
return context.TransactionContext.IsParentSampled.Value
15+
? 1.0
16+
: 0.0;
17+
}
18+
19+
// Otherwise, sample based on URL (exposed through custom sampling context)
20+
return context.CustomSamplingContext.GetValueOrDefault("url") switch
21+
{
22+
// These are important - take a big sample
23+
"/payment" => 0.5,
24+
25+
// Search is less important and happen much more frequently - only take 1%
26+
"/search" => 0.01,
27+
28+
// The health check endpoint is just noise - drop all transactions
29+
"/health" => 0.0,
30+
31+
// Default sample rate
32+
_ => 0.1
33+
34+
// Or return null to fallback to options.TracesSampleRate (1.0 in this case)
35+
// _ => null
36+
};
37+
};
38+
```

src/includes/performance/traces-sampler-as-sampler/dotnet.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ options.TracesSampler = context =>
1717
}
1818

1919
// Otherwise, sample based on URL (exposed through custom sampling context)
20-
return context.CustomSamplingContext.GetValueOrDefault("url") switch
20+
return context.CustomSamplingContext.GetValueOrDefault("__HttpPath") switch
2121
{
2222
// These are important - take a big sample
2323
"/payment" => 0.5,

0 commit comments

Comments
 (0)