Skip to content

json_logging library is breaking Sanic app #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Sureya opened this issue Jul 10, 2020 · 5 comments
Closed

json_logging library is breaking Sanic app #49

Sureya opened this issue Jul 10, 2020 · 5 comments

Comments

@Sureya
Copy link

Sureya commented Jul 10, 2020

When I execute the following code. I get an error

# in-built
import logging
from sys import stdout

# 3rd party
import json_logging
from sanic import Sanic
from sanic_restful_api import Api, Resource


app = Sanic(__name__)
api = Api(app)

# JSON logging configuration
json_logging.ENABLE_JSON_LOGGING = True
json_logging.CREATE_CORRELATION_ID_IF_NOT_EXISTS = True
json_logging.init_sanic()
json_logging.init_request_instrument(app)
logger = logging.getLogger("extractor-app")
logger.setLevel(logging.INFO)
logger.addHandler(logging.StreamHandler(stdout))


class ParseData(Resource):
    async def post(self, request):
        input_record = request.json
        logger.info("Everything looks great, queuing record for ")
        input_record['_id'] = json_logging.get_correlation_id()
        logger.info("corelation parsed")
        return input_record, 200


api.add_resource(ParseData, '/review')

if __name__ == '__main__':
    app.run(host="0.0.0.0", port=9558, debug=True)
 File "..//lib/python3.6/site-packages/json_logging/framework/sanic/__init__.py", line 100, in get_correlation_id_in_request_context
    return request.get('correlation_id')
AttributeError: 'Request' object has no attribute 'get'

But if I remove the json_logging it works,

this works

# in-built
import logging
from sys import stdout

# 3rd party
import json_logging
from sanic import Sanic
from sanic_restful_api import Api, Resource


app = Sanic(__name__)
api = Api(app)

# JSON logging configuration
logger = logging.getLogger("extractor-app")
logger.setLevel(logging.INFO)
logger.addHandler(logging.StreamHandler(stdout))


class ParseData(Resource):
    async def post(self, request):
        input_record = request.json
        logger.info("Everything looks great, queuing record for ")
        logger.info("corelation parsed")
        return input_record, 200


api.add_resource(ParseData, '/review')

if __name__ == '__main__':
    app.run(host="0.0.0.0", port=9558, debug=True)
@Sureya
Copy link
Author

Sureya commented Jul 10, 2020

@thangbn: Any help on this would be much appreciated

@bobbui
Copy link
Owner

bobbui commented Jul 13, 2020

@Sureya hi will try to take a look ASAP

@Sureya
Copy link
Author

Sureya commented Jul 14, 2020

@thangbn : Thanks 👍

@bobbui
Copy link
Owner

bobbui commented Jul 15, 2020

@Sureya this bug is caused by a breaking upgrade introduce on sanic version 19.12.0: https://github.com/huge-success/sanic/releases/tag/v19.12.0
If you use an earlier version, it should be working fine.
I will try a patch the sanic support to make it work with latest sanic version

bobbui pushed a commit that referenced this issue Jul 15, 2020
@bobbui
Copy link
Owner

bobbui commented Jul 15, 2020

release fix on 1.2.1

@bobbui bobbui closed this as completed Jul 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants