2021-09-15 11:41:03 +00:00
|
|
|
package tracer
|
|
|
|
|
|
|
|
import (
|
2021-09-15 14:03:51 +00:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2021-09-15 11:41:03 +00:00
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
type jsonTracerTransport struct {
|
|
|
|
out *os.File
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewJsonTracerTransport(out *os.File) TracerTransport {
|
|
|
|
return &jsonTracerTransport{
|
|
|
|
out: out,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-15 14:16:12 +00:00
|
|
|
func (jtt *jsonTracerTransport) Transport(evt TracerTransportEvent) error {
|
2021-09-15 14:03:51 +00:00
|
|
|
var e interface{}
|
2021-09-15 14:16:12 +00:00
|
|
|
if evt.lotusTraceEvent != nil {
|
|
|
|
e = *evt.lotusTraceEvent
|
|
|
|
} else if evt.pubsubTraceEvent != nil {
|
|
|
|
e = *evt.pubsubTraceEvent
|
2021-09-15 14:03:51 +00:00
|
|
|
} else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-09-15 14:16:12 +00:00
|
|
|
jsonEvt, err := json.Marshal(e)
|
2021-09-15 14:03:51 +00:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("error while marshaling event: %s", err)
|
|
|
|
}
|
|
|
|
|
2021-09-15 14:16:12 +00:00
|
|
|
_, err = jtt.out.Write(jsonEvt)
|
2021-09-15 11:41:03 +00:00
|
|
|
return err
|
|
|
|
}
|