def test_should_not_sample_route_returns_false_if_route_is_not_blacklisted(
        request):
    request.registry.settings = {'zipkin.blacklisted_routes': ['bar']}
    route = mock.Mock()
    route.name = 'foo'
    request.registry.queryUtility = lambda _: lambda req: {'route': route}
    assert not request_helper.should_not_sample_route(request)
Exemple #2
0
def test_should_not_sample_route_returns_false_if_route_is_not_blacklisted(
        request):
    request.registry.settings = {'zipkin.blacklisted_routes': ['bar']}
    route = mock.Mock()
    route.name = 'foo'
    request.registry.queryUtility = lambda _: lambda req: {'route': route}
    assert not request_helper.should_not_sample_route(request)
def test_should_not_sample_route_returns_true_if_route_is_blacklisted(
    dummy_request
):
    dummy_request.registry.settings = {'zipkin.blacklisted_routes': ['foo.bar']}
    route = mock.Mock()
    route.name = 'foo.bar'
    dummy_request.registry.queryUtility = lambda _: lambda req: {'route': route}
    assert request_helper.should_not_sample_route(dummy_request)
Exemple #4
0
def test_should_not_sample_route_returns_true_if_route_is_blacklisted(
    dummy_request
):
    dummy_request.registry.settings = {'zipkin.blacklisted_routes': ['foo.bar']}
    route = mock.Mock()
    route.name = 'foo.bar'
    dummy_request.registry.queryUtility = lambda _: lambda req: {'route': route}
    assert request_helper.should_not_sample_route(dummy_request)
Exemple #5
0
    def tween(request):
        zipkin_settings = _get_settings_from_request(request)
        tracer = get_default_tracer()

        tween_kwargs = dict(
            service_name=zipkin_settings.service_name,
            span_name=zipkin_settings.span_name,
            zipkin_attrs=zipkin_settings.zipkin_attrs,
            transport_handler=zipkin_settings.transport_handler,
            host=zipkin_settings.host,
            port=zipkin_settings.port,
            add_logging_annotation=zipkin_settings.add_logging_annotation,
            report_root_timestamp=zipkin_settings.report_root_timestamp,
            context_stack=zipkin_settings.context_stack,
            max_span_batch_size=zipkin_settings.max_span_batch_size,
            encoding=zipkin_settings.encoding,
            kind=Kind.SERVER,
        )

        # Only set the firehose_handler if it's defined and only if the current
        # request is not blacklisted. This prevents py_zipkin from emitting
        # firehose spans for blacklisted paths like /status
        if zipkin_settings.firehose_handler is not None and \
                not should_not_sample_path(request) and \
                not should_not_sample_route(request):
            tween_kwargs['firehose_handler'] = zipkin_settings.firehose_handler

        with tracer.zipkin_span(**tween_kwargs) as zipkin_context:
            response = handler(request)
            if zipkin_settings.use_pattern_as_span_name and request.matched_route:
                zipkin_context.override_span_name('{} {}'.format(
                    request.method,
                    request.matched_route.pattern,
                ))
            zipkin_context.update_binary_annotations(
                get_binary_annotations(request, response),
            )

            if zipkin_settings.post_handler_hook:
                zipkin_settings.post_handler_hook(
                    request,
                    response,
                    zipkin_context
                )

            return response
def test_should_not_sample_route_returns_false_if_blacklisted_list_is_empty(
        request):
    assert not request_helper.should_not_sample_route(request)
Exemple #7
0
def test_should_not_sample_route_returns_false_if_blacklisted_list_is_empty(
        dummy_request):
    assert not request_helper.should_not_sample_route(dummy_request)