|
| 1 | +from spanid import SpanID, Annotation |
| 2 | + |
| 3 | +class AppdashRecorder(object): |
| 4 | + def __init__(self, collector): |
| 5 | + self._collector = collector |
| 6 | + |
| 7 | + def record_span(self, span): |
| 8 | + if not span.context.sampled: |
| 9 | + return |
| 10 | + annotations = [] |
| 11 | + span_id = SpanID() |
| 12 | + span_id.trace = span.context.trace_id |
| 13 | + span_id.span = span.context.span |
| 14 | + span_id.parent = span.context.parent_span_id |
| 15 | + |
| 16 | + # It might not be right to build a list, maybe send events one at a time. |
| 17 | + annotations.append(MarshalEvent(SpanNameEvent(span.operation_name))) |
| 18 | + |
| 19 | + approx_endtime = span.context.start_time + span.duration |
| 20 | + annotations.append(MarshalEvent( |
| 21 | + TimespanEvent(span.context.start_time, approx_endtime))) |
| 22 | + |
| 23 | + for key in span.tags: |
| 24 | + annotations.append(Annotation(key, span.tag[key]) |
| 25 | + |
| 26 | + for key in span.context.baggage_items: |
| 27 | + annotations.append(Annotation(key, span.contex.baggage_items[value]) |
| 28 | + |
| 29 | + self._collector.collect(span_id, events) |
| 30 | + |
| 31 | + |
| 32 | +class AppdashTracer(BasicTracer): |
| 33 | + |
| 34 | + def __init__(self, collector, sampler=None): |
| 35 | + self._recorder = AppdashRecorder(collector) |
| 36 | + super(AppdashTracer, self).__init__(recorder=self._recorder, |
| 37 | + sampler=sampler) |
0 commit comments