mirror of
https://github.com/foomo/keel.git
synced 2025-10-16 12:35:34 +00:00
refactor: update span names
This commit is contained in:
parent
ed5880a22d
commit
d6a4c362b4
@ -7,6 +7,7 @@ import (
|
||||
"io"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/foomo/gotsrpc/v2"
|
||||
@ -180,7 +181,9 @@ func TelemetryWithOptions(opts TelemetryOptions) middleware.Middleware {
|
||||
|
||||
return func(l *zap.Logger, name string, next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx, span := telemetry.Start(r.Context(), "GOTSRPC")
|
||||
ctx, span := telemetry.Start(r.Context(), "GOTSRPC",
|
||||
trace.WithSpanKind(trace.SpanKindServer),
|
||||
)
|
||||
*r = *gotsrpc.RequestWithStatsContext(r.WithContext(ctx))
|
||||
|
||||
if !opts.PayloadAttributeDisabled {
|
||||
@ -190,7 +193,11 @@ func TelemetryWithOptions(opts TelemetryOptions) middleware.Middleware {
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
|
||||
if stats, ok := gotsrpc.GetStatsForRequest(r); ok {
|
||||
span.SetName(fmt.Sprintf("GOTSRPC %s.%s", stats.Service, stats.Func))
|
||||
var pkg string
|
||||
if parts := strings.Split(stats.Package, "/"); len(parts) > 0 {
|
||||
pkg = parts[len(parts)-1] + "."
|
||||
}
|
||||
span.SetName(fmt.Sprintf("GOTSRPC %s%s/%s", pkg, stats.Service, stats.Func))
|
||||
span.SetAttributes(
|
||||
attribute.String("gotsrpc.func", stats.Func),
|
||||
attribute.String("gotsrpc.service", stats.Service),
|
||||
|
||||
@ -3,6 +3,7 @@ package http
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@ -228,7 +229,11 @@ func HTTPClientWithRoundTripware(l *zap.Logger, roundTripware ...roundtripware.R
|
||||
|
||||
func HTTPClientWithTelemetry(opts ...otelhttp.Option) HTTPClientOption {
|
||||
return func(v *http.Client) {
|
||||
v.Transport = otelhttp.NewTransport(v.Transport, opts...)
|
||||
v.Transport = otelhttp.NewTransport(v.Transport, append(opts,
|
||||
otelhttp.WithSpanNameFormatter(func(operation string, r *http.Request) string {
|
||||
return fmt.Sprintf("HTTP %s %s", r.Method, r.URL.Host)
|
||||
}),
|
||||
)...)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -28,7 +28,7 @@ func GetDefaultTelemetryOptions() TelemetryOptions {
|
||||
return TelemetryOptions{
|
||||
OtelOpts: []otelhttp.Option{
|
||||
otelhttp.WithSpanNameFormatter(func(operation string, r *http.Request) string {
|
||||
return fmt.Sprintf("HTTP %s", operation)
|
||||
return fmt.Sprintf("HTTP %s %s", r.Method, operation)
|
||||
}),
|
||||
},
|
||||
InjectPropagationHeader: true,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user