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

Commit

Permalink
add SetUntraceableEndpoints for add UntraceableEndpoints like Health …
Browse files Browse the repository at this point in the history
…urls
  • Loading branch information
sergeylanzman committed Aug 25, 2018
1 parent 71e2e3e commit 0bef57a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion plugin/ochttp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type Transport struct {
// RoundTrip implements http.RoundTripper, delegating to Base and recording stats and traces for the request.
func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) {
rt := t.base()
if isHealthEndpoint(req.URL.Path) {
if isUntraceableEndpoints(req.URL.Path) {
return rt.RoundTrip(req)
}
// TODO: remove excessive nesting of http.RoundTrippers here.
Expand Down
2 changes: 1 addition & 1 deletion plugin/ochttp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}

func (h *Handler) startTrace(w http.ResponseWriter, r *http.Request) (*http.Request, func()) {
if isHealthEndpoint(r.URL.Path) {
if isUntraceableEndpoints(r.URL.Path) {
return r, func() {}
}
var name string
Expand Down
26 changes: 19 additions & 7 deletions plugin/ochttp/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ import (

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

// Disable canonical health checking endpoints
// like /healthz and /_ah/health for now.
var untraceableEndpoints = map[string]bool{
"/healthz": true,
"/_ah/health": true,
}

// Attributes recorded on the span for the requests.
// Only trace exporters will need them.
const (
Expand Down Expand Up @@ -205,13 +212,18 @@ var codeToStr = map[int32]string{
trace.StatusCodeUnauthenticated: `"UNAUTHENTICATED"`,
}

func isHealthEndpoint(path string) bool {
// Health checking is pretty frequent and
// traces collected for health endpoints
// can be extremely noisy and expensive.
// Disable canonical health checking endpoints
// like /healthz and /_ah/health for now.
if path == "/healthz" || path == "/_ah/health" {
// Set Untraceable Endpoints like Health checking
// is pretty frequent and traces collected
// for health endpoints can be extremely noisy and expensive.
func SetUntraceableEndpoints(newUntraceableEndpoints []string) {
untraceableEndpoints = map[string]bool{}
for _, endpoint := range newUntraceableEndpoints {
untraceableEndpoints[endpoint] = true
}
}

func isUntraceableEndpoints(path string) bool {
if _, exist := untraceableEndpoints[path]; exist {
return true
}
return false
Expand Down

0 comments on commit 0bef57a

Please sign in to comment.