Skip to content
This repository was archived by the owner on Jul 10, 2024. It is now read-only.

Commit 332ff31

Browse files
[POA-41] Update analytics functions to support amplitude functions (#246)
* Replace Segment related keys and mentioned with Amplitude Keys and configs * Updated few event names to make them consistent in Amplitude
1 parent 3db5466 commit 332ff31

File tree

5 files changed

+42
-39
lines changed

5 files changed

+42
-39
lines changed

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func preRun(cmd *cobra.Command, args []string) {
7777
rest.Domain = rest.DefaultDomain()
7878
}
7979

80-
// Initialize Segment-based telemetry of usage information and CLI errors.
80+
// Initialize Amplitude-based telemetry of usage information and CLI errors.
8181
telemetry.Init(true)
8282

8383
switch logFormatFlag {

go.mod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/OneOfOne/xxhash v1.2.8
88
github.com/Pallinder/go-randomdata v1.2.0
99
github.com/akitasoftware/akita-ir v0.0.0-20220630210013-8926783978fe
10-
github.com/akitasoftware/akita-libs v0.0.0-20230708003852-6c8da9931921
10+
github.com/akitasoftware/akita-libs v0.0.0-20231215074746-59e2f35abf36
1111
github.com/akitasoftware/go-utils v0.0.0-20221207014235-6f4c9079488d
1212
github.com/akitasoftware/plugin-flickr v0.2.0
1313
github.com/andybalholm/brotli v1.0.1
@@ -38,7 +38,7 @@ require (
3838
github.com/spf13/cobra v1.6.0
3939
github.com/spf13/pflag v1.0.5
4040
github.com/spf13/viper v1.7.1
41-
github.com/stretchr/testify v1.8.0
41+
github.com/stretchr/testify v1.8.1
4242
github.com/yudai/gojsondiff v1.0.0
4343
golang.org/x/exp v0.0.0-20220428152302-39d4317da171
4444
golang.org/x/term v0.5.0
@@ -51,6 +51,7 @@ require (
5151

5252
require (
5353
github.com/akitasoftware/objecthash-proto v0.0.0-20211020162104-173a34b1afb0 // indirect
54+
github.com/amplitude/analytics-go v1.0.1 // indirect
5455
github.com/aws/aws-sdk-go-v2/credentials v1.12.23 // indirect
5556
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.19 // indirect
5657
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.25 // indirect
@@ -72,6 +73,7 @@ require (
7273
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
7374
github.com/hashicorp/go-multierror v1.1.1 // indirect
7475
github.com/hashicorp/hcl v1.0.0 // indirect
76+
github.com/iancoleman/strcase v0.3.0 // indirect
7577
github.com/inconshreveable/mousetrap v1.0.1 // indirect
7678
github.com/jmespath/go-jmespath v0.4.0 // indirect
7779
github.com/json-iterator/go v1.1.12 // indirect

go.sum

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ github.com/akitasoftware/akita-ir v0.0.0-20211020161529-944af4d11d6e/go.mod h1:W
3131
github.com/akitasoftware/akita-ir v0.0.0-20220630210013-8926783978fe h1:0BeBDjLDFPwv2bkk6YuRAPf1r6U4Wby98NHI9+Lddvs=
3232
github.com/akitasoftware/akita-ir v0.0.0-20220630210013-8926783978fe/go.mod h1:WEWPzhZtxlJnov3MxcqSDiZaHHf00vs3aJwCdt3OwzA=
3333
github.com/akitasoftware/akita-libs v0.0.0-20211020162041-fe02207174fb/go.mod h1:YLFCjhwQ0ZFfYWSUD2c9KYKEeBn+R+Cz+A5SitXvJz8=
34-
github.com/akitasoftware/akita-libs v0.0.0-20230708003852-6c8da9931921 h1:Dyka6J+ts8JEcvMwmRMll8h8Hy435Q4uaBX0odiMxe4=
35-
github.com/akitasoftware/akita-libs v0.0.0-20230708003852-6c8da9931921/go.mod h1:qufiDcBb7r0oemPbxlXk9HUSyDt5rLO0PQGFOWRx3y4=
34+
github.com/akitasoftware/akita-libs v0.0.0-20231215074746-59e2f35abf36 h1:7z3N2D1WNZBSwiVMBdvgq0jam2Vc/Hc6mr94Vdh8egg=
35+
github.com/akitasoftware/akita-libs v0.0.0-20231215074746-59e2f35abf36/go.mod h1:Wo3rkItMZBjXszdCutVK5I6QNMMEslN+ltRSS7C03jk=
3636
github.com/akitasoftware/go-utils v0.0.0-20221207014235-6f4c9079488d h1:pN1dbNacZ/mvlU1NcJVDxqmKnrDQDTVaN6iKOarfdYM=
3737
github.com/akitasoftware/go-utils v0.0.0-20221207014235-6f4c9079488d/go.mod h1:+IOXf7l/QCAQECJzjJwhTp1sBkRoJ6WciZwJezUwBa4=
3838
github.com/akitasoftware/gopacket v1.1.18-0.20210730205736-879e93dac35b h1:toBhS5rhCjo/N4YZ1cYtlsdSTGjMFH+gbJGCc+OmZiY=
@@ -51,6 +51,8 @@ github.com/alecthomas/kong v0.2.4/go.mod h1:kQOmtJgV+Lb4aj+I2LEn40cbtawdWJ9Y8QLq
5151
github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ=
5252
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
5353
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
54+
github.com/amplitude/analytics-go v1.0.1 h1:rrdC5VBctlJigSk0kw7ktwSijob/wyH4bop2SqWduCU=
55+
github.com/amplitude/analytics-go v1.0.1/go.mod h1:kAQG8OQ6aPOxZrEZ3+/NFCfxdYSyjqXZhgkjWFD3/vo=
5456
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=
5557
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
5658
github.com/andybalholm/brotli v1.0.1 h1:KqhlKozYbRtJvsPrrEeXcO+N2l6NYT5A2QAFmSULpEc=
@@ -241,6 +243,8 @@ github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174/go.mod h1:DqJ97dSdRW
241243
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog=
242244
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68=
243245
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
246+
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
247+
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
244248
github.com/inconshreveable/log15 v0.0.0-20170622235902-74a0988b5f80/go.mod h1:cOaXtrgN4ScfRrD9Bre7U1thNq5RtJ8ZoP4iXVGRj6o=
245249
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
246250
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
@@ -407,6 +411,8 @@ github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5q
407411
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
408412
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
409413
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
414+
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
415+
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
410416
github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
411417
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
412418
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
@@ -415,8 +421,9 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
415421
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
416422
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
417423
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
418-
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
419424
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
425+
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
426+
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
420427
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
421428
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
422429
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=

telemetry/telemetry.go

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var (
2424
analyticsEnabled bool
2525

2626
// Client key; set at link-time with -X flag
27-
defaultSegmentKey = ""
27+
defaultAmplitudeKey = ""
2828

2929
// Store the distinct ID; run through the process
3030
// of getting it only once.
@@ -64,16 +64,16 @@ func Init(isLoggingEnabled bool) {
6464
}
6565

6666
// If unset, will be "" and we'll use the default
67-
segmentEndpoint := os.Getenv("AKITA_SEGMENT_ENDPOINT")
67+
amplitudeEndpoint := os.Getenv("POSTMAN_LC_AGENT_AMPLITUDE_ENDPOINT")
6868

6969
// If unset, will use this hard-coded value.
70-
segmentKey := os.Getenv("AKITA_SEGMENT_WRITE_KEY")
71-
if segmentKey == "" {
72-
segmentKey = defaultSegmentKey
70+
amplitudeKey := os.Getenv("POSTMAN_LC_AGENT_AMPLITUDE_WRITE_KEY")
71+
if amplitudeKey == "" {
72+
amplitudeKey = defaultAmplitudeKey
7373
}
74-
if segmentKey == "" {
74+
if amplitudeKey == "" {
7575
if isLoggingEnabled {
76-
printer.Infof("Telemetry unavailable; no Segment key configured.\n")
76+
printer.Infof("Telemetry unavailable; no Amplitude key configured.\n")
7777
printer.Infof("This is caused by building from source rather than using an official build.\n")
7878
}
7979
analyticsClient = nullClient{}
@@ -83,23 +83,25 @@ func Init(isLoggingEnabled bool) {
8383
var err error
8484
analyticsClient, err = analytics.NewClient(
8585
analytics.Config{
86-
WriteKey: segmentKey,
87-
SegmentEndpoint: segmentEndpoint,
86+
// Enable analytics for Amplitude only
87+
IsAmplitudeEnabled: true,
88+
AmplitudeConfig: analytics.AmplitudeConfig{
89+
AmplitudeAPIKey: amplitudeKey,
90+
AmplitudeEndpoint: amplitudeEndpoint,
91+
// No output from the Amplitude library
92+
IsLoggingEnabled: false,
93+
},
8894
App: analytics.AppInfo{
8995
Name: "akita-cli",
9096
Version: version.ReleaseVersion().String(),
9197
Build: version.GitVersion(),
9298
Namespace: "",
9399
},
94-
// No output from the Segment library
95-
IsLoggingEnabled: false,
96-
// IsMixpanelEnabled: false, -- irrelevant for us, leaving at default value
97-
BatchSize: 1, // disable batching
98100
},
99101
)
100102
if err != nil {
101103
if isLoggingEnabled {
102-
printer.Infof("Telemetry unavailable; error setting up Segment client: %v\n", err)
104+
printer.Infof("Telemetry unavailable; error setting up Analytics(Amplitude) client: %v\n", err)
103105
printer.Infof("Postman support will not be able to see any errors you encounter.\n")
104106
printer.Infof("Please send this log message to observability-support@postman.com.\n")
105107
}
@@ -114,7 +116,7 @@ func getDistinctID() string {
114116
// Otherwise use the configured API Key.
115117
// Failing that, try to use the user name and host name?
116118

117-
id := os.Getenv("AKITA_SEGMENT_DISTINCT_ID")
119+
id := os.Getenv("POSTMAN_ANALYTICS_DISTINCT_ID")
118120
if id != "" {
119121
return id
120122
}
@@ -245,7 +247,7 @@ func RateLimitError(inContext string, e error) {
245247
// Report an error in a particular API, including the text of the error.
246248
func APIError(method string, path string, e error) {
247249
analyticsClient.Track(distinctID(),
248-
fmt.Sprintf("Error calling API"),
250+
"Error calling API",
249251
map[string]any{
250252
"method": method,
251253
"path": path,
@@ -255,10 +257,10 @@ func APIError(method string, path string, e error) {
255257
)
256258
}
257259

258-
// Report a failure withoout a specific error object
260+
// Report a failure without a specific error object
259261
func Failure(message string) {
260262
analyticsClient.Track(distinctID(),
261-
message,
263+
fmt.Sprintf("Unknown Error: %s", message),
262264
map[string]any{
263265
"type": "error",
264266
},
@@ -268,7 +270,7 @@ func Failure(message string) {
268270
// Report success of an operation
269271
func Success(message string) {
270272
analyticsClient.Track(distinctID(),
271-
message,
273+
fmt.Sprintf("Success in %s", message),
272274
map[string]any{
273275
"type": "success",
274276
},
@@ -278,7 +280,7 @@ func Success(message string) {
278280
// Report a step in a multi-part workflow.
279281
func WorkflowStep(workflow string, message string) {
280282
analyticsClient.Track(distinctID(),
281-
message,
283+
fmt.Sprintf("Executing Step: %s", message),
282284
map[string]any{
283285
"type": "workflow",
284286
"workflow": workflow,

trace/backend_collector_test.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,24 +105,16 @@ func TestObfuscate(t *testing.T) {
105105
},
106106
Args: map[string]*pb.Data{
107107
"nxnOc5Qy3D4=": newTestBodySpecFromStruct(0, pb.HTTPBody_JSON, "application/json", map[string]*pb.Data{
108-
"name": dataFromPrimitive(spec_util.NewPrimitiveString(
109-
"lgkXNsG1k7-cxarrFoo-MmhjoRP3YOXV3C0k6rrKy2A="),
110-
),
111-
"number": dataFromPrimitive(spec_util.NewPrimitiveInt64(8191886688482385179)),
108+
"name": dataFromPrimitive(spec_util.NewPrimitiveString("")),
109+
"number": dataFromPrimitive(spec_util.NewPrimitiveInt64(0)),
112110
}),
113111
},
114112
Responses: map[string]*pb.Data{
115113
"AyBUQkT0SHU=": newTestBodySpecFromStruct(200, pb.HTTPBody_JSON, "application/json", map[string]*pb.Data{
116114
"homes": dataFromList(
117-
dataFromPrimitive(spec_util.NewPrimitiveString(
118-
"hZwXhGMIxoOotCt-Cu4toMf9g8CpZnOdUe3bPxEn_Sg="),
119-
),
120-
dataFromPrimitive(spec_util.NewPrimitiveString(
121-
"ESrSgUKxboEvBrJrfm6z9xQKnegYZ_YUcOaZ4il3ytY="),
122-
),
123-
dataFromPrimitive(spec_util.NewPrimitiveString(
124-
"M7hhiIKycdahIkwhrHNl9gDQSxzbbcElQMyvDOPiJhI="),
125-
),
115+
dataFromPrimitive(spec_util.NewPrimitiveString("")),
116+
dataFromPrimitive(spec_util.NewPrimitiveString("")),
117+
dataFromPrimitive(spec_util.NewPrimitiveString("")),
126118
),
127119
}),
128120
},

0 commit comments

Comments
 (0)