Skip to content

Commit c1e986c

Browse files
Andrew Ellisonmarinalimeira
andauthored
Feature/telemetry forwarder (#90)
* Update mixpanel telemetry to use forwarder * allow custom url * clean dependencies * Update telemetry/mixpanel.go Co-authored-by: Marina <marinaflessa@gmail.com> --------- Co-authored-by: Marina <marinaflessa@gmail.com>
1 parent 9517ad3 commit c1e986c

File tree

3 files changed

+31
-20
lines changed

3 files changed

+31
-20
lines changed

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ require (
1515
github.com/fatih/color v1.13.0
1616
github.com/go-errors/errors v1.4.2
1717
github.com/google/go-github/v44 v44.1.0
18+
github.com/google/uuid v1.2.0
1819
github.com/gruntwork-io/terratest v0.41.0
1920
github.com/hashicorp/go-multierror v1.1.1
2021
github.com/mattn/go-zglob v0.0.3
@@ -24,7 +25,6 @@ require (
2425
golang.org/x/crypto v0.1.0
2526
golang.org/x/exp v0.0.0-20221106115401-f9659909a136
2627
golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c
27-
vizzlo.com/mixpanel v1.2.0
2828
)
2929

3030
require (
@@ -62,7 +62,6 @@ require (
6262
github.com/google/go-github/v29 v29.0.2 // indirect
6363
github.com/google/go-querystring v1.1.0 // indirect
6464
github.com/google/gofuzz v1.1.0 // indirect
65-
github.com/google/uuid v1.2.0 // indirect
6665
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
6766
github.com/googleapis/gnostic v0.4.1 // indirect
6867
github.com/hashicorp/errwrap v1.0.0 // indirect

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -828,5 +828,3 @@ sigs.k8s.io/structured-merge-diff/v4 v4.0.3/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK
828828
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
829829
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
830830
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
831-
vizzlo.com/mixpanel v1.2.0 h1:ip0yFM9mIgAKDB0yIkUB2y+C2n+6MXaQ0KQk3DyISjE=
832-
vizzlo.com/mixpanel v1.2.0/go.mod h1:bmKnyCOO+/6SRhjujPG6ARtNJdTRepmA/TH+Nt/1GyU=

telemetry/mixpanel.go

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
package telemetry
22

33
import (
4+
"bytes"
5+
"encoding/json"
46
"github.com/google/uuid"
57
"log"
8+
"net/http"
69
"time"
7-
8-
"vizzlo.com/mixpanel"
910
)
1011

1112
type MixpanelTelemetryTracker struct {
12-
clientId string
13-
client *mixpanel.Client
14-
appName string
15-
version string
16-
runId string
13+
client *http.Client
14+
url string
15+
appName string
16+
version string
17+
runId string
1718
}
1819

1920
/*
@@ -42,20 +43,33 @@ func (m MixpanelTelemetryTracker) TrackEvent(eventContext EventContext, eventPro
4243
// Combine our baseline props that we send for _ALL_ events with the passed in props from the event
4344
trackProps := mergeMaps(baseProps, eventProps)
4445

45-
err := m.client.Track(m.runId, eventContext.EventName, trackProps)
46-
46+
request := map[string]interface{}{
47+
"id": m.runId,
48+
"event": eventContext.EventName,
49+
"eventProps": trackProps,
50+
}
51+
jsonStr, err := json.Marshal(request)
52+
if err != nil {
53+
log.Println(err.Error())
54+
return
55+
}
56+
resp, err := m.client.Post(m.url, "application/json", bytes.NewBuffer(jsonStr))
57+
if err != nil {
58+
log.Println(err.Error())
59+
return
60+
}
61+
err = resp.Body.Close()
4762
if err != nil {
4863
log.Println(err.Error())
4964
}
5065
}
5166

52-
func NewMixPanelTelemetryClient(clientId string, appName string, version string) MixpanelTelemetryTracker {
53-
mixpanelClient := mixpanel.New(clientId)
67+
func NewMixPanelTelemetryClient(url string, appName string, version string) MixpanelTelemetryTracker {
5468
return MixpanelTelemetryTracker{
55-
client: mixpanelClient,
56-
clientId: clientId,
57-
appName: appName,
58-
version: version,
59-
runId: uuid.New().String(),
69+
client: &http.Client{},
70+
url: url,
71+
appName: appName,
72+
version: version,
73+
runId: uuid.New().String(),
6074
}
6175
}

0 commit comments

Comments
 (0)