Skip to content

Conversation

@pglombardo
Copy link
Contributor

Noted by @steveww:

Just calling logging.error('foo') works when in the body of the route.
It does not work when inside an error handler.

import instana
import logging
import json
from flask import Flask

app = Flask(__name__)

@app.errorhandler(Exception)
def exception_handler(err):
    app.logger.error(str(err))
    return str(err), 500

@app.route('/health', methods=['GET'])
def health():
    return 'OK'

@app.route('/warning', methods=['GET'])
def warning():
    app.logger.warn('This is a warning')
    return 'warning', 400

@app.route('/error', methods=['GET'])
def error():
    app.logger.error('This is an error')
    return 'error', 500

@app.route('/rerror', methods=['GET'])
def rerror():
    found_it = False
    my_list = None
    for i in my_list:
        if i == 'foo':
            found_it = True

    return found_it


if __name__ == '__main__':
    app.logger.setLevel(logging.INFO)
    app.logger.info('Starting')
    app.run(host='0.0.0.0', port=8080)

@steveww
Copy link
Contributor

steveww commented Jun 20, 2019

Looks like it's a clash with instrumentation/flask/vanilla.py
There is a wrapper around handle_user_exception that interferes. It closes the scope so there is None scope when the logging instrumentation tries to add an error span.

@steveww
Copy link
Contributor

steveww commented Jun 20, 2019

PR #173 created.

@pglombardo pglombardo mentioned this pull request Jul 10, 2019
@pglombardo pglombardo merged commit 787b19b into master Aug 26, 2019
@pglombardo pglombardo deleted the issue-172 branch August 26, 2019 11:35
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

Successfully merging this pull request may close these issues.

3 participants