From ae6b3fa4f4ddc71df9f705b4895c3d2917abe50f Mon Sep 17 00:00:00 2001 From: Joana Hrotko Date: Fri, 15 Mar 2024 11:44:44 +0000 Subject: [PATCH] send otel metrics related to keyboard feature Signed-off-by: Joana Hrotko --- cmd/formatter/shortcut.go | 15 +++++++++++++++ internal/tracing/attributes.go | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/cmd/formatter/shortcut.go b/cmd/formatter/shortcut.go index 42b67477a89..2431b7c5ed0 100644 --- a/cmd/formatter/shortcut.go +++ b/cmd/formatter/shortcut.go @@ -9,6 +9,7 @@ import ( "github.com/buger/goterm" "github.com/compose-spec/compose-go/v2/types" + "github.com/docker/compose/v2/internal/tracing" "github.com/docker/compose/v2/pkg/api" "github.com/docker/compose/v2/pkg/watch" "github.com/eiannone/keyboard" @@ -48,6 +49,7 @@ type LogKeyboard struct { // services []string // printerStop func() // printerStart func() + metrics tracing.KeyboardMetrics } var KeyboardManager *LogKeyboard @@ -66,6 +68,10 @@ func NewKeyboardManager(isDockerDesktopActive, isWatchConfigured bool, sc chan<- km.Watch.Watching = false km.Watch.WatchFn = watchFn km.SignalChannel = sc + km.metrics = tracing.KeyboardMetrics{ + EnabledViewDockerDesktop: isDockerDesktopActive, + HasWatchConfig: isWatchConfigured, + } KeyboardManager = &km } @@ -180,6 +186,7 @@ func (lk *LogKeyboard) openDockerDesktop(project *types.Project) { if !lk.IsDockerDesktopActive { return } + lk.metrics.ActivateViewDockerDesktop = true link := fmt.Sprintf("docker-desktop://dashboard/apps/%s", project.Name) err := open.Run(link) if err != nil { @@ -291,6 +298,7 @@ func (lk *LogKeyboard) HandleKeyEvents(event keyboard.KeyEvent, ctx context.Cont case 'V': lk.openDockerDesktop(project) case 'W': + lk.metrics.ActivateWatch = true lk.StartWatch(ctx, project, options) // case 'D': // lk.debug(project) @@ -304,6 +312,13 @@ func (lk *LogKeyboard) HandleKeyEvents(event keyboard.KeyEvent, ctx context.Cont lk.Watch.Cancel() _ = eg.Wait().ErrorOrNil() // Need to print this ? } + go func() { + tracing.SpanWrapFunc("nav_menu", tracing.KeyboardOptions(lk.metrics), + func(ctx context.Context) error { + return nil + })(ctx) + }() + // will notify main thread to kill and will handle gracefully lk.SignalChannel <- syscall.SIGINT case keyboard.KeyEnter: diff --git a/internal/tracing/attributes.go b/internal/tracing/attributes.go index 3d27c4796ac..622f5f8b40c 100644 --- a/internal/tracing/attributes.go +++ b/internal/tracing/attributes.go @@ -42,6 +42,13 @@ type Metrics struct { CountIncludesRemote int } +type KeyboardMetrics struct { + EnabledViewDockerDesktop bool + HasWatchConfig bool + ActivateViewDockerDesktop bool + ActivateWatch bool +} + func (s SpanOptions) SpanStartOptions() []trace.SpanStartOption { out := make([]trace.SpanStartOption, len(s)) for i := range s { @@ -135,6 +142,18 @@ func ServiceOptions(service types.ServiceConfig) SpanOptions { } } +func KeyboardOptions(metrics KeyboardMetrics) SpanOptions { + attrs := []attribute.KeyValue{ + attribute.Bool("view.enabled", metrics.EnabledViewDockerDesktop), + attribute.Bool("view.activated", metrics.ActivateViewDockerDesktop), + attribute.Bool("watch.activated", metrics.ActivateWatch), + attribute.Bool("watch.config", metrics.HasWatchConfig), + } + return []trace.SpanStartEventOption{ + trace.WithAttributes(attrs...), + } +} + // ContainerOptions returns common attributes from a Moby container. // // For convenience, it's returned as a SpanOptions object to allow it to be