コード例 #1
0
ファイル: zipkin.py プロジェクト: rmoorman/pyramid_zipkin
    def tween(request):
        # Creates zipkin attributes, attaches a zipkin_trace_id attr to the
        # request, and pushes the attrs onto threadlocal stack.
        zipkin_attrs = create_zipkin_attr(request)
        push_zipkin_attrs(zipkin_attrs)

        try:
            # If this request isn't sampled, don't go through the work
            # of initializing the rest of the zipkin attributes
            if not zipkin_attrs.is_sampled:
                return handler(request)

            # If the request IS sampled, we create thrift objects and
            # enter zipkin logging context
            thrift_endpoint = create_endpoint(request)
            log_handler = ZipkinLoggerHandler(zipkin_attrs)
            with ZipkinLoggingContext(zipkin_attrs, thrift_endpoint,
                                      log_handler, request) as context:
                response = handler(request)
                context.response_status_code = response.status_code
                context.binary_annotations_dict = get_binary_annotations(
                        request, response)

                return response
        finally:
            # Regardless of what happens in the request we want to pop attrs
            pop_zipkin_attrs()
コード例 #2
0
def test_create_endpoint_creates_correct_endpoint(gethostbyname, request):
    gethostbyname.return_value = '0.0.0.0'
    request.registry.settings = {'service_name': 'foo'}
    request.server_port = 8080
    endpoint = thrift_helper.create_endpoint(request)
    assert endpoint.service_name == 'foo'
    assert endpoint.port == 8080
    # An IP address of 0.0.0.0 unpacks to just 0
    assert endpoint.ipv4 == 0
コード例 #3
0
def test_create_endpoint_creates_correct_endpoint(gethostbyname, request):
    gethostbyname.return_value = '0.0.0.0'
    request.registry.settings = {'service_name': 'foo'}
    request.server_port = 8080
    endpoint = thrift_helper.create_endpoint(request)
    assert endpoint.service_name == 'foo'
    assert endpoint.port == 8080
    # An IP address of 0.0.0.0 unpacks to just 0
    assert endpoint.ipv4 == 0
コード例 #4
0
def test_copy_endpoint_with_new_service_name(gethostbyname, request):
    gethostbyname.return_value = '0.0.0.0'
    request.registry.settings = {'service_name': 'foo'}
    request.server_port = 8080
    endpoint = thrift_helper.create_endpoint(request)
    new_endpoint = thrift_helper.copy_endpoint_with_new_service_name(
            endpoint, 'blargh')
    assert new_endpoint.port == 8080
    assert new_endpoint.service_name == 'blargh'
    # An IP address of 0.0.0.0 unpacks to just 0
    assert endpoint.ipv4 == 0
コード例 #5
0
def test_copy_endpoint_with_new_service_name(gethostbyname, request):
    gethostbyname.return_value = '0.0.0.0'
    request.registry.settings = {'service_name': 'foo'}
    request.server_port = 8080
    endpoint = thrift_helper.create_endpoint(request)
    new_endpoint = thrift_helper.copy_endpoint_with_new_service_name(
        endpoint, 'blargh')
    assert new_endpoint.port == 8080
    assert new_endpoint.service_name == 'blargh'
    # An IP address of 0.0.0.0 unpacks to just 0
    assert endpoint.ipv4 == 0
コード例 #6
0
ファイル: zipkin.py プロジェクト: mjbryant/pyramid_zipkin
    def tween(request):
        zipkin_attrs = create_zipkin_attr(request)
        endpoint_attrs = create_endpoint(request)
        log_handler = ZipkinLoggerHandler(zipkin_attrs)
        with ZipkinLoggingContext(zipkin_attrs, endpoint_attrs, log_handler,
                                  request) as context:
            response = handler(request)
            context.response_status_code = response.status_code
            context.binary_annotations_dict = get_binary_annotations(
                    request, response)

            return response
コード例 #7
0
    def tween(request):
        zipkin_attrs = create_zipkin_attr(request)
        endpoint_attrs = create_endpoint(request)
        log_handler = ZipkinLoggerHandler(zipkin_attrs)
        with ZipkinLoggingContext(zipkin_attrs, endpoint_attrs, log_handler,
                                  request) as context:
            response = handler(request)
            context.response_status_code = response.status_code
            context.binary_annotations_dict = get_binary_annotations(
                request, response)

            return response
コード例 #8
0
ファイル: zipkin.py プロジェクト: prat0318/pyramid_zipkin
    def tween(request):
        zipkin_attrs = create_zipkin_attr(request)

        # If this request isn't sampled, don't go through the work
        # of initializing the rest of the zipkin attributes
        if not zipkin_attrs.is_sampled:
            return handler(request)

        # If the request IS sampled, we create thrift objects, store
        # thread-local variables, etc, to enter zipkin logging context
        thrift_endpoint = create_endpoint(request)
        log_handler = ZipkinLoggerHandler(zipkin_attrs)
        with ZipkinLoggingContext(zipkin_attrs, thrift_endpoint, log_handler, request) as context:
            response = handler(request)
            context.response_status_code = response.status_code
            context.binary_annotations_dict = get_binary_annotations(request, response)

            return response
コード例 #9
0
ファイル: zipkin.py プロジェクト: sunmoonone/pyramid_zipkin
    def tween(request):
        zipkin_attrs = create_zipkin_attr(request)

        # If this request isn't sampled, don't go through the work
        # of initializing the rest of the zipkin attributes
        if not zipkin_attrs.is_sampled:
            return handler(request)

        # If the request IS sampled, we create thrift objects, store
        # thread-local variables, etc, to enter zipkin logging context
        thrift_endpoint = create_endpoint(request)
        log_handler = ZipkinLoggerHandler(zipkin_attrs)
        with ZipkinLoggingContext(zipkin_attrs, thrift_endpoint, log_handler,
                                  request) as context:
            response = handler(request)
            context.response_status_code = response.status_code
            context.binary_annotations_dict = get_binary_annotations(
                    request, response)

            return response
コード例 #10
0
def test_create_endpoint_creates_correct_endpoint(request):
    request.registry.settings = {"service_name": "foo"}
    request.server_port = 8080
    endpoint = thrift_helper.create_endpoint(request)
    assert endpoint.service_name == "foo"
    assert endpoint.port == 8080
コード例 #11
0
def test_create_endpoint_creates_correct_endpoint(request):
    request.registry.settings = {'service_name': 'foo'}
    request.server_port = 8080
    endpoint = thrift_helper.create_endpoint(request)
    assert endpoint.service_name == 'foo'
    assert endpoint.port == 8080