Skip to content

Commit ae6b3fa

Browse files
committed
send otel metrics related to keyboard feature
Signed-off-by: Joana Hrotko <[email protected]>
1 parent ee4834f commit ae6b3fa

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

Diff for: cmd/formatter/shortcut.go

+15
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/buger/goterm"
1111
"github.com/compose-spec/compose-go/v2/types"
12+
"github.com/docker/compose/v2/internal/tracing"
1213
"github.com/docker/compose/v2/pkg/api"
1314
"github.com/docker/compose/v2/pkg/watch"
1415
"github.com/eiannone/keyboard"
@@ -48,6 +49,7 @@ type LogKeyboard struct {
4849
// services []string
4950
// printerStop func()
5051
// printerStart func()
52+
metrics tracing.KeyboardMetrics
5153
}
5254

5355
var KeyboardManager *LogKeyboard
@@ -66,6 +68,10 @@ func NewKeyboardManager(isDockerDesktopActive, isWatchConfigured bool, sc chan<-
6668
km.Watch.Watching = false
6769
km.Watch.WatchFn = watchFn
6870
km.SignalChannel = sc
71+
km.metrics = tracing.KeyboardMetrics{
72+
EnabledViewDockerDesktop: isDockerDesktopActive,
73+
HasWatchConfig: isWatchConfigured,
74+
}
6975
KeyboardManager = &km
7076
}
7177

@@ -180,6 +186,7 @@ func (lk *LogKeyboard) openDockerDesktop(project *types.Project) {
180186
if !lk.IsDockerDesktopActive {
181187
return
182188
}
189+
lk.metrics.ActivateViewDockerDesktop = true
183190
link := fmt.Sprintf("docker-desktop://dashboard/apps/%s", project.Name)
184191
err := open.Run(link)
185192
if err != nil {
@@ -291,6 +298,7 @@ func (lk *LogKeyboard) HandleKeyEvents(event keyboard.KeyEvent, ctx context.Cont
291298
case 'V':
292299
lk.openDockerDesktop(project)
293300
case 'W':
301+
lk.metrics.ActivateWatch = true
294302
lk.StartWatch(ctx, project, options)
295303
// case 'D':
296304
// lk.debug(project)
@@ -304,6 +312,13 @@ func (lk *LogKeyboard) HandleKeyEvents(event keyboard.KeyEvent, ctx context.Cont
304312
lk.Watch.Cancel()
305313
_ = eg.Wait().ErrorOrNil() // Need to print this ?
306314
}
315+
go func() {
316+
tracing.SpanWrapFunc("nav_menu", tracing.KeyboardOptions(lk.metrics),
317+
func(ctx context.Context) error {
318+
return nil
319+
})(ctx)
320+
}()
321+
307322
// will notify main thread to kill and will handle gracefully
308323
lk.SignalChannel <- syscall.SIGINT
309324
case keyboard.KeyEnter:

Diff for: internal/tracing/attributes.go

+19
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ type Metrics struct {
4242
CountIncludesRemote int
4343
}
4444

45+
type KeyboardMetrics struct {
46+
EnabledViewDockerDesktop bool
47+
HasWatchConfig bool
48+
ActivateViewDockerDesktop bool
49+
ActivateWatch bool
50+
}
51+
4552
func (s SpanOptions) SpanStartOptions() []trace.SpanStartOption {
4653
out := make([]trace.SpanStartOption, len(s))
4754
for i := range s {
@@ -135,6 +142,18 @@ func ServiceOptions(service types.ServiceConfig) SpanOptions {
135142
}
136143
}
137144

145+
func KeyboardOptions(metrics KeyboardMetrics) SpanOptions {
146+
attrs := []attribute.KeyValue{
147+
attribute.Bool("view.enabled", metrics.EnabledViewDockerDesktop),
148+
attribute.Bool("view.activated", metrics.ActivateViewDockerDesktop),
149+
attribute.Bool("watch.activated", metrics.ActivateWatch),
150+
attribute.Bool("watch.config", metrics.HasWatchConfig),
151+
}
152+
return []trace.SpanStartEventOption{
153+
trace.WithAttributes(attrs...),
154+
}
155+
}
156+
138157
// ContainerOptions returns common attributes from a Moby container.
139158
//
140159
// For convenience, it's returned as a SpanOptions object to allow it to be

0 commit comments

Comments
 (0)