def __init__(self, application, request, **kwargs): self.name = self.__class__.__name__ self.request_id = request.request_id = request_context.get_request_id() self.config = application.config self.log = handler_logger self.text = None super().__init__(application, request, **kwargs) self._preprocessor_futures = [] self._exception_hooks = [] for integration in application.available_integrations: integration.initialize_handler(self) self.stages_logger = StagesLogger(request, self.statsd_client) self._debug_access = None self._render_postprocessors = [] self._postprocessors = [] self._mandatory_cookies = {} self._mandatory_headers = tornado.httputil.HTTPHeaders() self.timeout_checker = None outer_timeout = request.headers.get(OUTER_TIMEOUT_MS_HEADER) if outer_timeout: self.timeout_checker = get_timeout_checker( request.headers.get(USER_AGENT_HEADER), float(outer_timeout), request.request_time)
def format(self, record): handler_name = request_context.get_handler_name() request_id = request_context.get_request_id() record.name = '.'.join(filter(None, [record.name, handler_name, request_id])) if not record.msg: record.msg = ', '.join(f'{k}={v}' for k, v in getattr(record, CUSTOM_JSON_EXTRA, {}).items()) return super().format(record)
def format(self, record): handler_name = request_context.get_handler_name() request_id = request_context.get_request_id() record.name = '.'.join(filter(None, [record.name, handler_name, request_id])) if not record.msg: record.msg = ', '.join(f'{k}={v}' for k, v in getattr(record, CUSTOM_JSON_EXTRA, {}).items()) return super().format(record)
def get_mdc(): mdc = {'thread': MDC.pid, 'role': MDC.role} handler_name = request_context.get_handler_name() if handler_name: mdc['controller'] = handler_name request_id = request_context.get_request_id() if request_id: mdc['rid'] = request_id return mdc
def get_mdc(self): mdc = { 'thread': self.PID } handler_name = request_context.get_handler_name() if handler_name: mdc['controller'] = handler_name request_id = request_context.get_request_id() if request_id: mdc['rid'] = request_id return mdc
def get_mdc(self): mdc = { 'thread': self.PID } handler_name = request_context.get_handler_name() if handler_name: mdc['controller'] = handler_name request_id = request_context.get_request_id() if request_id: mdc['rid'] = request_id return mdc
def modify_http_client_request(self, balanced_request: 'BalancedHttpRequest'): balanced_request.headers['x-request-id'] = request_context.get_request_id() balanced_request.headers[OUTER_TIMEOUT_MS_HEADER] = f'{balanced_request.request_timeout * 1000:.0f}' if self.timeout_checker is not None: self.timeout_checker.check(balanced_request) if self.debug_mode.pass_debug: balanced_request.headers[DEBUG_HEADER_NAME] = 'true' # debug_timestamp is added to avoid caching of debug responses balanced_request.uri = make_url(balanced_request.uri, debug_timestamp=int(time.time())) for header_name in ('Authorization', DEBUG_AUTH_HEADER_NAME): authorization = self.request.headers.get(header_name) if authorization is not None: balanced_request.headers[header_name] = authorization
def __init__(self, application, request, **kwargs): self.name = self.__class__.__name__ self.request_id = request.request_id = request_context.get_request_id() self.config = application.config self.log = handler_logger self.text = None super().__init__(application, request, **kwargs) self._preprocessor_futures = [] self._exception_hooks = [] for integration in application.available_integrations: integration.initialize_handler(self) self.stages_logger = StagesLogger(request, self.statsd_client) self._debug_access = None self._render_postprocessors = [] self._postprocessors = []
def log_request(self, handler): if not options.log_json: super().log_request(handler) return request_time = int(1000.0 * handler.request.request_time()) extra = { 'ip': handler.request.remote_ip, 'rid': request_context.get_request_id(), 'status': handler.get_status(), 'time': request_time, 'method': handler.request.method, 'uri': handler.request.uri, } handler_name = request_context.get_handler_name() if handler_name: extra['controller'] = handler_name JSON_REQUESTS_LOGGER.info('', extra={CUSTOM_JSON_EXTRA: extra})
def log_request(self, handler): if not options.log_json: super().log_request(handler) return request_time = int(1000.0 * handler.request.request_time()) extra = { 'ip': handler.request.remote_ip, 'rid': request_context.get_request_id(), 'status': handler.get_status(), 'time': request_time, 'method': handler.request.method, 'uri': handler.request.uri, } handler_name = request_context.get_handler_name() if handler_name: extra['controller'] = handler_name JSON_REQUESTS_LOGGER.info('', extra={CUSTOM_JSON_EXTRA: extra})
def __init__(self, application, request, **kwargs): self.name = self.__class__.__name__ self.request_id = request.request_id = request_context.get_request_id() self.config = application.config self.log = handler_logger self.text = None super().__init__(application, request, **kwargs) self._preprocessor_futures = [] self._exception_hooks = [] for integration in application.available_integrations: integration.initialize_handler(self) self.stages_logger = StagesLogger(request, self.statsd_client) self._debug_access = None self._render_postprocessors = [] self._postprocessors = []
def filter(self, record): handler_name = request_context.get_handler_name() request_id = request_context.get_request_id() record.name = '.'.join(filter(None, [record.name, handler_name, request_id])) return True
def filter(self, record): handler_name = request_context.get_handler_name() request_id = request_context.get_request_id() record.name = '.'.join(filter(None, [record.name, handler_name, request_id])) return True