Skip to content
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

[flask] avoid double instrumentation when TraceMiddleware is used #538

Merged
merged 3 commits into from
Aug 16, 2018

Conversation

palazzem
Copy link

Overview

In some cases it's possible to instrument the framework twice. For instance, using ddtrace-run and the TraceMiddleware together will produce unexpected behavior. Using both is not the right behavior and it's possible to hit this code-path, causing traces to not be sent.

This safe-guard ensures that signals and callbacks are attached to the Flask application only once, making the instrumentation idempotent and safe.

Note

I've refactored also the test suite, to make these tests possible. The main change is explained here: 23287fe

Copy link
Member

@Kyle-Verhoog Kyle-Verhoog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

besides the broken test, looks good!

def handle_me():
raise HandleMe()

@app.route('/fatal')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moving this route handler to this file breaks this line of this test:

assert re.search('File ".*/contrib/flask/test_flask.py", line [0-9]+, in fatal', s.meta.get(errors.ERROR_STACK))

since now the error is in contrib/flask/web.py

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch! thank you very much!

@palazzem palazzem merged commit 8f203d0 into master Aug 16, 2018
@palazzem palazzem deleted the palazzem/flask-double-instrumentation branch August 16, 2018 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants