Beispiel #1
0
    def make_headers(cls, context: BaseTraceContext) -> Headers:
        """Creates dict with zipkin headers from supplied trace context."""

        # TODO: toggle for make single header or remove single
        headers = {
            cls.TRACE_ID_HEADER: hexify(context.trace_id),
            cls.SPAN_ID_HEADER: hexify(context.span_id),
            cls.FLAGS_HEADER: "0",
            cls.SAMPLED_ID_HEADER: "1" if context.sampled else "0",
        }
        if context.parent_id > 0:
            headers[cls.PARENT_ID_HEADER] = hexify(context.parent_id)
        return headers
async def test_batches(fake_zipkin, loop):
    endpoint = az.create_endpoint("simple_service", ipv4="127.0.0.1", port=80)

    tr = azt.ZipkinTransport(
        fake_zipkin.url,
        send_interval=0.01,
        send_max_size=2,
        send_timeout=ClientTimeout(total=1),
    )

    tracer = await az.create_custom(endpoint, tr)

    with tracer.new_trace(sampled=True) as span:
        span.name("root_span")
        span.kind(az.CLIENT)
        with span.new_child("child_1", az.CLIENT):
            pass
        with span.new_child("child_2", az.CLIENT):
            pass

    # close forced sending data to server regardless of send interval
    await tracer.close()

    data = fake_zipkin.get_received_data()
    trace_id = hexify(span.context.trace_id)
    assert len(data[0]) == 2
    assert len(data[1]) == 1
    assert data[0][0]["name"] == "child_1"
    assert data[0][1]["name"] == "child_2"
    assert data[1][0]["name"] == "root_span"
    assert any(s["traceId"] == trace_id for trace in data for s in trace), data
async def test_retry(fake_zipkin, loop):
    endpoint = az.create_endpoint("simple_service", ipv4="127.0.0.1", port=80)

    tr = azt.ZipkinTransport(
        fake_zipkin.url,
        send_interval=0.01,
        send_max_size=100,
        send_attempt_count=3,
        send_timeout=ClientTimeout(total=1),
    )
    fake_zipkin.next_errors.append("disconnect")
    fake_zipkin.next_errors.append("timeout")
    waiter = fake_zipkin.wait_data(1)
    tracer = await az.create_custom(endpoint, tr)

    with tracer.new_trace(sampled=True) as span:
        span.name("root_span")
        span.kind(az.CLIENT)

    async with timeout(10):
        await waiter
    await tracer.close()

    data = fake_zipkin.get_received_data()
    trace_id = hexify(span.context.trace_id)
    assert any(s["traceId"] == trace_id for trace in data for s in trace), data
Beispiel #4
0
    def make_single_header(cls, context: BaseTraceContext) -> Headers:
        """Creates dict with zipkin single header format."""
        # b3={TraceId}-{SpanId}-{SamplingState}-{ParentSpanId}
        c = context

        # encode sampled flag
        if c.debug:
            sampled = "d"
        elif c.sampled:
            sampled = "1"
        else:
            sampled = "0"

        params: List[str] = [hexify(c.trace_id), hexify(c.span_id), sampled]
        if c.parent_id > 0:
            params.append(hexify(c.parent_id))

        h = cls.DELIMITER.join(params)
        headers = {cls.SINGLE_HEADER: h}
        return headers
Beispiel #5
0
async def test_basic_context_manager(zipkin_url, client, loop):
    endpoint = az.create_endpoint("simple_service", ipv4="127.0.0.1", port=80)
    interval = 50
    async with az.create_zipkin(zipkin_url,
                                endpoint,
                                sample_rate=1.0,
                                send_interval=interval) as tracer:
        with tracer.new_trace(sampled=True) as span:
            span.name("root_span")
            await asyncio.sleep(0.1)

    trace_id = hexify(span.context.trace_id)
    url = URL(zipkin_url).with_path("/zipkin/api/v2/traces")
    data = await _retry_zipkin_client(url, client)

    assert any(s["traceId"] == trace_id for trace in data for s in trace), data
async def test_basic(jaeger_server, jaeger_url, jaeger_api_url, client):
    endpoint = az.create_endpoint("simple_service", ipv4="127.0.0.1", port=80)
    tracer = await az.create_jaeger(jaeger_url, endpoint)
    with tracer.new_trace(sampled=True) as span:
        span.name("jaeger_span")
        span.tag("span_type", "root")
        span.kind(az.CLIENT)
        span.annotate("SELECT * FROM")
        await asyncio.sleep(0.1)
        span.annotate("start end sql")

    # close forced sending data to server regardless of send interval
    await tracer.close()

    trace_id = hexify(span.context.trace_id)
    url = URL(jaeger_api_url) / "api" / "traces" / trace_id
    resp = await client.get(url, headers={"Content-Type": "application/json"})
    assert resp.status == 200
    data = await resp.json()
    assert data["data"][0]["traceID"] == trace_id
Beispiel #7
0
async def test_basic(zipkin_url, client, loop):
    endpoint = az.create_endpoint("simple_service", ipv4="127.0.0.1", port=80)
    interval = 50
    tracer = await az.create_zipkin(zipkin_url,
                                    endpoint,
                                    sample_rate=1.0,
                                    send_interval=interval)

    with tracer.new_trace(sampled=True) as span:
        span.name("root_span")
        span.tag("span_type", "root")
        span.kind(az.CLIENT)
        span.annotate("SELECT * FROM")
        await asyncio.sleep(0.1)
        span.annotate("start end sql")

    # close forced sending data to server regardless of send interval
    await tracer.close()

    trace_id = hexify(span.context.trace_id)
    url = URL(zipkin_url).with_path("/zipkin/api/v2/traces")
    data = await _retry_zipkin_client(url, client)
    assert any(s["traceId"] == trace_id for trace in data for s in trace), data