Esempio n. 1
0
def test_noop_span_methods(tracer):
    context = TraceContext(trace_id='6f9a20b5092fa5e144fd15cc31141cd4',
                           parent_id=None,
                           span_id='41baf1be2fb9bfc5',
                           sampled=False,
                           debug=False,
                           shared=True)

    with tracer.new_child(context) as span:
        span.name('root_span')
        span.tag('span_type', 'root')
        span.kind('CLIENT')
        span.annotate('start:sql', ts=1506970524)
        span.annotate('end:sql', ts=1506970524)
        span.remote_endpoint('service_a', ipv4='127.0.0.1', port=8080)

        with span.new_child() as child_span:
            pass

    assert isinstance(span, NoopSpan)
    assert span.context.parent_id is not None
    assert not span.context.sampled
    assert span.is_noop

    span = tracer.to_span(context)
    assert isinstance(span, NoopSpan)
    assert span.tracer is tracer

    assert isinstance(child_span, NoopSpan)
Esempio n. 2
0
def test_noop_span_methods(tracer: Tracer) -> Any:
    context = TraceContext(
        trace_id="6f9a20b5092fa5e144fd15cc31141cd4",
        parent_id=None,
        span_id="41baf1be2fb9bfc5",
        sampled=False,
        debug=False,
        shared=True,
    )

    with tracer.new_child(context) as span:
        span.name("root_span")
        span.tag("span_type", "root")
        span.kind("CLIENT")
        span.annotate("start:sql", ts=1506970524)
        span.annotate("end:sql", ts=1506970524)
        span.remote_endpoint("service_a", ipv4="127.0.0.1", port=8080)

        with span.new_child() as child_span:
            pass

    assert isinstance(span, NoopSpan)
    assert span.context.parent_id is not None
    assert not span.context.sampled
    assert span.is_noop

    span = tracer.to_span(context)
    assert isinstance(span, NoopSpan)
    assert span.tracer is tracer

    assert isinstance(child_span, NoopSpan)
Esempio n. 3
0
def context():
    context = TraceContext(trace_id='6f9a20b5092fa5e144fd15cc31141cd4',
                           parent_id=None,
                           span_id='41baf1be2fb9bfc5',
                           sampled=True,
                           debug=False,
                           shared=True)
    return context
Esempio n. 4
0
def other_trace_context():
    context = TraceContext(trace_id='6f9a20b5092fa5e144fd15cc31141cd4',
                           parent_id='05e3ac9a4f6e3b90',
                           span_id='41baf1be2fb9bfc5',
                           sampled=None,
                           debug=False,
                           shared=False)
    return context
Esempio n. 5
0
def context() -> TraceContext:
    context = TraceContext(
        trace_id="6f9a20b5092fa5e144fd15cc31141cd4",
        parent_id=None,
        span_id="41baf1be2fb9bfc5",
        sampled=True,
        debug=False,
        shared=True,
    )
    return context
Esempio n. 6
0
def test_make_headers(trace_context: TraceContext) -> None:
    headers = make_headers(trace_context)
    expected = {
        "X-B3-Flags": "0",
        "X-B3-Sampled": "1",
        "X-B3-SpanId": "41baf1be2fb9bfc5",
        "X-B3-TraceId": "6f9a20b5092fa5e144fd15cc31141cd4",
    }
    headers2 = trace_context.make_headers()
    assert headers == expected == headers2
Esempio n. 7
0
def other_trace_context() -> TraceContext:
    context = TraceContext(
        trace_id="6f9a20b5092fa5e144fd15cc31141cd4",
        parent_id="05e3ac9a4f6e3b90",
        span_id="41baf1be2fb9bfc5",
        sampled=True,
        debug=True,
        shared=False,
    )
    return context
