Skip to content

Commit

Permalink
[POA-41] Update analytics functions to support amplitude functions (#246
Browse files Browse the repository at this point in the history
)

* Replace Segment related keys and mentioned with Amplitude Keys and
configs
* Updated few event names to make them consistent in Amplitude
  • Loading branch information
mudit-postman committed Dec 18, 2023
1 parent 3db5466 commit 332ff31
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 39 deletions.
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func preRun(cmd *cobra.Command, args []string) {
rest.Domain = rest.DefaultDomain()
}

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

switch logFormatFlag {
Expand Down
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/OneOfOne/xxhash v1.2.8
github.com/Pallinder/go-randomdata v1.2.0
github.com/akitasoftware/akita-ir v0.0.0-20220630210013-8926783978fe
github.com/akitasoftware/akita-libs v0.0.0-20230708003852-6c8da9931921
github.com/akitasoftware/akita-libs v0.0.0-20231215074746-59e2f35abf36
github.com/akitasoftware/go-utils v0.0.0-20221207014235-6f4c9079488d
github.com/akitasoftware/plugin-flickr v0.2.0
github.com/andybalholm/brotli v1.0.1
Expand Down Expand Up @@ -38,7 +38,7 @@ require (
github.com/spf13/cobra v1.6.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.8.0
github.com/stretchr/testify v1.8.1
github.com/yudai/gojsondiff v1.0.0
golang.org/x/exp v0.0.0-20220428152302-39d4317da171
golang.org/x/term v0.5.0
Expand All @@ -51,6 +51,7 @@ require (

require (
github.com/akitasoftware/objecthash-proto v0.0.0-20211020162104-173a34b1afb0 // indirect
github.com/amplitude/analytics-go v1.0.1 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.12.23 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.19 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.25 // indirect
Expand All @@ -72,6 +73,7 @@ require (
github.com/hashicorp/go-cleanhttp v0.5.1 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/iancoleman/strcase v0.3.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
Expand Down
13 changes: 10 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ github.com/akitasoftware/akita-ir v0.0.0-20211020161529-944af4d11d6e/go.mod h1:W
github.com/akitasoftware/akita-ir v0.0.0-20220630210013-8926783978fe h1:0BeBDjLDFPwv2bkk6YuRAPf1r6U4Wby98NHI9+Lddvs=
github.com/akitasoftware/akita-ir v0.0.0-20220630210013-8926783978fe/go.mod h1:WEWPzhZtxlJnov3MxcqSDiZaHHf00vs3aJwCdt3OwzA=
github.com/akitasoftware/akita-libs v0.0.0-20211020162041-fe02207174fb/go.mod h1:YLFCjhwQ0ZFfYWSUD2c9KYKEeBn+R+Cz+A5SitXvJz8=
github.com/akitasoftware/akita-libs v0.0.0-20230708003852-6c8da9931921 h1:Dyka6J+ts8JEcvMwmRMll8h8Hy435Q4uaBX0odiMxe4=
github.com/akitasoftware/akita-libs v0.0.0-20230708003852-6c8da9931921/go.mod h1:qufiDcBb7r0oemPbxlXk9HUSyDt5rLO0PQGFOWRx3y4=
github.com/akitasoftware/akita-libs v0.0.0-20231215074746-59e2f35abf36 h1:7z3N2D1WNZBSwiVMBdvgq0jam2Vc/Hc6mr94Vdh8egg=
github.com/akitasoftware/akita-libs v0.0.0-20231215074746-59e2f35abf36/go.mod h1:Wo3rkItMZBjXszdCutVK5I6QNMMEslN+ltRSS7C03jk=
github.com/akitasoftware/go-utils v0.0.0-20221207014235-6f4c9079488d h1:pN1dbNacZ/mvlU1NcJVDxqmKnrDQDTVaN6iKOarfdYM=
github.com/akitasoftware/go-utils v0.0.0-20221207014235-6f4c9079488d/go.mod h1:+IOXf7l/QCAQECJzjJwhTp1sBkRoJ6WciZwJezUwBa4=
github.com/akitasoftware/gopacket v1.1.18-0.20210730205736-879e93dac35b h1:toBhS5rhCjo/N4YZ1cYtlsdSTGjMFH+gbJGCc+OmZiY=
Expand All @@ -51,6 +51,8 @@ github.com/alecthomas/kong v0.2.4/go.mod h1:kQOmtJgV+Lb4aj+I2LEn40cbtawdWJ9Y8QLq
github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/amplitude/analytics-go v1.0.1 h1:rrdC5VBctlJigSk0kw7ktwSijob/wyH4bop2SqWduCU=
github.com/amplitude/analytics-go v1.0.1/go.mod h1:kAQG8OQ6aPOxZrEZ3+/NFCfxdYSyjqXZhgkjWFD3/vo=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
github.com/andybalholm/brotli v1.0.1 h1:KqhlKozYbRtJvsPrrEeXcO+N2l6NYT5A2QAFmSULpEc=
Expand Down Expand Up @@ -241,6 +243,8 @@ github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174/go.mod h1:DqJ97dSdRW
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec h1:qv2VnGeEQHchGaZ/u7lxST/RaJw+cv273q79D81Xbog=
github.com/hinshun/vt10x v0.0.0-20220119200601-820417d04eec/go.mod h1:Q48J4R4DvxnHolD5P8pOtXigYlRuPLGl6moFx3ulM68=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/inconshreveable/log15 v0.0.0-20170622235902-74a0988b5f80/go.mod h1:cOaXtrgN4ScfRrD9Bre7U1thNq5RtJ8ZoP4iXVGRj6o=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
Expand Down Expand Up @@ -407,6 +411,8 @@ github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5q
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0 h1:1zr/of2m5FGMsad5YfcqgdqdWrIhu+EBEJRhR1U7z/c=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.2.1/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
Expand All @@ -415,8 +421,9 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
Expand Down
42 changes: 22 additions & 20 deletions telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var (
analyticsEnabled bool

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

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

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

// If unset, will use this hard-coded value.
segmentKey := os.Getenv("AKITA_SEGMENT_WRITE_KEY")
if segmentKey == "" {
segmentKey = defaultSegmentKey
amplitudeKey := os.Getenv("POSTMAN_LC_AGENT_AMPLITUDE_WRITE_KEY")
if amplitudeKey == "" {
amplitudeKey = defaultAmplitudeKey
}
if segmentKey == "" {
if amplitudeKey == "" {
if isLoggingEnabled {
printer.Infof("Telemetry unavailable; no Segment key configured.\n")
printer.Infof("Telemetry unavailable; no Amplitude key configured.\n")
printer.Infof("This is caused by building from source rather than using an official build.\n")
}
analyticsClient = nullClient{}
Expand All @@ -83,23 +83,25 @@ func Init(isLoggingEnabled bool) {
var err error
analyticsClient, err = analytics.NewClient(
analytics.Config{
WriteKey: segmentKey,
SegmentEndpoint: segmentEndpoint,
// Enable analytics for Amplitude only
IsAmplitudeEnabled: true,
AmplitudeConfig: analytics.AmplitudeConfig{
AmplitudeAPIKey: amplitudeKey,
AmplitudeEndpoint: amplitudeEndpoint,
// No output from the Amplitude library
IsLoggingEnabled: false,
},
App: analytics.AppInfo{
Name: "akita-cli",
Version: version.ReleaseVersion().String(),
Build: version.GitVersion(),
Namespace: "",
},
// No output from the Segment library
IsLoggingEnabled: false,
// IsMixpanelEnabled: false, -- irrelevant for us, leaving at default value
BatchSize: 1, // disable batching
},
)
if err != nil {
if isLoggingEnabled {
printer.Infof("Telemetry unavailable; error setting up Segment client: %v\n", err)
printer.Infof("Telemetry unavailable; error setting up Analytics(Amplitude) client: %v\n", err)
printer.Infof("Postman support will not be able to see any errors you encounter.\n")
printer.Infof("Please send this log message to observability-support@postman.com.\n")
}
Expand All @@ -114,7 +116,7 @@ func getDistinctID() string {
// Otherwise use the configured API Key.
// Failing that, try to use the user name and host name?

id := os.Getenv("AKITA_SEGMENT_DISTINCT_ID")
id := os.Getenv("POSTMAN_ANALYTICS_DISTINCT_ID")
if id != "" {
return id
}
Expand Down Expand Up @@ -245,7 +247,7 @@ func RateLimitError(inContext string, e error) {
// Report an error in a particular API, including the text of the error.
func APIError(method string, path string, e error) {
analyticsClient.Track(distinctID(),
fmt.Sprintf("Error calling API"),
"Error calling API",
map[string]any{
"method": method,
"path": path,
Expand All @@ -255,10 +257,10 @@ func APIError(method string, path string, e error) {
)
}

// Report a failure withoout a specific error object
// Report a failure without a specific error object
func Failure(message string) {
analyticsClient.Track(distinctID(),
message,
fmt.Sprintf("Unknown Error: %s", message),
map[string]any{
"type": "error",
},
Expand All @@ -268,7 +270,7 @@ func Failure(message string) {
// Report success of an operation
func Success(message string) {
analyticsClient.Track(distinctID(),
message,
fmt.Sprintf("Success in %s", message),
map[string]any{
"type": "success",
},
Expand All @@ -278,7 +280,7 @@ func Success(message string) {
// Report a step in a multi-part workflow.
func WorkflowStep(workflow string, message string) {
analyticsClient.Track(distinctID(),
message,
fmt.Sprintf("Executing Step: %s", message),
map[string]any{
"type": "workflow",
"workflow": workflow,
Expand Down
18 changes: 5 additions & 13 deletions trace/backend_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,16 @@ func TestObfuscate(t *testing.T) {
},
Args: map[string]*pb.Data{
"nxnOc5Qy3D4=": newTestBodySpecFromStruct(0, pb.HTTPBody_JSON, "application/json", map[string]*pb.Data{
"name": dataFromPrimitive(spec_util.NewPrimitiveString(
"lgkXNsG1k7-cxarrFoo-MmhjoRP3YOXV3C0k6rrKy2A="),
),
"number": dataFromPrimitive(spec_util.NewPrimitiveInt64(8191886688482385179)),
"name": dataFromPrimitive(spec_util.NewPrimitiveString("")),
"number": dataFromPrimitive(spec_util.NewPrimitiveInt64(0)),
}),
},
Responses: map[string]*pb.Data{
"AyBUQkT0SHU=": newTestBodySpecFromStruct(200, pb.HTTPBody_JSON, "application/json", map[string]*pb.Data{
"homes": dataFromList(
dataFromPrimitive(spec_util.NewPrimitiveString(
"hZwXhGMIxoOotCt-Cu4toMf9g8CpZnOdUe3bPxEn_Sg="),
),
dataFromPrimitive(spec_util.NewPrimitiveString(
"ESrSgUKxboEvBrJrfm6z9xQKnegYZ_YUcOaZ4il3ytY="),
),
dataFromPrimitive(spec_util.NewPrimitiveString(
"M7hhiIKycdahIkwhrHNl9gDQSxzbbcElQMyvDOPiJhI="),
),
dataFromPrimitive(spec_util.NewPrimitiveString("")),
dataFromPrimitive(spec_util.NewPrimitiveString("")),
dataFromPrimitive(spec_util.NewPrimitiveString("")),
),
}),
},
Expand Down

0 comments on commit 332ff31

Please sign in to comment.