Documentation
¶
Overview ¶
Package otelroute provides an HTTP middleware that enriches active OpenTelemetry spans with missing HTTP semantic convention attributes.
Standard net/http instrumentation (e.g. otelhttp) cannot populate http.route without router cooperation, leading to unbounded metric cardinality. This middleware infers the route from the URL path using the clusterurl ML model and also adds client.address and network.protocol.version.
Usage:
h, err := otelroute.New(myHandler)
if err != nil {
log.Fatal(err)
}
http.ListenAndServe(":8080", otelhttp.NewHandler(h, "server"))
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
New wraps next and returns an http.Handler that enriches the active OTel span with missing HTTP semantic convention attributes after the wrapped handler returns:
- http.route — inferred via clusterurl or set explicitly via SetRoute
- client.address — real client IP, proxy-header aware
- network.protocol.version — e.g. "1.1" or "2.0"
It is a no-op when there is no recording span in the request context.
func SetRoute ¶
SetRoute explicitly marks the matched route pattern on the request so the middleware uses it instead of inferring it from the URL path. Call this from your router or handler when you know the template (e.g. "/users/{id}").
The request must have passed through the otelroute middleware for this to have any effect.
Types ¶
type Option ¶
type Option func(*config)
Option configures the middleware.
func WithClusterer ¶
func WithClusterer(c *clusterurl.ClusterURLClassifier) Option
WithClusterer sets a pre-built ClusterURLClassifier for route inference. Use this when you want full control over the clusterer configuration.