MCPcopy
hub / github.com/docker/compose / Setup

Function Setup

cmd/cmdtrace/cmd_span.go:48–67  ·  cmd/cmdtrace/cmd_span.go::Setup

Setup should be called as part of the command's PersistentPreRunE as soon as possible after initializing the dockerCli. It initializes the tracer for the CLI using both auto-detection from the Docker context metadata as well as standard OTEL_ env vars, creates a root span for the command, and wraps

(cmd *cobra.Command, dockerCli command.Cli, args []string)

Source from the content-addressed store, hash-verified

46// command invocation to ensure the span is properly finalized and
47// exported before exit.
48func Setup(cmd *cobra.Command, dockerCli command.Cli, args []string) error {
49 tracingShutdown, err := tracing.InitTracing(dockerCli)
50 if err != nil {
51 return fmt.Errorf("initializing tracing: %w", err)
52 }
53
54 ctx := cmd.Context()
55 ctx, cmdSpan := otel.Tracer("").Start(
56 ctx,
57 "cli/"+strings.Join(commandName(cmd), "-"),
58 )
59 cmdSpan.SetAttributes(
60 attribute.StringSlice("cli.flags", getFlags(cmd.Flags())),
61 attribute.Bool("cli.isatty", dockerCli.In().IsTerminal()),
62 )
63
64 cmd.SetContext(ctx)
65 wrapRunE(cmd, cmdSpan, tracingShutdown)
66 return nil
67}
68
69// wrapRunE injects a wrapper function around the command's actual RunE (or Run)
70// method. This is necessary to capture the command result for reporting as well

Callers 1

pluginMainFunction · 0.92

Calls 6

InitTracingFunction · 0.92
commandNameFunction · 0.85
getFlagsFunction · 0.85
wrapRunEFunction · 0.85
StartMethod · 0.65
InMethod · 0.45

Tested by

no test coverage detected