@@ -4,7 +4,6 @@ package root
44
55import (
66 "context"
7- "encoding/json"
87 "errors"
98 "fmt"
109 "io"
@@ -14,7 +13,6 @@ import (
1413 "os/exec"
1514 "path/filepath"
1615 "strings"
17- "time"
1816
1917 "github.com/AlecAivazis/survey/v2/terminal"
2018 "github.com/MakeNowJust/heredoc"
@@ -119,56 +117,6 @@ func NewRootCmd(f *cmdutil.Factory) *cobra.Command {
119117 return cmd
120118}
121119
122- // runSummary is the JSON object written to stderr when observability env vars are set.
123- type runSummary struct {
124- Event string `json:"event"`
125- InvocationID string `json:"invocation_id"`
126- Command string `json:"command"`
127- Status string `json:"status"`
128- DurationMs int64 `json:"duration_ms"`
129- Error string `json:"error,omitempty"`
130- }
131-
132- func shouldEmitRunSummary () bool {
133- return os .Getenv ("ALGOLIA_CLI_NON_INTERACTIVE" ) == "1" ||
134- os .Getenv ("ALGOLIA_CLI_OBSERVABILITY" ) == "1"
135- }
136-
137- func emitRunSummary (stderr io.Writer , ctx context.Context , cmd * cobra.Command , runErr error , duration time.Duration ) {
138- meta := telemetry .GetEventMetadata (ctx )
139- invocationID := ""
140- if meta != nil {
141- invocationID = meta .InvocationID
142- }
143- commandPath := ""
144- if meta != nil && meta .CommandPath != "" {
145- commandPath = meta .CommandPath
146- }
147- if commandPath == "" && cmd != nil {
148- commandPath = cmd .CommandPath ()
149- }
150- status := "ok"
151- errMsg := ""
152- if runErr != nil {
153- status = "error"
154- errMsg = runErr .Error ()
155- if len (errMsg ) > 500 {
156- errMsg = errMsg [:497 ] + "..."
157- }
158- }
159- s := runSummary {
160- Event : "cli_run" ,
161- InvocationID : invocationID ,
162- Command : commandPath ,
163- Status : status ,
164- DurationMs : duration .Milliseconds (),
165- Error : errMsg ,
166- }
167- enc := json .NewEncoder (stderr )
168- enc .SetEscapeHTML (false )
169- _ = enc .Encode (s )
170- }
171-
172120func Execute () exitCode {
173121 hasDebug := os .Getenv ("DEBUG" ) != ""
174122 hasTelemetry := os .Getenv ("ALGOLIA_CLI_TELEMETRY" ) != "0"
@@ -254,14 +202,7 @@ func Execute() exitCode {
254202 }
255203
256204 // Run the command.
257- start := time .Now ()
258205 cmd , err := rootCmd .ExecuteContextC (ctx )
259- duration := time .Since (start )
260-
261- if shouldEmitRunSummary () {
262- emitRunSummary (stderr , ctx , cmd , err , duration )
263- }
264-
265206 // Handle eventual errors.
266207 if err != nil {
267208 if err == cmdutil .ErrSilent {
0 commit comments