connect contexts managed by fiber middleware to join at c.UserContext()

This commit is contained in:
2024-05-20 11:45:27 +02:00
parent 372f4367ed
commit d119563c7d
2 changed files with 8 additions and 2 deletions

View File

@ -44,9 +44,11 @@ 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) {
ctx := fiberOpentelemetry.FromCtx(c)
return fiberOpentelemetry.Tracer.Start(ctx, c.Method()+" "+c.Path(), opts...)
link := trace.LinkFromContext(fiberOpentelemetry.FromCtx(c))
opts = append(opts, trace.WithLinks(link))
return fiberOpentelemetry.Tracer.Start(c.UserContext(), c.Method()+" "+c.Path(), opts...)
}
// Retrieve span using [fiber.Ctx]