1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
From: Tonis Tiigi <tonistiigi@gmail.com>
Date: Mon, 3 Feb 2025 22:14:55 -0800
Subject: [PATCH] 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 <tonistiigi@gmail.com>
Origin: upstream, https://github.com/docker/buildx/commit/0982070af84d476b232d2d75ab551c3222592db1
Bug-Debian: http://bugs.debian.org/1100991
Backported-by: Nicolas Peugnet <nicolas@club1.fr>
* Added missing import in commands/bake.go
* Fixed conflicts in other hunks
---
commands/bake.go | 6 +++++-
commands/build.go | 6 +++++-
util/tracing/trace.go | 7 +++----
3 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/commands/bake.go b/commands/bake.go
index 12befc8..3405f0c 100644
--- a/commands/bake.go
+++ b/commands/bake.go
@@ -61,7 +61,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 7850c1b..3bbdb29 100644
--- a/commands/build.go
+++ b/commands/build.go
@@ -282,7 +282,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 d16ca9f..4e22013 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) {
|