Skip to content

Commit

Permalink
Bugfix/public event vars (#87)
Browse files Browse the repository at this point in the history
* make event context vars public

* Adds run ID

* handle distinct id within go-commons
  • Loading branch information
Andrew Ellison authored Mar 30, 2023
1 parent 7f35ac8 commit 362bd2d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ require (
golang.org/x/crypto v0.1.0
golang.org/x/exp v0.0.0-20221106115401-f9659909a136
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c
vizzlo.com/mixpanel v1.2.0
)

require (
Expand Down Expand Up @@ -118,5 +119,4 @@ require (
k8s.io/utils v0.0.0-20201110183641-67b214c5f920 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.0.3 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
vizzlo.com/mixpanel v1.2.0 // indirect
)
14 changes: 11 additions & 3 deletions telemetry/mixpanel.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package telemetry

import (
"github.com/google/uuid"
"log"
"time"

Expand All @@ -12,6 +13,7 @@ type MixpanelTelemetryTracker struct {
client *mixpanel.Client
appName string
version string
runId string
}

/*
Expand All @@ -33,14 +35,14 @@ func (m MixpanelTelemetryTracker) TrackEvent(eventContext EventContext, eventPro
baseProps := map[string]interface{}{
"timestamp": time.Now().Unix(),
"context": m.appName,
"command": eventContext.command,
"command": eventContext.Command,
"version": m.version,
}

// Combine our baseline props that we send for _ALL_ events with the passed in props from the event
trackProps := mergeMaps(baseProps, eventProps)

err := m.client.Track(m.clientId, eventContext.eventName, trackProps)
err := m.client.Track(m.runId, eventContext.EventName, trackProps)

if err != nil {
log.Fatal(err)
Expand All @@ -49,5 +51,11 @@ func (m MixpanelTelemetryTracker) TrackEvent(eventContext EventContext, eventPro

func NewMixPanelTelemetryClient(clientId string, appName string, version string) MixpanelTelemetryTracker {
mixpanelClient := mixpanel.New(clientId)
return MixpanelTelemetryTracker{client: mixpanelClient, clientId: clientId, appName: appName, version: version}
return MixpanelTelemetryTracker{
client: mixpanelClient,
clientId: clientId,
appName: appName,
version: version,
runId: uuid.New().String(),
}
}
4 changes: 2 additions & 2 deletions telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ type telemetryTracker interface {
}

type EventContext struct {
command string
eventName string
Command string
EventName string
}

0 comments on commit 362bd2d

Please sign in to comment.