EventWrapFuncForErrGroup invokes a function and records an event, optionally including the returned error as the "exception message" on the event. This is intended for lightweight usage to wrap errgroup.Group calls where a full span is not desired.
(ctx context.Context, eventName string, opts SpanOptions, fn func(ctx context.Context) error)
| 78 | // |
| 79 | // This is intended for lightweight usage to wrap errgroup.Group calls where a full span is not desired. |
| 80 | func EventWrapFuncForErrGroup(ctx context.Context, eventName string, opts SpanOptions, fn func(ctx context.Context) error) func() error { |
| 81 | return func() error { |
| 82 | span := trace.SpanFromContext(ctx) |
| 83 | eventOpts := opts.EventOptions() |
| 84 | |
| 85 | err := fn(ctx) |
| 86 | if err != nil { |
| 87 | eventOpts = append(eventOpts, trace.WithAttributes(semconv.ExceptionMessage(stripansi.Strip(err.Error())))) |
| 88 | } |
| 89 | span.AddEvent(eventName, eventOpts...) |
| 90 | |
| 91 | return err |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | func AddAttributeToSpan(ctx context.Context, attr ...attribute.KeyValue) { |
| 96 | span := trace.SpanFromContext(ctx) |
no test coverage detected