Skip to content

Feature/telemetry forwarder #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/fatih/color v1.13.0
github.com/go-errors/errors v1.4.2
github.com/google/go-github/v44 v44.1.0
github.com/google/uuid v1.2.0
github.com/gruntwork-io/terratest v0.41.0
github.com/hashicorp/go-multierror v1.1.1
github.com/mattn/go-zglob v0.0.3
Expand All @@ -24,7 +25,6 @@ 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 @@ -62,7 +62,6 @@ require (
github.com/google/go-github/v29 v29.0.2 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/uuid v1.2.0 // indirect
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
github.com/googleapis/gnostic v0.4.1 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -828,5 +828,3 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.3/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
vizzlo.com/mixpanel v1.2.0 h1:ip0yFM9mIgAKDB0yIkUB2y+C2n+6MXaQ0KQk3DyISjE=
vizzlo.com/mixpanel v1.2.0/go.mod h1:bmKnyCOO+/6SRhjujPG6ARtNJdTRepmA/TH+Nt/1GyU=
46 changes: 30 additions & 16 deletions telemetry/mixpanel.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package telemetry

import (
"bytes"
"encoding/json"
"github.com/google/uuid"
"log"
"net/http"
"time"

"vizzlo.com/mixpanel"
)

type MixpanelTelemetryTracker struct {
clientId string
client *mixpanel.Client
appName string
version string
runId string
client *http.Client
url string
appName string
version string
runId string
}

/*
Expand Down Expand Up @@ -42,20 +43,33 @@ func (m MixpanelTelemetryTracker) TrackEvent(eventContext EventContext, eventPro
// 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.runId, eventContext.EventName, trackProps)

request := map[string]interface{}{
"id": m.runId,
"event": eventContext.EventName,
"eventProps": trackProps,
}
jsonStr, err := json.Marshal(request)
if err != nil {
log.Println(err.Error())
return
}
resp, err := m.client.Post(m.url, "application/json", bytes.NewBuffer(jsonStr))
if err != nil {
log.Println(err.Error())
return
}
err = resp.Body.Close()
if err != nil {
log.Println(err.Error())
}
}

func NewMixPanelTelemetryClient(clientId string, appName string, version string) MixpanelTelemetryTracker {
mixpanelClient := mixpanel.New(clientId)
func NewMixPanelTelemetryClient(url string, appName string, version string) MixpanelTelemetryTracker {
return MixpanelTelemetryTracker{
client: mixpanelClient,
clientId: clientId,
appName: appName,
version: version,
runId: uuid.New().String(),
client: &http.Client{},
url: url,
appName: appName,
version: version,
runId: uuid.New().String(),
}
}