SpanWrapFuncForErrGroup 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 SpanWra
(ctx context.Context, spanName string, opts SpanOptions, fn func(ctx context.Context) error)
| 59 | // convenience with errgroup.Group due to its prevalence throughout the codebase. The code is duplicated to avoid |
| 60 | // adding even more levels of function wrapping/indirection. |
| 61 | func SpanWrapFuncForErrGroup(ctx context.Context, spanName string, opts SpanOptions, fn func(ctx context.Context) error) func() error { |
| 62 | return func() error { |
| 63 | ctx, span := otel.Tracer("").Start(ctx, spanName, opts.SpanStartOptions()...) |
| 64 | defer span.End() |
| 65 | |
| 66 | if err := fn(ctx); err != nil { |
| 67 | span.SetStatus(codes.Error, err.Error()) |
| 68 | return err |
| 69 | } |
| 70 | |
| 71 | span.SetStatus(codes.Ok, "") |
| 72 | return nil |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | // EventWrapFuncForErrGroup invokes a function and records an event, optionally including the returned |
| 77 | // error as the "exception message" on the event. |
nothing calls this directly
no test coverage detected