diff --git a/commands/bake.go b/commands/bake.go index 4afe2e51..a8ad4c57 100644 --- a/commands/bake.go +++ b/commands/bake.go @@ -66,7 +66,11 @@ type bakeOptions struct { func runBake(ctx context.Context, dockerCli command.Cli, targets []string, in bakeOptions, cFlags commonFlags) (err error) { mp := dockerCli.MeterProvider() - ctx, end, err := tracing.TraceCurrentCommand(ctx, "bake") + ctx, end, err := tracing.TraceCurrentCommand(ctx, append([]string{"bake"}, targets...), + attribute.String("builder", in.builder), + attribute.StringSlice("targets", targets), + attribute.StringSlice("files", in.files), + ) if err != nil { return err } diff --git a/commands/build.go b/commands/build.go index 08eabd93..9c3ae280 100644 --- a/commands/build.go +++ b/commands/build.go @@ -286,7 +286,11 @@ func (o *buildOptionsHash) String() string { func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions) (err error) { mp := dockerCli.MeterProvider() - ctx, end, err := tracing.TraceCurrentCommand(ctx, "build") + ctx, end, err := tracing.TraceCurrentCommand(ctx, []string{"build", options.contextPath}, + attribute.String("builder", options.builder), + attribute.String("context", options.contextPath), + attribute.String("dockerfile", options.dockerfileName), + ) if err != nil { return err } diff --git a/util/tracing/trace.go b/util/tracing/trace.go index d16ca9f9..4e220139 100644 --- a/util/tracing/trace.go +++ b/util/tracing/trace.go @@ -2,7 +2,6 @@ package tracing import ( "context" - "os" "strings" "github.com/moby/buildkit/util/tracing/delegated" @@ -13,7 +12,7 @@ import ( "go.opentelemetry.io/otel/trace" ) -func TraceCurrentCommand(ctx context.Context, name string) (context.Context, func(error), error) { +func TraceCurrentCommand(ctx context.Context, args []string, attrs ...attribute.KeyValue) (context.Context, func(error), error) { opts := []sdktrace.TracerProviderOption{ sdktrace.WithResource(detect.Resource()), sdktrace.WithBatcher(delegated.DefaultExporter), @@ -25,8 +24,8 @@ func TraceCurrentCommand(ctx context.Context, name string) (context.Context, fun } tp := sdktrace.NewTracerProvider(opts...) - ctx, span := tp.Tracer("").Start(ctx, name, trace.WithAttributes( - attribute.String("command", strings.Join(os.Args, " ")), + ctx, span := tp.Tracer("").Start(ctx, strings.Join(args, " "), trace.WithAttributes( + attrs..., )) return ctx, func(err error) {