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

Commit

Permalink
Update trace.go
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeylanzman committed Aug 25, 2018
1 parent 588ded3 commit 514ed93
Show file tree
Hide file tree
Showing 3 changed files with 16 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
21 changes: 14 additions & 7 deletions plugin/ochttp/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,13 @@ import (

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


// 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.
var HealthEndpoints = map[string]bool{
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 @@ -215,8 +212,18 @@ var codeToStr = map[int32]string{
trace.StatusCodeUnauthenticated: `"UNAUTHENTICATED"`,
}

func isHealthEndpoint(path string) bool {
if _, exist := HealthEndpoints[path]; exist {
// 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 514ed93

Please sign in to comment.