From 799de273d1d7f31def79afd752a7693527ce8c0e Mon Sep 17 00:00:00 2001 From: JBD Date: Fri, 21 Sep 2018 17:13:46 -0700 Subject: [PATCH 1/2] Add request object influenced sampling option Request object influenced sampling also allows us to implement blacklist/whitelist features. --- trace/HTTP.md | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/trace/HTTP.md b/trace/HTTP.md index 577da08..b427cb1 100644 --- a/trace/HTTP.md +++ b/trace/HTTP.md @@ -117,3 +117,43 @@ known attributes/labels on supported tracing backends. | "http.route" | "http.route" | "http.route" | "/http/route" | | "http.user_agent" | "http.user_agent" | "http.user_agent" | "/http/user_agent" | | "http.status_code" | "http.status_code" | "http.status_code" | "/http/status_code" | + +## Sampling + +There are two ways to control the `Sampler` used: +* Controlling the global default `Sampler` via [TraceConfig](https://github.com/census-instrumentation/opencensus-specs/blob/master/trace/TraceConfig.md). +* Pass a specific `Sampler` as an option to the HTTP plugin. Plugins should support setting +a sampler per HTTP request. + +Example cases where per-request sampling is useful: + +- Having different sampling policy per route +- Having different sampling policy per method +- Filtering out certain paths (e.g. health endpoints) to disable tracing +- Always sampling critical paths +- Sampling based on the custom request header or query parameter + +In the following Go example, incoming and outgoing request objects can +dynamically inspected to set a sampler. + +For outgoing requests: + +``` +type Transport struct { + // GetStartOptions allows to set start options per request. + GetStartOptions func(*http.Request) trace.StartOptions + + // ... +} +``` + +For incoming requests: + +``` +type Handler struct { + // GetStartOptions allows to set start options per request. + GetStartOptions func(*http.Request) trace.StartOptions + + // ... +} +``` From 7ae3810847d951ae79d0576afc3fd2cf0e020862 Mon Sep 17 00:00:00 2001 From: JBD Date: Mon, 8 Oct 2018 10:49:33 -0700 Subject: [PATCH 2/2] feedback --- trace/HTTP.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/trace/HTTP.md b/trace/HTTP.md index b427cb1..4dd96c1 100644 --- a/trace/HTTP.md +++ b/trace/HTTP.md @@ -138,22 +138,22 @@ dynamically inspected to set a sampler. For outgoing requests: -``` +```go type Transport struct { // GetStartOptions allows to set start options per request. GetStartOptions func(*http.Request) trace.StartOptions - // ... + // ... } ``` For incoming requests: -``` +```go type Handler struct { // GetStartOptions allows to set start options per request. GetStartOptions func(*http.Request) trace.StartOptions - // ... + // ... } ```