예제 #1
0
async def home(request):
    logger.info("test log statement")
    logger.info("test log statement with extra props",
                extra={'props': {
                    "extra_property": 'extra_value'
                }})
    # this will be faster
    correlation_id = json_logging.get_correlation_id(request=request)
    # this will be slower, but will work in context you cant get a reference of request object
    correlation_id_without_request_obj = json_logging.get_correlation_id()

    return sanic.response.text("hello world")
예제 #2
0
    async def post(self, request):
        """
        ASYNC post method which will evaluate the input JSON schema and if the
        schema is valid, will produce the message to KAFKA TOPIC.

        :param request: Input Request
        :return: dict with status and message
        """
        input_record = request.json
        try:
            logger.debug("Validating the input record")
            validate(instance=input_record, schema=app.config.SCHEMA)
            logger.info("Input Record has been successfully Validated")

            if input_record["currency"] in app.config.ALL_CURRENCIES:
                logger.info("Everything looks great, queuing record for "
                            "persistence")
                input_record['_id'] = json_logging.get_correlation_id()
                app.config.PRODUCER.produce(app.config.TOPIC,
                                            dumps(input_record))
                logger.debug("record published")
                app.config.PRODUCER.flush()

                return {"status": 200, "message": "Record persisted"}, 200

            else:
                return {
                    "status": 400,
                    "error": "invalid currency code found"
                }, 400

        except ValidationError:
            logger.error("Invalid Currency found in the record")
            return {"status": 400, "error": traceback.format_exc()}, 400
예제 #3
0
def home():
    logger.info("test log statement")
    logger.info("test log statement with extra props",
                extra={'props': {
                    "extra_property": 'extra_value'
                }})
    correlation_id = json_logging.get_correlation_id()
    return "Hello world : " + str(datetime.datetime.now())
예제 #4
0
def main():
    logger.info("test log statement")
    correlation_id = json_logging.get_correlation_id()
    logger.info("test log statement with extra props",
                extra={'props': {
                    "correlation_id": correlation_id
                }})
    return '<html><p><a href="/wait/4">/wait/4</a><p><a href="/status/500">/status/500</a></html></html>'
예제 #5
0
def home():
    logger.info("test log statement")
    logger.info("test log statement with extra props",
                extra={'props': {
                    "extra_property": 'extra_value'
                }})
    correlation_id = json_logging.get_correlation_id()
    return "hello world" \
           "\ncorrelation_id                    : " + correlation_id
예제 #6
0
 async def get_correlation_id():
     return {'correlation_id': json_logging.get_correlation_id()}
 def format(self, record):
     json_customized_log_object = ({
         "customized_prop": "customized value",
         "correlation_id": json_logging.get_correlation_id(),
     })
     return json.dumps(json_customized_log_object)
async def add_x_request_id_response_header(request: Request, call_next):
    response = await call_next(request)
    response.headers["X-Request-ID"] = json_logging.get_correlation_id(
        request=request)
    return response