diff --git a/commands/build.go b/commands/build.go index 66c6bcec5158..b2a195916dc5 100644 --- a/commands/build.go +++ b/commands/build.go @@ -239,10 +239,12 @@ const ( commandOptionsHash = attribute.Key("command.options.hash") driverNameAttribute = attribute.Key("driver.name") driverTypeAttribute = attribute.Key("driver.type") + debuggerName = attribute.Key("debugger.name") + debuggerUserAgent = attribute.Key("debugger.user.agent") ) -func buildMetricAttributes(dockerCli command.Cli, driverType string, options *buildOptions) attribute.Set { - return attribute.NewSet( +func buildMetricAttributes(dockerCli command.Cli, driverType string, options *buildOptions, debugger debuggerOptions) attribute.Set { + kvs := []attribute.KeyValue{ commandNameAttribute.String("build"), attribute.Stringer(string(commandOptionsHash), &buildOptionsHash{ buildOptions: options, @@ -250,7 +252,16 @@ func buildMetricAttributes(dockerCli command.Cli, driverType string, options *bu }), driverNameAttribute.String(options.builder), driverTypeAttribute.String(driverType), - ) + } + + if debugger != nil { + d := debugger.Info() + kvs = append(kvs, + debuggerName.String(d.Name), + debuggerUserAgent.String(d.UserAgent), + ) + } + return attribute.NewSet(kvs...) } // buildOptionsHash computes a hash for the buildOptions when the String method is invoked. @@ -331,7 +342,7 @@ func runBuild(ctx context.Context, dockerCli command.Cli, debugOpts debuggerOpti } driverType := b.Driver - attributes := buildMetricAttributes(dockerCli, driverType, &options) + attributes := buildMetricAttributes(dockerCli, driverType, &options, debugOpts) ctx2, cancel := context.WithCancelCause(context.TODO()) defer func() { cancel(errors.WithStack(context.Canceled)) }() diff --git a/commands/dap.go b/commands/dap.go index 08ccde34d381..f2b3ef3f8ff5 100644 --- a/commands/dap.go +++ b/commands/dap.go @@ -18,6 +18,10 @@ import ( "github.com/spf13/cobra" ) +const ( + dapEnvUserAgent = "BUILDX_DAP_USER_AGENT" +) + func dapCmd(dockerCli command.Cli, rootOpts *rootOptions) *cobra.Command { var options dapOptions cmd := &cobra.Command{ @@ -51,6 +55,13 @@ func (d *dapOptions) New(in ioset.In) (debuggerInstance, error) { }, nil } +func (d *dapOptions) Info() debuggerInfo { + return debuggerInfo{ + Name: "dap", + UserAgent: os.Getenv(dapEnvUserAgent), + } +} + type LaunchConfig struct { Dockerfile string `json:"dockerfile,omitempty"` ContextPath string `json:"contextPath,omitempty"` diff --git a/commands/debug.go b/commands/debug.go index 926ea800838b..ff331903dfc6 100644 --- a/commands/debug.go +++ b/commands/debug.go @@ -26,9 +26,15 @@ type debugOptions struct { OnFlag string } +type debuggerInfo struct { + Name string + UserAgent string +} + // debuggerOptions will start a debuggerOptions instance. type debuggerOptions interface { New(in ioset.In) (debuggerInstance, error) + Info() debuggerInfo } // debuggerInstance is an instance of a Debugger that has been started. @@ -71,6 +77,12 @@ func (d *debugOptions) New(in ioset.In) (debuggerInstance, error) { }, nil } +func (d *debugOptions) Info() debuggerInfo { + return debuggerInfo{ + Name: "debug", + } +} + type monitorDebuggerInstance struct { cfg *build.InvokeConfig in io.ReadCloser