Update OpenTelemetry to v1.38.0 and semantic conventions to v1.37.0
This commit is contained in:
parent
5878238077
commit
5dfb832921
13 changed files with 250 additions and 196 deletions
|
|
@ -13,8 +13,8 @@ import (
|
|||
"github.com/traefik/traefik/v3/pkg/middlewares/observability"
|
||||
"github.com/traefik/traefik/v3/pkg/tracing"
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/metric"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.26.0"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.37.0"
|
||||
"go.opentelemetry.io/otel/semconv/v1.37.0/httpconv"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
)
|
||||
|
||||
|
|
@ -68,9 +68,7 @@ func (t *wrapper) RoundTrip(req *http.Request) (*http.Response, error) {
|
|||
span.End(trace.WithTimestamp(end))
|
||||
}
|
||||
|
||||
if !observability.SemConvMetricsEnabled(req.Context()) ||
|
||||
t.semConvMetricRegistry == nil ||
|
||||
t.semConvMetricRegistry.HTTPClientRequestDuration() == nil {
|
||||
if !observability.SemConvMetricsEnabled(req.Context()) || t.semConvMetricRegistry == nil {
|
||||
return response, err
|
||||
}
|
||||
|
||||
|
|
@ -86,24 +84,27 @@ func (t *wrapper) RoundTrip(req *http.Request) (*http.Response, error) {
|
|||
attrs = append(attrs, semconv.HTTPResponseStatusCode(statusCode))
|
||||
attrs = append(attrs, semconv.NetworkProtocolName(strings.ToLower(req.Proto)))
|
||||
attrs = append(attrs, semconv.NetworkProtocolVersion(observability.Proto(req.Proto)))
|
||||
attrs = append(attrs, semconv.ServerAddress(req.URL.Host))
|
||||
|
||||
var serverPort int
|
||||
_, port, splitErr := net.SplitHostPort(req.URL.Host)
|
||||
if splitErr != nil {
|
||||
switch req.URL.Scheme {
|
||||
case "http":
|
||||
attrs = append(attrs, semconv.ServerPort(80))
|
||||
serverPort = 80
|
||||
attrs = append(attrs, semconv.ServerPort(serverPort))
|
||||
case "https":
|
||||
attrs = append(attrs, semconv.ServerPort(443))
|
||||
serverPort = 443
|
||||
attrs = append(attrs, semconv.ServerPort(serverPort))
|
||||
}
|
||||
} else {
|
||||
intPort, _ := strconv.Atoi(port)
|
||||
attrs = append(attrs, semconv.ServerPort(intPort))
|
||||
serverPort, _ := strconv.Atoi(port)
|
||||
attrs = append(attrs, semconv.ServerPort(serverPort))
|
||||
}
|
||||
|
||||
attrs = append(attrs, semconv.URLScheme(req.Header.Get("X-Forwarded-Proto")))
|
||||
|
||||
t.semConvMetricRegistry.HTTPClientRequestDuration().Record(req.Context(), end.Sub(start).Seconds(), metric.WithAttributes(attrs...))
|
||||
t.semConvMetricRegistry.HTTPClientRequestDuration().Record(req.Context(), end.Sub(start).Seconds(),
|
||||
httpconv.RequestMethodAttr(req.Method), req.URL.Host, serverPort, attrs...)
|
||||
|
||||
return response, err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue