|
@@ -29,6 +29,7 @@ import (
|
|
commands "github.com/docker/compose/v2/cmd/compose"
|
|
commands "github.com/docker/compose/v2/cmd/compose"
|
|
"github.com/docker/compose/v2/internal/tracing"
|
|
"github.com/docker/compose/v2/internal/tracing"
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/cobra"
|
|
|
|
+ flag "github.com/spf13/pflag"
|
|
"go.opentelemetry.io/otel/attribute"
|
|
"go.opentelemetry.io/otel/attribute"
|
|
"go.opentelemetry.io/otel/codes"
|
|
"go.opentelemetry.io/otel/codes"
|
|
"go.opentelemetry.io/otel/trace"
|
|
"go.opentelemetry.io/otel/trace"
|
|
@@ -42,7 +43,7 @@ import (
|
|
// vars, creates a root span for the command, and wraps the actual
|
|
// vars, creates a root span for the command, and wraps the actual
|
|
// command invocation to ensure the span is properly finalized and
|
|
// command invocation to ensure the span is properly finalized and
|
|
// exported before exit.
|
|
// exported before exit.
|
|
-func Setup(cmd *cobra.Command, dockerCli command.Cli) error {
|
|
|
|
|
|
+func Setup(cmd *cobra.Command, dockerCli command.Cli, args []string) error {
|
|
tracingShutdown, err := tracing.InitTracing(dockerCli)
|
|
tracingShutdown, err := tracing.InitTracing(dockerCli)
|
|
if err != nil {
|
|
if err != nil {
|
|
return fmt.Errorf("initializing tracing: %w", err)
|
|
return fmt.Errorf("initializing tracing: %w", err)
|
|
@@ -53,6 +54,9 @@ func Setup(cmd *cobra.Command, dockerCli command.Cli) error {
|
|
ctx,
|
|
ctx,
|
|
"cli/"+strings.Join(commandName(cmd), "-"),
|
|
"cli/"+strings.Join(commandName(cmd), "-"),
|
|
)
|
|
)
|
|
|
|
+ cmdSpan.SetAttributes(attribute.StringSlice("cli.args", args))
|
|
|
|
+ cmdSpan.SetAttributes(attribute.StringSlice("cli.flags", getFlags(cmd.Flags())))
|
|
|
|
+
|
|
cmd.SetContext(ctx)
|
|
cmd.SetContext(ctx)
|
|
wrapRunE(cmd, cmdSpan, tracingShutdown)
|
|
wrapRunE(cmd, cmdSpan, tracingShutdown)
|
|
return nil
|
|
return nil
|
|
@@ -129,3 +133,11 @@ func commandName(cmd *cobra.Command) []string {
|
|
sort.Sort(sort.Reverse(sort.StringSlice(name)))
|
|
sort.Sort(sort.Reverse(sort.StringSlice(name)))
|
|
return name
|
|
return name
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func getFlags(fs *flag.FlagSet) []string {
|
|
|
|
+ var result []string
|
|
|
|
+ fs.Visit(func(flag *flag.Flag) {
|
|
|
|
+ result = append(result, flag.Name)
|
|
|
|
+ })
|
|
|
|
+ return result
|
|
|
|
+}
|