-
Notifications
You must be signed in to change notification settings - Fork 37
/
cmd_step.go
52 lines (43 loc) · 1.55 KB
/
cmd_step.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"strings"
"time"
"github.com/spf13/cobra"
libhoney "github.com/honeycombio/libhoney-go"
)
func commandStep(cfg *libhoney.Config, filename *string, ciProvider *string) *cobra.Command {
// STEP - eg: buildevents step $TRAVIS_BUILD_ID $STAGE_SPAN_ID $STAGE_START script
stepCmd := &cobra.Command{
Use: "step [flags] BUILD_ID STEP_ID START_TIME NAME",
Short: "Joins a collection of individual commands",
Long: `
The step mode represents a block of related commands. In Travis-CI, this is
one of "install", "before_script", "script", and so on. In CircleCI, this
most closely maps to a single job. It should be run at the end of the step.`,
Args: cobra.ExactArgs(4),
DisableFlagsInUseLine: true,
RunE: func(cmd *cobra.Command, args []string) error {
traceID := strings.TrimSpace(args[0])
stepID := strings.TrimSpace(args[1])
startTime := parseUnix(strings.TrimSpace(args[2]))
name := strings.TrimSpace(args[3])
ev := createEvent(cfg, *ciProvider, traceID)
defer ev.Send()
providerInfo(*ciProvider, ev)
ev.Add(map[string]interface{}{
"trace.parent_id": traceID,
"trace.span_id": stepID,
"service_name": ifClassic(cfg.APIKey, "step", cfg.Dataset),
"service.name": ifClassic(cfg.APIKey, "step", cfg.Dataset),
"command_name": "step",
"name": name,
"duration_ms": time.Since(startTime) / time.Millisecond,
"source": "buildevents",
})
ev.Timestamp = startTime
arbitraryFields(*filename, ev)
return nil
},
}
return stepCmd
}