MCPcopy
hub / github.com/docker/compose / SpanWrapFuncForErrGroup

Function SpanWrapFuncForErrGroup

internal/tracing/wrap.go:61–74  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
61func 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.

Callers

nothing calls this directly

Calls 3

SpanStartOptionsMethod · 0.80
ErrorMethod · 0.80
StartMethod · 0.65

Tested by

no test coverage detected