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

Function SpanWrapFunc

internal/tracing/wrap.go:38–51  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 5

UpMethod · 0.92
rebuildMethod · 0.92
ScaleMethod · 0.92
BuildMethod · 0.92
ensureImagesExistsMethod · 0.92

Calls 3

SpanStartOptionsMethod · 0.80
ErrorMethod · 0.80
StartMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…