From 294616bff9877231a6975c7dba9e911fc4fd0ffc Mon Sep 17 00:00:00 2001 From: Natalia Goc Date: Mon, 20 May 2024 19:43:39 +0200 Subject: [PATCH] make span names more generic by using OriginalURL instead of Path --- example/main.go | 1 + example/requests.hurl | 5 ++++- pkg/fiber_tracing/fiber_tracing.go | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/example/main.go b/example/main.go index 4584410..9efe544 100644 --- a/example/main.go +++ b/example/main.go @@ -51,6 +51,7 @@ func main() { }) main.Get("/", Handler) + main.Get("/just/some/more/complex/path/:with/params", Handler) // handle interrupts (shutdown) c := make(chan os.Signal, 1) diff --git a/example/requests.hurl b/example/requests.hurl index df37240..9d4d059 100644 --- a/example/requests.hurl +++ b/example/requests.hurl @@ -1,2 +1,5 @@ GET http://127.0.0.1:3344/ -HTTP 200 +HTTP 500 + +GET http://127.0.0.1:3344/just/some/more/complex/path/:with/params +HTTP 500 diff --git a/pkg/fiber_tracing/fiber_tracing.go b/pkg/fiber_tracing/fiber_tracing.go index 54daf12..375865f 100644 --- a/pkg/fiber_tracing/fiber_tracing.go +++ b/pkg/fiber_tracing/fiber_tracing.go @@ -48,7 +48,7 @@ func Start(ctx context.Context, spanName string, opts ...trace.SpanStartOption) func FStart(c *fiber.Ctx, opts ...trace.SpanStartOption) (context.Context, trace.Span) { span := trace.SpanFromContext(fiberOpentelemetry.FromCtx(c)) c.SetUserContext(trace.ContextWithSpan(c.UserContext(), span)) - return fiberOpentelemetry.Tracer.Start(c.UserContext(), c.Method()+" "+c.Path(), opts...) + return fiberOpentelemetry.Tracer.Start(c.UserContext(), c.Method()+" "+c.Route().Path, opts...) } // Retrieve span using [fiber.Ctx] @@ -81,7 +81,7 @@ func NewMiddleware(config Config) func(*fiber.Ctx) error { return fiberOpentelemetry.New( fiberOpentelemetry.Config{ Tracer: tracer, - SpanName: "{{ .Method }} {{ .Path }}", + SpanName: "{{ .Method }} {{ .Route.Path }}", TracerStartAttributes: []trace.SpanStartOption{ trace.WithSpanKind(trace.SpanKindServer), trace.WithNewRoot(),