Skip to content

Commit

Permalink
fix: Prevent filtered traces from biasing the sample rate (#1018)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AaronFriel authored and kjin committed May 6, 2019
1 parent 2cbf1c2 commit 1832473
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/tracing-policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ export class TracePolicy {
*/
shouldTrace(options: {timestamp: number, url: string, method: string}):
boolean {
return this.sampler.shouldTrace(options.timestamp) &&
this.urlFilter.shouldTrace(options.url) &&
this.methodsFilter.shouldTrace(options.method);
return this.urlFilter.shouldTrace(options.url) &&
this.methodsFilter.shouldTrace(options.method) &&
this.sampler.shouldTrace(options.timestamp);
}

static always(): TracePolicy {
Expand Down

0 comments on commit 1832473

Please sign in to comment.