Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    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
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
    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
Exemplo n.º 7
0
    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
Exemplo n.º 8
0
    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 = []
Exemplo n.º 9
0
Arquivo: app.py Projeto: hhru/frontik
    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})
Exemplo n.º 10
0
    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})
Exemplo n.º 11
0
    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 = []
Exemplo n.º 12
0
 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
Exemplo n.º 13
0
 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