Пример #1
0
def test_create_http_headers_new_span_id(gen_mock):
    tracer = MockTracer()
    tracer.push_zipkin_attrs(
        ZipkinAttrs(
            trace_id="17133d482ba4f605",
            span_id="37133d482ba4f605",
            is_sampled=True,
            parent_span_id="27133d482ba4f605",
            flags=None,
        ))
    gen_mock.return_value = "47133d482ba4f605"

    # if new_span_id = True we generate a new span id
    assert request_helpers.create_http_headers(tracer=tracer,
                                               new_span_id=True) == {
                                                   "X-B3-TraceId":
                                                   "17133d482ba4f605",
                                                   "X-B3-SpanId":
                                                   "47133d482ba4f605",
                                                   "X-B3-ParentSpanId":
                                                   "37133d482ba4f605",
                                                   "X-B3-Flags": "0",
                                                   "X-B3-Sampled": "1",
                                               }

    # by default we keep the same span id as the current span
    assert request_helpers.create_http_headers(tracer=tracer) == {
        "X-B3-TraceId": "17133d482ba4f605",
        "X-B3-SpanId": "37133d482ba4f605",
        "X-B3-ParentSpanId": "27133d482ba4f605",
        "X-B3-Flags": "0",
        "X-B3-Sampled": "1",
    }
Пример #2
0
def test_create_headers_for_new_span_custom_tracer(gen_mock):
    tracer = MockTracer()
    tracer.push_zipkin_attrs(
        mock.Mock(
            trace_id='27133d482ba4f605',
            span_id='37133d482ba4f605',
            is_sampled=True,
        ))
    gen_mock.return_value = '17133d482ba4f605'
    expected = {
        'X-B3-TraceId': '27133d482ba4f605',
        'X-B3-SpanId': '17133d482ba4f605',
        'X-B3-ParentSpanId': '37133d482ba4f605',
        'X-B3-Flags': '0',
        'X-B3-Sampled': '1',
    }
    assert expected == zipkin.create_http_headers_for_new_span(tracer=tracer, )
Пример #3
0
def test_create_http_headers_custom_tracer():
    tracer = MockTracer()
    tracer.push_zipkin_attrs(
        ZipkinAttrs(
            trace_id="17133d482ba4f605",
            span_id="37133d482ba4f605",
            is_sampled=True,
            parent_span_id="27133d482ba4f605",
            flags=None,
        ))
    expected = {
        "X-B3-TraceId": "17133d482ba4f605",
        "X-B3-SpanId": "37133d482ba4f605",
        "X-B3-ParentSpanId": "27133d482ba4f605",
        "X-B3-Flags": "0",
        "X-B3-Sampled": "1",
    }
    assert expected == request_helpers.create_http_headers(tracer=tracer)