Skip to content

Commit 0982070

Browse files
tonistiigicrazy-max
authored andcommitted
otel: avoid tracing raw os arguments
User might pass a value that they don't expect to be kept in trace storage. For example some cache backends allow passing authentication tokens with a flag. Instead use known primary config values as attributes of the root span. Signed-off-by: Tonis Tiigi <[email protected]>
1 parent 1360a9e commit 0982070

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

commands/bake.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ type bakeOptions struct {
6666
func runBake(ctx context.Context, dockerCli command.Cli, targets []string, in bakeOptions, cFlags commonFlags) (err error) {
6767
mp := dockerCli.MeterProvider()
6868

69-
ctx, end, err := tracing.TraceCurrentCommand(ctx, "bake")
69+
ctx, end, err := tracing.TraceCurrentCommand(ctx, append([]string{"bake"}, targets...),
70+
attribute.String("builder", in.builder),
71+
attribute.StringSlice("targets", targets),
72+
attribute.StringSlice("files", in.files),
73+
)
7074
if err != nil {
7175
return err
7276
}

commands/build.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,11 @@ func (o *buildOptionsHash) String() string {
285285
func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions) (err error) {
286286
mp := dockerCli.MeterProvider()
287287

288-
ctx, end, err := tracing.TraceCurrentCommand(ctx, "build")
288+
ctx, end, err := tracing.TraceCurrentCommand(ctx, []string{"build", options.contextPath},
289+
attribute.String("builder", options.builder),
290+
attribute.String("context", options.contextPath),
291+
attribute.String("dockerfile", options.dockerfileName),
292+
)
289293
if err != nil {
290294
return err
291295
}

util/tracing/trace.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package tracing
22

33
import (
44
"context"
5-
"os"
65
"strings"
76

87
"github.com/moby/buildkit/util/tracing/delegated"
@@ -13,7 +12,7 @@ import (
1312
"go.opentelemetry.io/otel/trace"
1413
)
1514

16-
func TraceCurrentCommand(ctx context.Context, name string) (context.Context, func(error), error) {
15+
func TraceCurrentCommand(ctx context.Context, args []string, attrs ...attribute.KeyValue) (context.Context, func(error), error) {
1716
opts := []sdktrace.TracerProviderOption{
1817
sdktrace.WithResource(detect.Resource()),
1918
sdktrace.WithBatcher(delegated.DefaultExporter),
@@ -25,8 +24,8 @@ func TraceCurrentCommand(ctx context.Context, name string) (context.Context, fun
2524
}
2625

2726
tp := sdktrace.NewTracerProvider(opts...)
28-
ctx, span := tp.Tracer("").Start(ctx, name, trace.WithAttributes(
29-
attribute.String("command", strings.Join(os.Args, " ")),
27+
ctx, span := tp.Tracer("").Start(ctx, strings.Join(args, " "), trace.WithAttributes(
28+
attrs...,
3029
))
3130

3231
return ctx, func(err error) {

0 commit comments

Comments
 (0)