github.com/pdmccormick/importable-docker-buildx@v0.0.0-20240426161518-e47091289030/util/tracing/trace.go (about) 1 package tracing 2 3 import ( 4 "context" 5 "os" 6 "strings" 7 8 "github.com/moby/buildkit/util/tracing/detect" 9 "go.opentelemetry.io/otel/attribute" 10 "go.opentelemetry.io/otel/trace" 11 ) 12 13 func TraceCurrentCommand(ctx context.Context, name string) (context.Context, func(error), error) { 14 tp, err := detect.TracerProvider() 15 if err != nil { 16 return context.Background(), nil, err 17 } 18 ctx, span := tp.Tracer("").Start(ctx, name, trace.WithAttributes( 19 attribute.String("command", strings.Join(os.Args, " ")), 20 )) 21 22 return ctx, func(err error) { 23 if err != nil { 24 span.RecordError(err) 25 } 26 span.End() 27 28 detect.Shutdown(context.TODO()) 29 }, nil 30 }