def request_id(self): if has_request_context() and hasattr(request, 'request_id'): return request.request_id elif has_app_context() and 'request_id' in g: return g.request_id else: return 'no-request-id'
def send_task(self, name, args=None, kwargs=None, **other_kwargs): kwargs = kwargs or {} if has_request_context() and hasattr(request, 'request_id'): kwargs['request_id'] = request.request_id elif has_app_context() and 'request_id' in g: kwargs['request_id'] = g.request_id return super().send_task(name, args, kwargs, **other_kwargs)
def apply_async(self, args=None, kwargs=None, **other_kwargs): kwargs = kwargs or {} if has_request_context() and hasattr(request, 'request_id'): kwargs['request_id'] = request.request_id elif has_app_context() and 'request_id' in g: kwargs['request_id'] = g.request_id return super().apply_async(args, kwargs, **other_kwargs)
def filter(self, log_record): """ Provide some extra variables to be placed into the log message """ # If we have an app context (because we're servicing an http request) then get the trace id we have # set in g (see app.py) if ctx.has_app_context(): log_record.trace_id = g.trace_id else: log_record.trace_id = 'N/A' return True
def apply_async(self, args=None, kwargs=None, task_id=None, producer=None, link=None, link_error=None, **options): kwargs = kwargs or {} if has_request_context() and hasattr(request, 'request_id'): kwargs['request_id'] = request.request_id elif has_app_context() and 'request_id' in g: kwargs['request_id'] = g.request_id with SQS_APPLY_ASYNC_DURATION_SECONDS.labels(self.name).time(): return super().apply_async(args, kwargs, task_id, producer, link, link_error, **options)
def filter(self, log_record): """Provide some extra variables to be placed into the log message""" # If we have an app context (because we're servicing an http request) then get the trace id we have # set in g (see app.py) if ctx.has_app_context(): log_record.trace_id = g.trace_id log_record.msg = "Endpoint: {}, Method: {}, Caller: {}.{}[{}], {}".format( request.endpoint, request.method, log_record.module, log_record.funcName, log_record.lineno, log_record.msg) else: log_record.trace_id = 'N/A' return True
def filter(self, log_record): """Provide some extra variables to be placed into the log message.""" # If we have an app context (because we're servicing an http request) then get the trace id we have # set in g (see app.py) # Also get other useful information about the request and session if ctx.has_app_context(): log_record.trace_id = g.trace_id # Augment log message with additional information if hasattr(g, 'session'): user_id = g.session.user.id else: user_id = "N/A" log_record.msg = "Endpoint: {}, Method: {}, User ID: {}, Caller: {}.{}[{}], {}".format( request.endpoint, request.method, user_id, log_record.module, log_record.funcName, log_record.lineno, log_record.msg) else: log_record.trace_id = 'N/A' return True
def service_id(self): if has_app_context() and 'service_id' in g: return g.service_id else: return 'no-service-id'