Skip to content

Commit aec5805

Browse files
committed
imrpove telemetry
Signed-off-by: Joana Hrotko <[email protected]>
1 parent 369e713 commit aec5805

File tree

3 files changed

+73
-25
lines changed

3 files changed

+73
-25
lines changed

Diff for: cmd/formatter/shortcut.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,7 @@ func NewKeyboardManager(isDockerDesktopActive, isWatchConfigured bool,
132132

133133
km.signalChannel = sc
134134

135-
km.metrics = tracing.KeyboardMetrics{
136-
EnabledViewDockerDesktop: isDockerDesktopActive,
137-
HasWatchConfig: isWatchConfigured,
138-
}
135+
km.metrics = tracing.NewKeyboardMetrics(isDockerDesktopActive, isWatchConfigured)
139136

140137
KeyboardManager = &km
141138

@@ -237,7 +234,7 @@ func (lk *LogKeyboard) openDockerDesktop(project *types.Project) {
237234
if !lk.IsDockerDesktopActive {
238235
return
239236
}
240-
lk.metrics.ActivateViewDockerDesktop = true
237+
lk.metrics.RegisterCommand(tracing.GUI)
241238
link := fmt.Sprintf("docker-desktop://dashboard/apps/%s", project.Name)
242239
err := open.Run(link)
243240
if err != nil {
@@ -276,7 +273,9 @@ func (lk *LogKeyboard) HandleKeyEvents(event keyboard.KeyEvent, ctx context.Cont
276273
case 'v':
277274
lk.openDockerDesktop(project)
278275
case 'w':
279-
lk.metrics.ActivateWatch = true
276+
if !lk.Watch.isWatching() {
277+
lk.metrics.RegisterCommand(tracing.WATCH)
278+
}
280279
lk.StartWatch(ctx, project, options)
281280
}
282281
switch key := event.Key; key {

Diff for: internal/tracing/attributes.go

+11-19
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@ 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-
5245
func (s SpanOptions) SpanStartOptions() []trace.SpanStartOption {
5346
out := make([]trace.SpanStartOption, len(s))
5447
for i := range s {
@@ -142,18 +135,6 @@ func ServiceOptions(service types.ServiceConfig) SpanOptions {
142135
}
143136
}
144137

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-
157138
// ContainerOptions returns common attributes from a Moby container.
158139
//
159140
// For convenience, it's returned as a SpanOptions object to allow it to be
@@ -175,6 +156,17 @@ func ContainerOptions(container moby.Container) SpanOptions {
175156
}
176157
}
177158

159+
func KeyboardOptions(metrics KeyboardMetrics) SpanOptions {
160+
attrs := []attribute.KeyValue{
161+
attribute.Bool("navmenu.enabled", metrics.enabled),
162+
attribute.StringSlice("navmenu.command", CommandSliceToString(metrics.command)),
163+
attribute.StringSlice("navmenu.command_available", CommandSliceToString(metrics.commandAvailable)),
164+
}
165+
return []trace.SpanStartEventOption{
166+
trace.WithAttributes(attrs...),
167+
}
168+
}
169+
178170
func keys[T any](m map[string]T) []string {
179171
out := make([]string, 0, len(m))
180172
for k := range m {

Diff for: internal/tracing/keyboard_metrics.go

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
Copyright 2024 Docker Compose CLI authors
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package tracing
18+
19+
type KeyboardMetrics struct {
20+
enabled bool
21+
command []Command
22+
commandAvailable []Command
23+
}
24+
25+
type Command string
26+
27+
const (
28+
GUI Command = "gui"
29+
WATCH Command = "watch"
30+
DEBUG Command = "debug"
31+
)
32+
33+
func NewKeyboardMetrics(IsDockerDesktopActive, isWatchConfigured bool) KeyboardMetrics {
34+
metrics := KeyboardMetrics{
35+
enabled: true,
36+
commandAvailable: []Command{},
37+
}
38+
if IsDockerDesktopActive {
39+
metrics.commandAvailable = append(metrics.commandAvailable, GUI)
40+
}
41+
if isWatchConfigured {
42+
metrics.commandAvailable = append(metrics.commandAvailable, WATCH)
43+
}
44+
return metrics
45+
}
46+
47+
func (metrics *KeyboardMetrics) RegisterCommand(command Command) {
48+
metrics.command = append(metrics.command, command)
49+
}
50+
51+
func CommandSliceToString(lst []Command) []string {
52+
result := []string{}
53+
for _, c := range lst {
54+
result = append(result, string(c))
55+
}
56+
return result
57+
}

0 commit comments

Comments
 (0)