def test_should_not_sample_path_returns_true_if_path_is_blacklisted(
    dummy_request
):
    dummy_request.registry.settings = {'zipkin.blacklisted_paths': [r'^/foo/?']}
    for path in ['/foo', '/foo/1/3', '/foo/bar', '/foobar']:
        dummy_request.path = path
        assert request_helper.should_not_sample_path(dummy_request)
Example #2
0
def test_should_not_sample_path_returns_true_if_path_is_blacklisted(
    dummy_request
):
    dummy_request.registry.settings = {'zipkin.blacklisted_paths': [r'^/foo/?']}
    for path in ['/foo', '/foo/1/3', '/foo/bar', '/foobar']:
        dummy_request.path = path
        assert request_helper.should_not_sample_path(dummy_request)
Example #3
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_path_returns_false_if_path_not_blacklisted(request):
    request.registry.settings = {'zipkin.blacklisted_paths': [r'^/foo/?']}
    for path in ['/bar', '/bar/foo', '/foe']:
        request.path = path
        assert not request_helper.should_not_sample_path(request)
Example #5
0
def test_should_not_sample_path_returns_false_if_path_not_blacklisted(request):
    request.registry.settings = {'zipkin.blacklisted_paths': [r'^/foo/?']}
    for path in ['/bar', '/bar/foo', '/foe']:
        request.path = path
        assert not request_helper.should_not_sample_path(request)