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 91 92 93 94 95
|
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 | 7 ++++++-
commands/build.go | 6 +++++-
util/tracing/trace.go | 7 +++----
3 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/commands/bake.go b/commands/bake.go
index 14e3d4a..bd4747a 100644
--- a/commands/bake.go
+++ b/commands/bake.go
@@ -26,6 +26,7 @@ import (
"github.com/moby/buildkit/util/progress/progressui"
"github.com/pkg/errors"
"github.com/spf13/cobra"
+ "go.opentelemetry.io/otel/attribute"
)
type bakeOptions struct {
@@ -42,7 +43,11 @@ type bakeOptions struct {
}
func runBake(ctx context.Context, dockerCli command.Cli, targets []string, in bakeOptions, cFlags commonFlags) (err error) {
- 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 9753650..c83934a 100644
--- a/commands/build.go
+++ b/commands/build.go
@@ -272,7 +272,11 @@ func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions)
}
defer mp.Report(context.Background())
- 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 c95ad5a..13ce349 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/detect"
@@ -10,13 +9,13 @@ 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) {
tp, err := detect.TracerProvider()
if err != nil {
return context.Background(), nil, err
}
- 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) {
|