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:03:51 +00:00
|
|
|
func (jtt *jsonTracerTransport) Transport(event TracerTransportEvent) error {
|
|
|
|
var e interface{}
|
|
|
|
if event.lotusTraceEvent != nil {
|
|
|
|
e = *event.lotusTraceEvent
|
|
|
|
} else if event.pubsubTraceEvent != nil {
|
|
|
|
e = *event.pubsubTraceEvent
|
|
|
|
} else {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
jsonEvent, err := json.Marshal(e)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("error while marshaling event: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = jtt.out.Write(jsonEvent)
|
2021-09-15 11:41:03 +00:00
|
|
|
return err
|
|
|
|
}
|