Skip to content

Commit 503d075

Browse files
Fix version property conflict (#101)
1 parent 94a89fe commit 503d075

1 file changed

Lines changed: 21 additions & 17 deletions

File tree

internal/tiger/analytics/analytics.go

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package analytics
22

33
import (
44
"context"
5+
"maps"
56
"os"
67
"runtime"
78
"slices"
@@ -137,17 +138,18 @@ func Error(err error) Option {
137138
// identification is only sent if the client is initialized and analytics are
138139
// enabled in the config, otherwise it is skipped.
139140
func (a *Analytics) Identify(event string, options ...Option) {
140-
// Create properties map with default/common properties
141+
// Create properties map with user-provided properties
141142
properties := map[string]any{}
142-
if a.projectID != "" {
143-
properties["project_id"] = a.projectID
144-
}
145-
146-
// Merge in user-provided properties (they can override common properties if needed)
147143
for _, option := range options {
148144
option(properties)
149145
}
150146

147+
// Merge in default/common properties, overwriting user-provided properties
148+
// if there's a conflict (we always want these properties to be accurate)
149+
if a.projectID != "" {
150+
properties["project_id"] = a.projectID
151+
}
152+
151153
logger := logging.GetLogger().With(
152154
zap.Any("properties", properties),
153155
)
@@ -194,22 +196,24 @@ func (a *Analytics) Identify(event string, options ...Option) {
194196
// architecture. Events are only sent if the client is initialized and
195197
// analytics are enabled in the config, otherwise they are skipped.
196198
func (a *Analytics) Track(event string, options ...Option) {
197-
// Create properties map with default/common properties
198-
properties := map[string]any{
199-
"source": "cli",
200-
"version": config.Version,
201-
"os": runtime.GOOS,
202-
"arch": runtime.GOARCH,
199+
// Create properties map with user-provided properties
200+
properties := map[string]any{}
201+
for _, option := range options {
202+
option(properties)
203203
}
204+
205+
// Merge in default/common properties, overwriting user-provided properties
206+
// if there's a conflict (we always want these properties to be accurate)
207+
maps.Copy(properties, map[string]any{
208+
"source": "cli",
209+
"cli_version": config.Version,
210+
"os": runtime.GOOS,
211+
"arch": runtime.GOARCH,
212+
})
204213
if a.projectID != "" {
205214
properties["project_id"] = a.projectID
206215
}
207216

208-
// Merge in user-provided properties (they can override common properties if needed)
209-
for _, option := range options {
210-
option(properties)
211-
}
212-
213217
logger := logging.GetLogger().With(
214218
zap.String("event", event),
215219
zap.Any("properties", properties),

0 commit comments

Comments
 (0)