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

add HealthEndpoints map as public #881

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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