mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 00:47:48 +08:00
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>
This commit is contained in:
parent
1360a9e8d2
commit
0982070af8
@ -66,7 +66,11 @@ type bakeOptions struct {
|
|||||||
func runBake(ctx context.Context, dockerCli command.Cli, targets []string, in bakeOptions, cFlags commonFlags) (err error) {
|
func runBake(ctx context.Context, dockerCli command.Cli, targets []string, in bakeOptions, cFlags commonFlags) (err error) {
|
||||||
mp := dockerCli.MeterProvider()
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -285,7 +285,11 @@ func (o *buildOptionsHash) String() string {
|
|||||||
func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions) (err error) {
|
func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions) (err error) {
|
||||||
mp := dockerCli.MeterProvider()
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package tracing
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"os"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/moby/buildkit/util/tracing/delegated"
|
"github.com/moby/buildkit/util/tracing/delegated"
|
||||||
@ -13,7 +12,7 @@ import (
|
|||||||
"go.opentelemetry.io/otel/trace"
|
"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{
|
opts := []sdktrace.TracerProviderOption{
|
||||||
sdktrace.WithResource(detect.Resource()),
|
sdktrace.WithResource(detect.Resource()),
|
||||||
sdktrace.WithBatcher(delegated.DefaultExporter),
|
sdktrace.WithBatcher(delegated.DefaultExporter),
|
||||||
@ -25,8 +24,8 @@ func TraceCurrentCommand(ctx context.Context, name string) (context.Context, fun
|
|||||||
}
|
}
|
||||||
|
|
||||||
tp := sdktrace.NewTracerProvider(opts...)
|
tp := sdktrace.NewTracerProvider(opts...)
|
||||||
ctx, span := tp.Tracer("").Start(ctx, name, trace.WithAttributes(
|
ctx, span := tp.Tracer("").Start(ctx, strings.Join(args, " "), trace.WithAttributes(
|
||||||
attribute.String("command", strings.Join(os.Args, " ")),
|
attrs...,
|
||||||
))
|
))
|
||||||
|
|
||||||
return ctx, func(err error) {
|
return ctx, func(err error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user