- Admin pprof is opt-in (AdminConfig.EnablePprof) - Client spans drop the URL query string; HostFunc bounds the host label - Config.HTTP/HTTPClient/GRPC configure the Observer's instrumentation - A panic after a partial HTTP response counts as 500 - GaugeFunc, CounterFunc and RegisterDBStats panic on duplicates - Abandoned client gRPC streams are recorded as Canceled - OTEL_EXPORTER_OTLP_PROTOCOL selects the protocol when unset - Health reports are cached for 1s; hung checks are not restarted - Environment is exported as deployment.environment.name Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
8647fdf1bb
commit
c92fd9826b
21 files changed
+457
-101
No files matched your search
+14
-5
@@ -19,6 +19,11 @@ type HTTPClientConfig struct {
|
||||
TracerProvider trace.TracerProvider // nil: global provider
|
||||
Propagator propagation.TextMapPropagator // nil: global propagator
|
||||
Buckets []float64 // latency buckets in seconds, default: prometheus.DefBuckets
|
||||
|
||||
// HostFunc returns the host metric label, default: the request URL host.
|
||||
// When hosts come from users (webhooks, fetch-by-URL) return a fixed
|
||||
// value such as "external" to keep metric cardinality bounded.
|
||||
HostFunc func(*http.Request) string
|
||||
}
|
||||
|
||||
func (c *HTTPClientConfig) defaults() {
|
||||
@@ -28,6 +33,9 @@ func (c *HTTPClientConfig) defaults() {
|
||||
if c.Propagator == nil {
|
||||
c.Propagator = otel.GetTextMapPropagator()
|
||||
}
|
||||
if c.HostFunc == nil {
|
||||
c.HostFunc = func(r *http.Request) string { return r.URL.Host }
|
||||
}
|
||||
}
|
||||
|
||||
type httpClientMetrics struct {
|
||||
@@ -50,6 +58,7 @@ type clientTransport struct {
|
||||
tracer trace.Tracer
|
||||
propagator propagation.TextMapPropagator
|
||||
metrics *httpClientMetrics
|
||||
hostFunc func(*http.Request) string
|
||||
}
|
||||
|
||||
// NewHTTPTransport wraps base (http.DefaultTransport when nil) with client
|
||||
@@ -65,6 +74,7 @@ func NewHTTPTransport(base http.RoundTripper, cfg HTTPClientConfig) http.RoundTr
|
||||
base: base,
|
||||
tracer: cfg.TracerProvider.Tracer(tracerName),
|
||||
propagator: cfg.Propagator,
|
||||
hostFunc: cfg.HostFunc,
|
||||
}
|
||||
if cfg.Metrics != nil {
|
||||
t.metrics = newHTTPClientMetrics(cfg.Metrics, cfg.Buckets)
|
||||
@@ -105,19 +115,18 @@ func (t *clientTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
}
|
||||
|
||||
if t.metrics != nil {
|
||||
host := req.URL.Host
|
||||
host := t.hostFunc(req)
|
||||
t.metrics.requests.WithLabelValues(method, host, code).Inc()
|
||||
observe(ctx, t.metrics.duration.WithLabelValues(method, host, code), time.Since(start).Seconds())
|
||||
}
|
||||
return resp, err
|
||||
}
|
||||
|
||||
// redactURL returns the request URL without user credentials.
|
||||
// redactURL returns the request URL without user credentials and without the
|
||||
// query string, which often carries tokens and signatures.
|
||||
func redactURL(req *http.Request) string {
|
||||
if req.URL.User == nil {
|
||||
return req.URL.String()
|
||||
}
|
||||
u := *req.URL
|
||||
u.User = nil
|
||||
u.RawQuery = ""
|
||||
return u.String()
|
||||
}
|
||||
Reference in new issue
Block a user