forked from SpirentOrion/luddite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trace.go
49 lines (41 loc) · 998 Bytes
/
trace.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
package luddite
import (
"fmt"
"io"
"gopkg.in/SpirentOrion/trace.v2"
"gopkg.in/yaml.v2"
)
const (
TraceKindAWS = "aws"
TraceKindProcess = "process"
TraceKindRequest = "request"
TraceKindWorker = "worker"
)
var recorders = make(map[string]trace.Recorder)
func RegisterTraceRecorder(name string, recorder trace.Recorder) {
if name == "" {
panic("empty trace recorder name")
}
if recorder == nil {
panic("nil trace recorder")
}
if _, ok := recorders[name]; ok {
panic(fmt.Sprintf("%s trace recorder registered twice", name))
}
recorders[name] = recorder
}
// yamlRecorder is included in luddite for backwards compatibility with v1 of
// github.com/SpirentOrion/trace since v2 of that package no longer supports
// YAML directly.
type yamlRecorder struct {
io.Writer
}
func (r *yamlRecorder) Record(s *trace.Span) error {
buf, err := yaml.Marshal(s)
if err != nil {
return err
}
fmt.Fprintln(r, "---") // document separator
_, err = r.Write(buf)
return err
}