SpanWrapFunc wraps a function that takes a context with a trace.Span, marking the status as codes.Error if the wrapped function returns an error. The context passed to the function is created from the span to ensure correct propagation. NOTE: This function is nearly identical to SpanWrapFuncForErr
(spanName string, opts SpanOptions, fn func(ctx context.Context) error)
| 36 | // convenience with errgroup.Group due to its prevalence throughout the codebase. The code is duplicated to avoid |
| 37 | // adding even more levels of function wrapping/indirection. |
| 38 | func SpanWrapFunc(spanName string, opts SpanOptions, fn func(ctx context.Context) error) func(context.Context) error { |
| 39 | return func(ctx context.Context) error { |
| 40 | ctx, span := otel.Tracer("").Start(ctx, spanName, opts.SpanStartOptions()...) |
| 41 | defer span.End() |
| 42 | |
| 43 | if err := fn(ctx); err != nil { |
| 44 | span.SetStatus(codes.Error, err.Error()) |
| 45 | return err |
| 46 | } |
| 47 | |
| 48 | span.SetStatus(codes.Ok, "") |
| 49 | return nil |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | // SpanWrapFuncForErrGroup wraps a function that takes a context with a trace.Span, marking the status as codes.Error |
| 54 | // if the wrapped function returns an error. |
no test coverage detected