|
1 |
| -```javascript |
| 1 | +```typescript |
| 2 | +// The shape of samplingContext that is passed to the tracesSampler function |
| 3 | +interface SamplingContext { |
| 4 | + // Name of the span |
| 5 | + name: string; |
| 6 | + // Initial attributes of the span |
| 7 | + attributes: SpanAttributes | undefined; |
| 8 | + // If the parent span was sampled - undefined if there is no parent span |
| 9 | + parentSampled: boolean | undefined; |
| 10 | +} |
| 11 | + |
2 | 12 | Sentry.init({
|
3 | 13 | // ...
|
4 | 14 |
|
5 |
| - tracesSampler: samplingContext => { |
6 |
| - // Examine provided context data (including parent decision, if any) along |
7 |
| - // with anything in the global namespace to compute the sample rate or |
8 |
| - // sampling decision for this transaction |
| 15 | + tracesSampler: ({ name, attributes, parentSampled }) => { |
| 16 | + // Do not sample health checks ever |
| 17 | + if (name.includes("healthcheck")) { |
| 18 | + // Drop this completelty, by setting its sample rate to 0% |
| 19 | + return 0; |
| 20 | + } |
9 | 21 |
|
10 |
| - if ("...") { |
11 |
| - // These are important - take a big sample |
| 22 | + // These are important - take a big sample |
| 23 | + if (name.includes("auth")) { |
12 | 24 | return 1;
|
13 |
| - } else if ("...") { |
14 |
| - // These are less important or happen much more frequently - only take 1% |
| 25 | + } |
| 26 | + |
| 27 | + // These are less important or happen much more frequently - only take 1% |
| 28 | + if (name.includes("comment")) { |
15 | 29 | return 0.01;
|
16 |
| - } else if ("...") { |
17 |
| - // These aren't something worth tracking - drop all transactions like this |
18 |
| - return 0; |
19 |
| - } else { |
20 |
| - // Default sample rate |
21 |
| - return 0.5; |
22 | 30 | }
|
23 |
| - }; |
| 31 | + |
| 32 | + // Continue trace decision, if there is any parentSampled information |
| 33 | + if (typeof parentSampled === "boolean") { |
| 34 | + return parentSampled; |
| 35 | + } |
| 36 | + |
| 37 | + // Else, use default sample rate |
| 38 | + return 0.5; |
| 39 | + }, |
24 | 40 | });
|
25 | 41 | ```
|
0 commit comments