def make_endpoint(ipv4, port, service_name): if isinstance(ipv4, basestring): ipv4 = ipv4_to_int(ipv4) port = port_to_int(port) if port is None: port = 0 return zipkin_collector.Endpoint(ipv4, port, service_name.lower())
def make_zipkin_spans(spans): zipkin_spans = [] for span in spans: endpoint = make_endpoint( ipv4=span.tracer.ip_address, port=0, # span.port, service_name=span.tracer.service_name) # TODO extend Zipkin Thrift and pass endpoint once only for event in span.logs: event.host = endpoint with span.update_lock: add_zipkin_annotations(span=span, endpoint=endpoint) parent_id = None if span.parent_id is not None: parent_id = id_to_int(span.parent_id) zipkin_span = zipkin_collector.Span( trace_id=id_to_int(span.trace_id), name=span.operation_name, id=id_to_int(span.span_id), parent_id=parent_id, annotations=span.logs, binary_annotations=span.tags, debug=span.is_debug(), timestamp=timestamp_micros(span.start_time), duration=timestamp_micros(span.end_time - span.start_time)) zipkin_spans.append(zipkin_span) return zipkin_spans
def make_peer_address_tag(key, host): """ Used for Zipkin binary annotations like CA/SA (client/server address). They are modeled as Boolean type with '0x01' as the value. :param key: :param host: """ return zipkin_collector.BinaryAnnotation( key, '0x01', zipkin_collector.AnnotationType.BOOL, host)
def test_make_endpoint(): endpoint1 = thrift.make_endpoint(ipv4='localhost', port='', service_name='XYZ') target = zipkin_collector.Endpoint( ipv4=127 << 24 | 1, port=0, service_name='xyz') assert endpoint1 == target endpoint2 = thrift.make_endpoint(ipv4='127.0.0.1', port='', service_name='XYZ') assert endpoint2 == target
def make_local_component_tag(component_name, endpoint): """ Used for Zipkin binary annotation LOCAL_COMPONENT. :param component_name: :param endpoint: """ return zipkin_collector.BinaryAnnotation( key=LOCAL_COMPONENT, value=component_name, annotation_type=zipkin_collector.AnnotationType.STRING, host=endpoint)
def make_string_tag(key, value): if len(value) > 256: value = value[:256] return zipkin_collector.BinaryAnnotation( key, value, zipkin_collector.AnnotationType.STRING)
def make_event(timestamp, name): return zipkin_collector.Annotation(timestamp=timestamp_micros(timestamp), value=name, host=None)