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
|
package dapperish
import (
"fmt"
"github.com/opentracing/basictracer-go"
)
// TrivialRecorder implements the basictracer.SpanRecorder interface.
type TrivialRecorder struct {
processName string
tags map[string]string
}
// NewTrivialRecorder returns a TrivialRecorder for the given `processName`.
func NewTrivialRecorder(processName string) *TrivialRecorder {
return &TrivialRecorder{
processName: processName,
tags: make(map[string]string),
}
}
// ProcessName returns the process name.
func (t *TrivialRecorder) ProcessName() string { return t.processName }
// SetTag sets a tag.
func (t *TrivialRecorder) SetTag(key string, val interface{}) *TrivialRecorder {
t.tags[key] = fmt.Sprint(val)
return t
}
// RecordSpan complies with the basictracer.Recorder interface.
func (t *TrivialRecorder) RecordSpan(span basictracer.RawSpan) {
fmt.Printf(
"RecordSpan: %v[%v, %v us] --> %v logs. context: %v; baggage: %v\n",
span.Operation, span.Start, span.Duration, len(span.Logs),
span.Context, span.Context.Baggage)
for i, l := range span.Logs {
fmt.Printf(
" log %v @ %v: %v\n", i, l.Timestamp, l.Fields)
}
}
|