Python opentracing.ext.tags.ERROR Examples

The following are 9 code examples of opentracing.ext.tags.ERROR(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module opentracing.ext.tags , or try the search function .
Example #1
Source File: tracing.py    From python-flask with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def _after_request_fn(self, response=None, error=None):
        request = stack.top.request

        # the pop call can fail if the request is interrupted by a
        # `before_request` method so we need a default
        scope = self._current_scopes.pop(request, None)
        if scope is None:
            return

        if response is not None:
            scope.span.set_tag(tags.HTTP_STATUS_CODE, response.status_code)
        if error is not None:
            scope.span.set_tag(tags.ERROR, True)
            scope.span.log_kv({
                'event': tags.ERROR,
                'error.object': error,
            })

        scope.close() 
Example #2
Source File: span.py    From apm-agent-python with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def log_kv(self, key_values, timestamp=None):
        exc_type, exc_val, exc_tb = None, None, None
        if "python.exception.type" in key_values:
            exc_type = key_values["python.exception.type"]
            exc_val = key_values.get("python.exception.val")
            exc_tb = key_values.get("python.exception.tb")
        elif ot_logs and key_values.get(ot_logs.EVENT) == tags.ERROR:
            exc_type = key_values[ot_logs.ERROR_KIND]
            exc_val = key_values.get(ot_logs.ERROR_OBJECT)
            exc_tb = key_values.get(ot_logs.STACK)
        else:
            logger.debug("Can't handle non-exception type opentracing logs")
        if exc_type:
            agent = self.tracer._agent
            agent.capture_exception(exc_info=(exc_type, exc_val, exc_tb))
        return self 
Example #3
Source File: tornado_http.py    From opentracing-python-instrumentation with MIT License 6 votes vote down vote up
def traced_fetch_impl(real_fetch_impl):

    @functools.wraps(real_fetch_impl)
    def new_fetch_impl(self, request, callback):
        request_wrapper = TornadoRequestWrapper(request=request)
        span = before_http_request(request=request_wrapper,
                                   current_span_extractor=get_current_span)

        def new_callback(response):
            if hasattr(response, 'code') and response.code:
                span.set_tag(tags.HTTP_STATUS_CODE, '%s' % response.code)
            if hasattr(response, 'error') and response.error:
                span.set_tag(tags.ERROR, True)
                span.log(event=tags.ERROR, payload='%s' % response.error)
            span.finish()
            return callback(response)

        real_fetch_impl(self, request, new_callback)

    return new_fetch_impl 
Example #4
Source File: span.py    From opentracing-python with Apache License 2.0 5 votes vote down vote up
def __exit__(self, exc_type, exc_val, exc_tb):
        """Ends context manager and calls finish() on the :class:`Span`.

        If exception has occurred during execution, it is automatically logged
        and added as a tag. :attr:`~operation.ext.tags.ERROR` will also be set
        to `True`.
        """
        Span._on_error(self, exc_type, exc_val, exc_tb)
        self.finish() 
Example #5
Source File: span.py    From opentracing-python with Apache License 2.0 5 votes vote down vote up
def _on_error(span, exc_type, exc_val, exc_tb):
        if not span or not exc_val:
            return

        span.set_tag(tags.ERROR, True)
        span.log_kv({
            logs.EVENT: tags.ERROR,
            logs.MESSAGE: str(exc_val),
            logs.ERROR_OBJECT: exc_val,
            logs.ERROR_KIND: exc_type,
            logs.STACK: exc_tb,
        }) 
Example #6
Source File: test_flask_tracing.py    From python-flask with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _verify_error(self, span):
        assert span.tags.get(tags.ERROR) is True

        assert len(span.logs) == 1
        assert span.logs[0].key_values.get('event', None) is tags.ERROR
        assert isinstance(
                span.logs[0].key_values.get('error.object', None),
                RuntimeError
        ) 
Example #7
Source File: test_flask_tracing.py    From python-flask with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_error(self):
        def start_span_cb(span, request):
            raise RuntimeError('Should not happen')

        tracing = FlaskTracing(MockTracer(), True, app,
                               start_span_cb=start_span_cb)
        rv = test_app.get('/test')
        assert '200' in str(rv.status_code)

        spans = tracing.tracer.finished_spans()
        assert len(spans) == 1
        assert spans[0].tags.get(tags.ERROR, None) is None 
Example #8
Source File: tracing.py    From python-django with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _finish_tracing(self, request, response=None, error=None):
        scope = self._current_scopes.pop(request, None)
        if scope is None:
            return

        if error is not None:
            scope.span.set_tag(tags.ERROR, True)
            scope.span.log_kv({
                'event': tags.ERROR,
                'error.object': error,
            })
        if response is not None:
            scope.span.set_tag(tags.HTTP_STATUS_CODE, response.status_code)

        scope.close() 
Example #9
Source File: test_middleware.py    From python-django with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def verify_traced_with_error(self):
        client = Client()
        with self.assertRaises(ValueError):
            client.get('/traced_with_error/')

        spans = settings.OPENTRACING_TRACING._tracer.finished_spans()
        assert len(spans) == 1
        assert spans[0].tags.get(tags.ERROR, False) is True

        assert len(spans[0].logs) == 1
        assert spans[0].logs[0].key_values.get('event', None) is 'error'
        assert isinstance(
                spans[0].logs[0].key_values.get('error.object', None),
                ValueError
        )