From 3024e888c7cd85a04b761bf8a824f92197cf109d Mon Sep 17 00:00:00 2001 From: Natalia Goc Date: Mon, 27 May 2024 07:37:54 +0200 Subject: [PATCH] adjust tracing middleware for practical use --- pkg/fiber_tracing/fiber_tracing.go | 3 +-- pkg/fiber_tracing/middleware.go | 14 +++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/pkg/fiber_tracing/fiber_tracing.go b/pkg/fiber_tracing/fiber_tracing.go index 57ba08c..e09bd55 100644 --- a/pkg/fiber_tracing/fiber_tracing.go +++ b/pkg/fiber_tracing/fiber_tracing.go @@ -24,8 +24,7 @@ type Config struct { Version string // Name of an organization providing the service ServiceProvider string - - Exporters []exporters.TraceExporter + Exporters []exporters.TraceExporter } func newResource(config Config) *resource.Resource { diff --git a/pkg/fiber_tracing/middleware.go b/pkg/fiber_tracing/middleware.go index 3f9e73b..6882bcf 100644 --- a/pkg/fiber_tracing/middleware.go +++ b/pkg/fiber_tracing/middleware.go @@ -5,6 +5,7 @@ package fiber_tracing // into the package. import ( + "git.ma-al.com/maal-libraries/observer/pkg/attr" "github.com/gofiber/fiber/v2" "go.opentelemetry.io/otel" semconv "go.opentelemetry.io/otel/semconv/v1.25.0" @@ -50,28 +51,27 @@ func new(config ...middlewareConfig) fiber.Handler { // Return new handler return func(c *fiber.Ctx) error { - spanStartAttributes := trace.WithAttributes( + spanStartAttributes := []attr.KeyValue{ semconv.HTTPMethod(c.Method()), semconv.HTTPTarget(string(c.Request().RequestURI())), semconv.HTTPRoute(c.Route().Path), semconv.HTTPURL(c.OriginalURL()), - semconv.HostIP(c.IP()), semconv.HTTPUserAgent(string(c.Request().Header.UserAgent())), semconv.HTTPRequestContentLength(c.Request().Header.ContentLength()), semconv.HTTPScheme(c.Protocol()), semconv.NetTransportTCP, - ) - spanKind := trace.WithSpanKind(trace.SpanKindServer) + } + spanStartAttributes = append(spanStartAttributes, attr.ProcessStart()...) opts := []trace.SpanStartOption{ - spanStartAttributes, - spanKind, + trace.WithAttributes(spanStartAttributes...), + trace.WithSpanKind(trace.SpanKindServer), } opts = append(opts, cfg.TracerStartAttributes...) otelCtx, span := Tracer.Start( c.UserContext(), - c.Method()+" "+c.Route().Path, + c.Method()+" "+c.OriginalURL(), opts..., )