func protoToAnnotationType(p traceproto.AnnotationType) AnnotationType {
	at := int32(p)
	if at > 6 || at < 1 {
		at = 0
	}
	return AnnotationType(at)
}
protoToAnnotationType converts a annotation type in our proto to our domain
package phosphor
import (
	"sort"
	"time"
	"github.com/mondough/phosphor/proto"
)
func prettyFormatTrace(t *Trace) interface{} {
	return map[string]interface{}{
		"annotations": formatAnnotations(t.Annotation),
	}
}
func formatAnnotations(ans []*Annotation) interface{} {
	sort.Sort(ByTime(ans))
	pa := AnnotationsToProto(ans)
	m := make([]interface{}, 0, len(pa))
	for _, a := range pa {
		m = append(m, formatAnnotation(a))
	}
	return m
}
func formatAnnotation(a *traceproto.Annotation) interface{} {
	return map[string]interface{}{
		"trace_id":    a.TraceId,
		"span_id":     a.SpanId,
		"parent_id":   a.ParentId,
		"type":        a.Type.String(),
		"async":       a.Async,
		"timestamp":   a.Timestamp,
		"duration":    a.Duration,
		"hostname":    a.Hostname,
		"origin":      a.Origin,
		"destination": a.Destination,
		"payload":     a.Payload,
		"key_value":   a.KeyValue,
	}
}
type ByTime []*Annotation
func (s ByTime) Len() int {
	return len(s)
}
func (s ByTime) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}
func (s ByTime) Less(i, j int) bool {
	return s[i].Timestamp.Before(s[j].Timestamp)
}
func ProtoToAnnotation(p *traceproto.Annotation) *Annotation {
	if p == nil {
		return &Annotation{}
	}
	return &Annotation{
		TraceId:        p.TraceId,
		SpanId:         p.SpanId,
		ParentSpanId:   p.ParentId,
		Timestamp:      microsecondInt64ToTime(p.Timestamp),
		Duration:       microsecondInt64ToDuration(p.Duration),
		Hostname:       p.Hostname,
		Origin:         p.Origin,
		Destination:    p.Destination,
		AnnotationType: protoToAnnotationType(p.Type),
		Async:          p.Async,
		Payload:        p.Payload,
		PayloadSize:    int32(len(p.Payload)),
		KeyValue:       protoToKeyValue(p.KeyValue),
	}
}