adjust tracing middleware for practical use

This commit is contained in:
Natalia Goc 2024-05-27 07:37:54 +02:00
parent d7b45a1439
commit 3024e888c7
2 changed files with 8 additions and 9 deletions

View File

@ -24,7 +24,6 @@ type Config struct {
Version string
// Name of an organization providing the service
ServiceProvider string
Exporters []exporters.TraceExporter
}

View File

@ -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...,
)