def test_send_event(self): ''' test correct behavior for send_event ''' ev = Mock() delattr(ev, 'traced_event') self.m_state.pop_event.return_value = ev beeline._send_event() self.m_state.pop_event.assert_called_once_with() ev.send.assert_called_once_with()
def send_traced_event(self): ''' test send_event behavior when event is traced ''' ev = Mock() ev.traced_event = True self.m_state.pop_event.return_value = ev beeline._send_event() self.m_state.pop_event.assert_called_once_with() self.m_tracer.send_traced_event.assert_called_once_with(ev)
def _start_response(status, headers, *args): status_code = int(status[0:4]) beeline.add_field("response.status_code", status_code) if status_code != 500: beeline._send_event() elif status_code == 500 and not signals.signals_available: beeline._send_event() return start_response(status, headers, *args)
def after_cursor_execute(self, conn, cursor, statement, parameters, context, executemany): if not current_app: return query_duration = datetime.datetime.now() - self.query_start_time beeline.add({ "db.duration": query_duration.total_seconds() * 1000, "db.last_insert_id": cursor.lastrowid, "db.rows_affected": cursor.rowcount, }) beeline._send_event()
def create_http_event(self, request): # Code to be executed for each request before # the view (and later middleware) are called. trace_name = "django_http_%s" % request.method.lower() beeline._new_event(data={ "type": "http_server", "request.host": request.get_host(), "request.method": request.method, "request.path": request.path, "request.remote_addr": request.META['REMOTE_ADDR'], "request.content_length": request.META.get('CONTENT_LENGTH', '0'), "request.user_agent": request.META.get('HTTP_USER_AGENT', ''), "request.scheme": request.scheme, "request.secure": request.is_secure(), "request.query": request.GET.dict(), "request.xhr": request.is_ajax(), "request.post": request.POST.dict() }, trace_name=trace_name, top_level=True) response = self.get_response(request) # Code to be executed for each request/response after # the view is called. beeline.add_field("response.status_code", response.status_code) beeline._send_event() return response
def test_send_no_events(self): ''' ensure nothing crashes when we try to send with no events in the stack ''' self.m_state.pop_event.return_value = None beeline._send_event() self.m_state.pop_event.assert_called_once_with()
def _teardown_request(self, exception): if exception: beeline.add_field('request.error_detail', str(exception)) beeline.add_field('request.error', str(type(exception))) beeline._send_event()
def handle_error(self, context): beeline.add_field("db.error", str(context.original_exception)) beeline._send_event()
def _start_response(status, headers, *args): beeline.add_field("response.status_code", status) beeline._send_event() return start_response(status, headers, *args)