File tree Expand file tree Collapse file tree 2 files changed +39
-1
lines changed
src/includes/performance/traces-sampler-as-sampler Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change
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
+ ```
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ options.TracesSampler = context =>
17
17
}
18
18
19
19
// Otherwise, sample based on URL (exposed through custom sampling context)
20
- return context .CustomSamplingContext .GetValueOrDefault (" url " ) switch
20
+ return context .CustomSamplingContext .GetValueOrDefault (" __HttpPath " ) switch
21
21
{
22
22
// These are important - take a big sample
23
23
" /payment" => 0 . 5 ,
You can’t perform that action at this time.
0 commit comments