Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,18 +239,29 @@ 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,
cfg: confutil.NewConfig(dockerCli),
}),
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.
Expand Down Expand Up @@ -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)) }()
Expand Down
11 changes: 11 additions & 0 deletions commands/dap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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"`
Expand Down
12 changes: 12 additions & 0 deletions commands/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down