コード例 #1
0
    async def test():
        token = "tests.contrib.httpx.test_httpx.test_configure_global_service_name_env"
        with snapshot_context(token=token):
            httpx.get(url)

        with snapshot_context(token=token):
            async with httpx.AsyncClient() as client:
                await client.get(url)
コード例 #2
0
async def test_get_200(snapshot_context):
    url = get_url("/status/200")
    with snapshot_context():
        resp = httpx.get(url)
        assert resp.status_code == 200

    with snapshot_context():
        async with httpx.AsyncClient() as client:
            resp = await client.get(url)
            assert resp.status_code == 200
コード例 #3
0
async def test_get_500(snapshot_context):
    """
    When the status code is 500
        We mark the span as an error
    """
    url = get_url("/status/500")
    with snapshot_context():
        resp = httpx.get(url)
        assert resp.status_code == 500

    with snapshot_context():
        async with httpx.AsyncClient() as client:
            resp = await client.get(url)
            assert resp.status_code == 500
コード例 #4
0
def test_enqueue(queue, distributed_tracing_enabled, worker_service_name):
    token = "tests.contrib.rq.test_rq.test_enqueue_distributed_tracing_enabled_%s_worker_service_%s" % (
        distributed_tracing_enabled,
        worker_service_name,
    )
    with snapshot_context(token, ignores=snapshot_ignores):
        env = os.environ.copy()
        env["DD_TRACE_REDIS_ENABLED"] = "false"
        if distributed_tracing_enabled is not None:
            env["DD_RQ_DISTRIBUTED_TRACING_ENABLED"] = str(
                distributed_tracing_enabled)
        if worker_service_name is not None:
            env["DD_SERVICE"] = "custom-worker-service"
        p = subprocess.Popen(["ddtrace-run", "rq", "worker", "q"], env=env)
        try:
            job = queue.enqueue(job_add1, 1)
            # Wait for job to complete
            for _ in range(100):
                if job.result is not None:
                    break
                time.sleep(0.1)
            assert job.result == 2
        finally:
            p.terminate()
            # Wait for trace to be sent
            time.sleep(0.5)
コード例 #5
0
async def test_configure_service_name(snapshot_context):
    """
    When setting ddtrace.config.httpx.service_name directly
        We use the value from ddtrace.config.httpx.service_name
    """
    url = get_url("/status/200")

    with override_config("httpx", {"service_name": "test-httpx-service-name"}):
        with snapshot_context():
            resp = httpx.get(url)
            assert resp.status_code == 200

        with snapshot_context():
            async with httpx.AsyncClient() as client:
                resp = await client.get(url)
                assert resp.status_code == 200
コード例 #6
0
async def test_trace_query_string(snapshot_context):
    """
    When trace_query_string is enabled
        We include the query string as a tag on the span
    """
    url = get_url("/status/200?some=query&string=args")

    with override_http_config("httpx", {"trace_query_string": True}):
        with snapshot_context():
            resp = httpx.get(url)
            assert resp.status_code == 200

        with snapshot_context():
            async with httpx.AsyncClient() as client:
                resp = await client.get(url)
                assert resp.status_code == 200
コード例 #7
0
async def test_split_by_domain(snapshot_context):
    """
    When split_by_domain is configure
        We set the service name to the <host>:<port>
    """
    url = get_url("/status/200")

    with override_config("httpx", {"split_by_domain": True}):
        with snapshot_context():
            resp = httpx.get(url)
            assert resp.status_code == 200

        with snapshot_context():
            async with httpx.AsyncClient() as client:
                resp = await client.get(url)
                assert resp.status_code == 200
コード例 #8
0
async def test_request_headers(snapshot_context):
    """
    When request headers are configured for this integration
        We add the request headers as tags on the span
    """
    url = get_url("/response-headers?Some-Response-Header=Response-Value")

    headers = {
        "Some-Request-Header": "Request-Value",
    }

    try:
        config.httpx.http.trace_headers(["Some-Request-Header", "Some-Response-Header"])
        with snapshot_context():
            resp = httpx.get(url, headers=headers)
            assert resp.status_code == 200

        with snapshot_context():
            async with httpx.AsyncClient() as client:
                resp = await client.get(url, headers=headers)
                assert resp.status_code == 200
    finally:
        config.httpx.http = HttpConfig()