Esempio n. 8
0
def test_make_single_header(trace_context: TraceContext,
                            other_trace_context: TraceContext) -> None:
    headers = make_single_header(trace_context)
    expected = {"b3": "6f9a20b5092fa5e144fd15cc31141cd4-41baf1be2fb9bfc5-1"}
    headers2 = trace_context.make_single_header()
    assert headers == expected == headers2

    headers = make_single_header(other_trace_context)
    h = "6f9a20b5092fa5e144fd15cc31141cd4-41baf1be2fb9bfc5-d-05e3ac9a4f6e3b90"
    headers2 = other_trace_context.make_single_header()
    expected = {"b3": h}
    assert headers == expected == headers2

    new_context = trace_context._replace(debug=True, sampled=None)
    headers = make_single_header(new_context)
    expected = {"b3": "6f9a20b5092fa5e144fd15cc31141cd4-41baf1be2fb9bfc5-d"}
    assert headers == expected

    new_context = trace_context._replace(debug=False, sampled=None)
    headers = make_single_header(new_context)
    expected = {"b3": "6f9a20b5092fa5e144fd15cc31141cd4-41baf1be2fb9bfc5-0"}
    assert headers == expected
Esempio n. 9
0
def test_basic_ctr():
    context = TraceContext('string', 'string', 'string', True, True, True)
    local_endpoint = Endpoint('string', 'string', 'string', 0)
    remote_endpoint = Endpoint('string', 'string', 'string', 0)
    record = (Record(context, local_endpoint).start(0).name('string').set_tag(
        'additionalProp1',
        'string').set_tag('additionalProp2', 'string').set_tag(
            'additionalProp3', 'string').kind('CLIENT').annotate(
                'string', 0).remote_endpoint(remote_endpoint).finish(0))
    dict_record = record.asdict()
    expected = {
        'traceId': 'string',
        'name': 'string',
        'parentId': 'string',
        'id': 'string',
        'kind': 'CLIENT',
        'timestamp': 0,
        'duration': 1,
        'debug': True,
        'shared': True,
        'localEndpoint': {
            'serviceName': 'string',
            'ipv4': 'string',
            'ipv6': 'string',
            'port': 0
        },
        'remoteEndpoint': {
            'serviceName': 'string',
            'ipv4': 'string',
            'ipv6': 'string',
            'port': 0
        },
        'annotations': [{
            'timestamp': 0,
            'value': 'string'
        }],
        'tags': {
            'additionalProp1': 'string',
            'additionalProp2': 'string',
            'additionalProp3': 'string'
        }
    }
    assert dict_record == expected
Esempio n. 10
0
def test_basic_ctr() -> None:
    context = TraceContext("string", "string", "string", True, True, True)
    local_endpoint = Endpoint("string", "string", "string", 0)
    remote_endpoint = Endpoint("string", "string", "string", 0)
    record = (Record(context, local_endpoint).start(0).name("string").set_tag(
        "additionalProp1",
        "string").set_tag("additionalProp2", "string").set_tag(
            "additionalProp3", "string").kind("CLIENT").annotate(
                "string", 0).remote_endpoint(remote_endpoint).finish(0))
    dict_record = record.asdict()
    expected = {
        "traceId": "string",
        "name": "string",
        "parentId": "string",
        "id": "string",
        "kind": "CLIENT",
        "timestamp": 0,
        "duration": 1,
        "debug": True,
        "shared": True,
        "localEndpoint": {
            "serviceName": "string",
            "ipv4": "string",
            "ipv6": "string",
            "port": 0,
        },
        "remoteEndpoint": {
            "serviceName": "string",
            "ipv4": "string",
            "ipv6": "string",
            "port": 0,
        },
        "annotations": [{
            "timestamp": 0,
            "value": "string"
        }],
        "tags": {
            "additionalProp1": "string",
            "additionalProp2": "string",
            "additionalProp3": "string",
        },
    }
    assert dict_record == expected
Esempio n. 11
0
    def make_context(self, headers: dict) -> dict:
        has_uber = self.TRACE_ID_HEADER in headers

        if has_uber:
            trace_id, span_id, parent_id, debug, sampled = self._parse_uber_headers(
                headers)
            tc = TraceContext(
                trace_id=trace_id,
                parent_id=parent_id,
                span_id=span_id,
                sampled=sampled,
                debug=debug,
                shared=False,
            )
            return tc
        else:
            # create context from B3 headers - used as a shortcut
            # for make_headers. It is NOT recommended to mix b3
            # and uber-trace-id formats together, as it is untested
            return make_context(headers)
Esempio n. 12
0
 def make_headers(self, context: TraceContext,
                  response_headers: dict) -> dict:
     return context.make_headers()