def test_with_trace(self, mock_start, mock_stop): with profiler.Trace("a", info="a1"): mock_start.assert_called_once_with("a", info="a1") mock_start.reset_mock() with profiler.Trace("b", info="b1"): mock_start.assert_called_once_with("b", info="b1") mock_stop.assert_called_once_with() mock_stop.reset_mock() mock_stop.assert_called_once_with()
def __call__(self, request): if (_ENABLED is not None and not _ENABLED or _ENABLED is None and not self.enabled): return request.get_response(self.application) trace_info = utils.signed_unpack(request.headers.get(X_TRACE_INFO), request.headers.get(X_TRACE_HMAC), _HMAC_KEYS or self.hmac_keys) if not self._trace_is_valid(trace_info): return request.get_response(self.application) profiler.init(**trace_info) info = { "request": { "path": request.path, "query": request.query_string, "method": request.method, "scheme": request.scheme } } try: with profiler.Trace(self.name, info=info): return request.get_response(self.application) finally: profiler._clean()
def traced(request, name, info=None): if info is None: info = {} profiler_instance = profiler.get() if profiler_instance is not None: trace_id = profiler_instance.get_base_id() info['user_id'] = request.user.id with profiler.Trace(name, info=info): yield trace_id else: yield
def __call__(self, environ, start_response): request = webob.Request(environ) trace_info = utils.signed_unpack(request.headers.get(web.X_TRACE_INFO), request.headers.get(web.X_TRACE_HMAC), self.hmac_keys) if not self._trace_is_valid(trace_info): return self.application(environ, start_response) profiler.init(**trace_info) info = { "request": { "path": request.path, "query": request.query_string, "method": request.method, "scheme": request.scheme } } with profiler.Trace(self.name, info=info): return self.application(environ, start_response)
def profiler_context(*args, **kwargs): if is_profiler_enabled(): with profiler.Trace(*args, **kwargs) as tracer: yield tracer else: yield None
def foo(): with profiler.Trace("foo"): raise ValueError("bar")