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

Commit 514ed93

Browse files
committed
Update trace.go
1 parent 588ded3 commit 514ed93

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

plugin/ochttp/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type Transport struct {
6363
// RoundTrip implements http.RoundTripper, delegating to Base and recording stats and traces for the request.
6464
func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) {
6565
rt := t.base()
66-
if isHealthEndpoint(req.URL.Path) {
66+
if isUntraceableEndpoints(req.URL.Path) {
6767
return rt.RoundTrip(req)
6868
}
6969
// TODO: remove excessive nesting of http.RoundTrippers here.

plugin/ochttp/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
8282
}
8383

8484
func (h *Handler) startTrace(w http.ResponseWriter, r *http.Request) (*http.Request, func()) {
85-
if isHealthEndpoint(r.URL.Path) {
85+
if isUntraceableEndpoints(r.URL.Path) {
8686
return r, func() {}
8787
}
8888
var name string

plugin/ochttp/trace.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,13 @@ import (
2828

2929
var defaultFormat propagation.HTTPFormat = &b3.HTTPFormat{}
3030

31-
32-
// Health checking is pretty frequent and
33-
// traces collected for health endpoints
34-
// can be extremely noisy and expensive.
3531
// Disable canonical health checking endpoints
3632
// like /healthz and /_ah/health for now.
37-
var HealthEndpoints = map[string]bool{
33+
var untraceableEndpoints = map[string]bool{
3834
"/healthz": true,
3935
"/_ah/health": true,
4036
}
37+
4138
// Attributes recorded on the span for the requests.
4239
// Only trace exporters will need them.
4340
const (
@@ -215,8 +212,18 @@ var codeToStr = map[int32]string{
215212
trace.StatusCodeUnauthenticated: `"UNAUTHENTICATED"`,
216213
}
217214

218-
func isHealthEndpoint(path string) bool {
219-
if _, exist := HealthEndpoints[path]; exist {
215+
// Set Untraceable Endpoints like Health checking
216+
// is pretty frequent and traces collected
217+
// for health endpoints can be extremely noisy and expensive.
218+
func SetUntraceableEndpoints(newUntraceableEndpoints []string) {
219+
untraceableEndpoints = map[string]bool{}
220+
for _, endpoint := range newUntraceableEndpoints {
221+
untraceableEndpoints[endpoint] = true
222+
}
223+
}
224+
225+
func isUntraceableEndpoints(path string) bool {
226+
if _, exist := untraceableEndpoints[path]; exist {
220227
return true
221228
}
222229
return false

0 commit comments

Comments
 (0)