예제 #1
0
def inject_tracing_headers(tracer: Tracer, span: Span, api_instance: ApiInstance):
    http_header_carrier = {}
    tracer.inject(
        span_context=span.context,
        format=Format.HTTP_HEADERS,
        carrier=http_header_carrier)

    for key, value in http_header_carrier.items():
        api_instance.headers[key] = value
예제 #2
0
def test_inject():
    tracer = Tracer()
    span = tracer.start_span()

    bin_carrier = bytearray()
    tracer.inject(span_context=span.context,
                  format=Format.BINARY,
                  carrier=bin_carrier)
    assert bin_carrier == bytearray()

    text_carrier = {}
    tracer.inject(span_context=span.context,
                  format=Format.TEXT_MAP,
                  carrier=text_carrier)
    assert text_carrier == {}
def test_inject():
    tracer = Tracer()
    span = tracer.start_span()

    bin_carrier = bytearray()
    tracer.inject(
        span_context=span.context,
        format=Format.BINARY,
        carrier=bin_carrier)
    assert bin_carrier == bytearray()

    text_carrier = {}
    tracer.inject(
        span_context=span.context,
        format=Format.TEXT_MAP,
        carrier=text_carrier)
    assert text_carrier == {}
def test_new_trace():
    tracer = Tracer()

    span = tracer.start_span(operation_name='test')
    span.set_baggage_item('Fry', 'Leela')
    span.set_tag('x', 'y')
    span.log_event('z')

    child = tracer.start_span(operation_name='child', parent=span)
    child.log_event('w')
    assert child.get_baggage_item('Fry') is None
    carrier = {}
    tracer.inject(span=child, format=Format.TEXT_MAP, carrier=carrier)
    assert carrier == dict()
    child.finish()

    span.finish()
예제 #5
0
def outgoing_trace(operation: str, request: Request, tracer: Tracer,
                   parent: Span) \
                       -> Generator[Tuple[Span, Dict[str, Any]], None, None]:
    with tracer.start_span(operation, child_of=parent) as span:
        span.set_tag('http.url', request.url)

        remote_ip = request.client.host
        if remote_ip:
            span.set_tag(tags.PEER_HOST_IPV4, remote_ip)

        remote_port = request.client.port
        if remote_port:
            span.set_tag(tags.PEER_PORT, remote_port)

        http_header_carrier = {}
        tracer.inject(span_context=span,
                      format=Format.HTTP_HEADERS,
                      carrier=http_header_carrier)

        yield span, http_header_carrier
예제 #6
0
def test_new_trace():
    tracer = Tracer()

    span = tracer.start_span(operation_name='test')
    span.set_baggage_item('Fry', 'Leela')
    span.set_tag('x', 'y')
    span.log_event('z')

    child = tracer.start_span(operation_name='child',
                              references=opentracing.child_of(span.context))
    child.log_event('w')
    assert child.get_baggage_item('Fry') is None
    carrier = {}
    tracer.inject(span_context=child.context,
                  format=Format.TEXT_MAP,
                  carrier=carrier)
    assert carrier == dict()
    child.finish()

    span.finish()