Skip to content

Commit

Permalink
fix: add telemetry cli context (#5226) (#5229)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicufk authored Mar 21, 2024
1 parent 86ad572 commit 9efb491
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/telemetry/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Params struct {
TestSuiteSteps int32 `json:"test_suite_steps,omitempty"`
Context RunContext `json:"context,omitempty"`
ClusterType string `json:"cluster_type,omitempty"`
CliContext string `json:"cli_context,omitempty"`
Error string `json:"error,omitempty"`
ErrorType string `json:"error_type,omitempty"`
ErrorStackTrace string `json:"error_stacktrace,omitempty"`
Expand Down Expand Up @@ -113,6 +114,7 @@ func NewCLIPayload(context RunContext, id, name, version, category, clusterType
Architecture: runtime.GOARCH,
Context: context,
ClusterType: clusterType,
CliContext: GetCliRunContext(),
},
}},
}
Expand Down
63 changes: 63 additions & 0 deletions pkg/telemetry/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package telemetry
import (
"context"
"net/http"
"os"
"runtime"
"sync"

Expand Down Expand Up @@ -231,3 +232,65 @@ func GetClusterType() string {

return "others"
}

func GetCliRunContext() string {
if value, ok := os.LookupEnv("GITHUB_ACTIONS"); ok {
if value == "true" {
return "github-actions"
}
}

if _, ok := os.LookupEnv("TF_BUILD"); ok {
return "azure-pipelines"
}

if _, ok := os.LookupEnv("JENKINS_URL"); ok {
return "jenkins"
}

if _, ok := os.LookupEnv("JENKINS_HOME"); ok {
return "jenkins"
}

if _, ok := os.LookupEnv("CIRCLECI"); ok {
return "circleci"
}

if _, ok := os.LookupEnv("GITLAB_CI"); ok {
return "gitlab-ci"
}

if _, ok := os.LookupEnv("BUILDKITE"); ok {
return "buildkite"
}

if _, ok := os.LookupEnv("TRAVIS"); ok {
return "travis-ci"
}

if _, ok := os.LookupEnv("AIRFLOW_HOME"); ok {
return "airflow"
}

if _, ok := os.LookupEnv("TEAMCITY_VERSION"); ok {
return "teamcity"
}

if _, ok := os.LookupEnv("GO_PIPELINE_NAME"); ok {
return "gocd"
}

if _, ok := os.LookupEnv("SEMAPHORE"); ok {
return "semaphore-ci"
}

if _, ok := os.LookupEnv("BITBUCKET_BUILD_NUMBER"); ok {
return "bitbucket-pipelines"
}

if _, ok := os.LookupEnv("DRONE"); ok {
return "drone"
}

return "others|local"
}

0 comments on commit 9efb491

Please sign in to comment.