def test_get_span_and_trace_no_xcloud_header():
    header = cloud_trace_header()
    del header["X-Cloud-Trace-Context"]  # pylint: disable=no-member
    span, trace = get_span_and_trace(header)  # pylint: disable=no-member

    assert trace is None
    assert span is None
Exemplo n.º 2
0
    def before_request():  # pylint: disable=unused-variable
        request_id = str(uuid4())
        logger.new(request_id=request_id)

        span, trace = get_span_and_trace(flask_request.headers)
        if span and trace:
            logger.bind(span=span, trace=trace)

        logger.info(
            "request",
            method=flask_request.method,
            url_path=flask_request.full_path,
            session_cookie_present="session" in flask_request.cookies,
            csrf_token_present="csrf_token" in cookie_session,
            user_agent=flask_request.user_agent.string,
        )
def test_get_span_and_trace():
    header = cloud_trace_header()
    span, trace = get_span_and_trace(header)  # pylint: disable=no-member
    assert trace == "0123456789"
    assert span == "0123456789012345678901"
def test_get_span_and_trace_malformed_xcloud_header():  # pylint: disable=no-member
    header = cloud_trace_header()
    header["X-Cloud-Trace-Context"] = "not a real trace context"
    span, trace = get_span_and_trace(header)  # pylint: disable=no-member
    assert trace is None
    assert span is None