From 0bef57a6002e2fcd0e878358e5152a66a2216be2 Mon Sep 17 00:00:00 2001 From: Sergey Lanzman Date: Fri, 24 Aug 2018 20:51:56 +0300 Subject: [PATCH] add SetUntraceableEndpoints for add UntraceableEndpoints like Health urls --- plugin/ochttp/client.go | 2 +- plugin/ochttp/server.go | 2 +- plugin/ochttp/trace.go | 26 +++++++++++++++++++------- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/plugin/ochttp/client.go b/plugin/ochttp/client.go index 68faf24f5..38d451575 100644 --- a/plugin/ochttp/client.go +++ b/plugin/ochttp/client.go @@ -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. diff --git a/plugin/ochttp/server.go b/plugin/ochttp/server.go index 72aa8c2d7..c6b9da51e 100644 --- a/plugin/ochttp/server.go +++ b/plugin/ochttp/server.go @@ -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 diff --git a/plugin/ochttp/trace.go b/plugin/ochttp/trace.go index 980b6390f..351a11cb7 100644 --- a/plugin/ochttp/trace.go +++ b/plugin/ochttp/trace.go @@ -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 ( @@ -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