Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit 4173983

Browse files
authored
Add request object influenced sampling option (#182)
Request object influenced sampling also allows us to implement blacklist/whitelist features.
1 parent 18ddbd7 commit 4173983

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

trace/HTTP.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,43 @@ known attributes/labels on supported tracing backends.
117117
| "http.route" | "http.route" | "http.route" | "/http/route" |
118118
| "http.user_agent" | "http.user_agent" | "http.user_agent" | "/http/user_agent" |
119119
| "http.status_code" | "http.status_code" | "http.status_code" | "/http/status_code" |
120+
121+
## Sampling
122+
123+
There are two ways to control the `Sampler` used:
124+
* Controlling the global default `Sampler` via [TraceConfig](https://github.com/census-instrumentation/opencensus-specs/blob/master/trace/TraceConfig.md).
125+
* Pass a specific `Sampler` as an option to the HTTP plugin. Plugins should support setting
126+
a sampler per HTTP request.
127+
128+
Example cases where per-request sampling is useful:
129+
130+
- Having different sampling policy per route
131+
- Having different sampling policy per method
132+
- Filtering out certain paths (e.g. health endpoints) to disable tracing
133+
- Always sampling critical paths
134+
- Sampling based on the custom request header or query parameter
135+
136+
In the following Go example, incoming and outgoing request objects can
137+
dynamically inspected to set a sampler.
138+
139+
For outgoing requests:
140+
141+
```go
142+
type Transport struct {
143+
// GetStartOptions allows to set start options per request.
144+
GetStartOptions func(*http.Request) trace.StartOptions
145+
146+
// ...
147+
}
148+
```
149+
150+
For incoming requests:
151+
152+
```go
153+
type Handler struct {
154+
// GetStartOptions allows to set start options per request.
155+
GetStartOptions func(*http.Request) trace.StartOptions
156+
157+
// ...
158+
}
159+
```

0 commit comments

Comments
 (0)