fix spans in UserContext() not connected properly to span from fiber.Ctx

This commit is contained in:
Natalia Goc 2024-05-20 19:35:21 +02:00
parent 86e9128c68
commit 031177f30c

View File

@ -46,14 +46,15 @@ func Start(ctx context.Context, spanName string, opts ...trace.SpanStartOption)
// NOTE: You can use [trace.WithAttributes] as a parameter to opts argument
// Returns [c.UserContext] as [context.Context]
func FStart(c *fiber.Ctx, opts ...trace.SpanStartOption) (context.Context, trace.Span) {
link := trace.LinkFromContext(fiberOpentelemetry.FromCtx(c))
opts = append(opts, trace.WithLinks(link))
span := trace.SpanFromContext(fiberOpentelemetry.FromCtx(c))
c.SetUserContext(trace.ContextWithSpan(c.UserContext(), span))
return fiberOpentelemetry.Tracer.Start(c.UserContext(), c.Method()+" "+c.Path(), opts...)
}
// Retrieve span using [fiber.Ctx]
func SpanFromContext(c *fiber.Ctx) trace.Span {
ctx := fiberOpentelemetry.FromCtx(c)
c.SetUserContext(trace.ContextWithSpan(c.UserContext(), trace.SpanFromContext(ctx)))
return trace.SpanFromContext(ctx)
}