Skip to content

Commit

Permalink
minor changes on events and build
Browse files Browse the repository at this point in the history
  • Loading branch information
JulesFaucherre committed Aug 1, 2023
1 parent f6d26cc commit c2680d8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ GOOS=$(shell go env GOOS)
GOARCH=$(shell go env GOARCH)

build: always
go build -o build/$(GOOS)/$(GOARCH)/circleci
go build -o build/$(GOOS)/$(GOARCH)/circleci -ldflags="-X 'github.com/CircleCI-Public/circleci-cli/telemetry.SegmentEndpoint=' -X 'github.com/CircleCI-Public/circleci-cli/telemetry.SegmentKey="`echo ${SEGMENT_KEY}`"'"

build-all: build/linux/amd64/circleci build/darwin/amd64/circleci

Expand Down
26 changes: 18 additions & 8 deletions telemetry/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func createEventFromCommandInfo(name string, cmdInfo CommandInfo) Event {
for key, value := range cmdInfo.LocalArgs {
properties[fmt.Sprintf("cmd.flag.%s", key)] = value
}
properties["has_been_executed"] = false

return Event{
Object: fmt.Sprintf("cli-%s", name),
Expand All @@ -26,28 +27,34 @@ func createEventFromCommandInfo(name string, cmdInfo CommandInfo) Event {
}

func errorToProperties(err error) map[string]interface{} {
if err == nil {
return nil
properties := map[string]interface{}{
"has_been_executed": true,
}
return map[string]interface{}{
"error": err.Error(),

if err != nil {
properties["error"] = err.Error()
}
return properties
}

func CreateSetupEvent(isServerCustomer bool) Event {
return Event{
Object: "cli-setup",
Action: "setup",
Properties: map[string]interface{}{
"is_server_customer": isServerCustomer,
"has_been_executed": true,
},
}
}

func CreateVersionEvent(version string) Event {
return Event{
Object: "cli-version",
Action: "version",
Properties: map[string]interface{}{
"version": version,
"version": version,
"has_been_executed": true,
},
}
}
Expand All @@ -58,18 +65,18 @@ func CreateUpdateEvent(cmdInfo CommandInfo) Event {

func CreateDiagnosticEvent(err error) Event {
return Event{
Object: "cli-diagnostic", Properties: errorToProperties(err),
Object: "cli-diagnostic", Action: "diagnostic", Properties: errorToProperties(err),
}
}

func CreateFollowEvent(err error) Event {
return Event{
Object: "cli-follow", Properties: errorToProperties(err),
Object: "cli-follow", Action: "follow", Properties: errorToProperties(err),
}
}

func CreateOpenEvent(err error) Event {
return Event{Object: "cli-open", Properties: errorToProperties(err)}
return Event{Object: "cli-open", Action: "open", Properties: errorToProperties(err)}
}

func CreateCompletionCommand(cmdInfo CommandInfo) Event {
Expand All @@ -80,6 +87,7 @@ func CreateConfigEvent(cmdInfo CommandInfo, err error) Event {
event := createEventFromCommandInfo("config", cmdInfo)
if err != nil {
event.Properties["error"] = err.Error()
event.Properties["has_been_executed"] = true
}
return event
}
Expand All @@ -104,6 +112,7 @@ func CreateRunnerInstanceEvent(cmdInfo CommandInfo, err error) Event {
event := createEventFromCommandInfo("runner-instance", cmdInfo)
if err != nil {
event.Properties["error"] = err.Error()
event.Properties["has_been_executed"] = true
}
return event
}
Expand All @@ -120,6 +129,7 @@ func CreateInfoEvent(cmdInfo CommandInfo, err error) Event {
event := createEventFromCommandInfo("info", cmdInfo)
if err != nil {
event.Properties["error"] = err.Error()
event.Properties["has_been_executed"] = true
}
return event
}
5 changes: 3 additions & 2 deletions telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func CreateClient(user User, enabled bool) Client {
// Sends the user's approval event
func SendTelemetryApproval(user User, approval Approval) error {
client := CreateActiveTelemetry(user)
defer client.Close()

return client.Track(Event{
Object: "cli-telemetry",
Expand Down Expand Up @@ -124,11 +125,11 @@ func (segment *segmentClient) Track(event Event) error {
}

if segment.user.UniqueID != "" {
event.Properties["UUID"] = segment.user.UniqueID
event.Properties["anonymous_id"] = segment.user.UniqueID
}

if segment.user.UserID != "" {
event.Properties["user_id"] = segment.user.UserID
event.Properties["cci_user_id"] = segment.user.UserID
}

event.Properties["is_self_hosted"] = segment.user.IsSelfHosted
Expand Down

0 comments on commit c2680d8

Please sign in to comment.