Skip to content
This repository was archived by the owner on Jan 21, 2026. It is now read-only.

Commit 1832473

Browse files
AaronFrielkjin
authored andcommitted
fix: Prevent filtered traces from biasing the sample rate (#1018)
The `URLFilter` and `MethodsFilter` implementations are side-effect free, and are safe to run in any order. However, `sampler.shouldTrace` is not, a result of `true` from it has the side effect of altering the trace window. This commit fixes this by calling the side-effecting sampler method last.
1 parent 2cbf1c2 commit 1832473

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/tracing-policy.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ export class TracePolicy {
117117
*/
118118
shouldTrace(options: {timestamp: number, url: string, method: string}):
119119
boolean {
120-
return this.sampler.shouldTrace(options.timestamp) &&
121-
this.urlFilter.shouldTrace(options.url) &&
122-
this.methodsFilter.shouldTrace(options.method);
120+
return this.urlFilter.shouldTrace(options.url) &&
121+
this.methodsFilter.shouldTrace(options.method) &&
122+
this.sampler.shouldTrace(options.timestamp);
123123
}
124124

125125
static always(): TracePolicy {

0 commit comments

Comments
 (0)