Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_set_correlation_id():
""" Test setting correlation_id """
correlation_id = '1234'
cf_logging.init(level=logging.DEBUG)
cf_logging.FRAMEWORK.context.set_correlation_id(correlation_id)
logger, stream = config_logger('cli.test')
logger.info('hi')
log_json = JSONDecoder().decode(stream.getvalue())
_, error = JsonValidator(JOB_LOG_SCHEMA).validate(log_json)
assert error == {}
assert log_json['correlation_id'] == correlation_id
assert cf_logging.FRAMEWORK.context.get_correlation_id() == correlation_id
def _wrapper(request):
correlation_id = cf_logging.FRAMEWORK.request_reader.get_correlation_id(request)
cf_logging.FRAMEWORK.context.set_correlation_id(correlation_id, request)
cf_logging.FRAMEWORK.context.set('request_started_at', datetime.utcnow(), request)
return wrapped(request)
def process_request(self, request, response): # pylint: disable=unused-argument,no-self-use
"""Process the request before routing it.
:param request: - Falcon Request object
:param response: - Falcon Response object
"""
framework = cf_logging.FRAMEWORK
cid = framework.request_reader.get_correlation_id(request)
framework.context.set_correlation_id(cid, request)
framework.context.set('request_started_at', datetime.utcnow(), request)
def _wrapper():
framework = cf_logging.FRAMEWORK
cid = framework.request_reader.get_correlation_id(request)
framework.context.set_correlation_id(cid, request)
framework.context.set('request_started_at', datetime.utcnow(), request)
return wrapped()
return _wrapper