-
Notifications
You must be signed in to change notification settings - Fork 624
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
Add Flask Instrumentation fixes #601
Conversation
7cc2f19
to
d111d44
Compare
Reopening up the discussion. |
I think it is actually not addressing my comments yet. I exposed an alternative to this here #579 (review). |
Adding @mauriciovasquezbernal comments from past reviews:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good to me.
I have some concerns about the conditionals in the (un)-instrument_app functions. I'll do a more detailed review starting next week.
ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py
Outdated
Show resolved
Hide resolved
ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py
Outdated
Show resolved
Hide resolved
ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py
Outdated
Show resolved
Hide resolved
opentelemetry-auto-instrumentation/src/opentelemetry/auto_instrumentation/instrumentor.py
Outdated
Show resolved
Hide resolved
Addressed all your comments, @mauriciovasquezbernal, please review again when you have a moment. @lzchen, these changes address your previous concern about doing instrumentation by replacing the Thanks! |
This looks good. I'm curious as to whether we can merge the two methods of auto-instrumentation and programmatic instrumentation but still have it patch an |
It is possible but we preferred not to do so. We prefer not to have a method whose actions are different depending on the optional attributes it gets, we rather use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the changes in FlaskInstrumentor
.
I think the tests could be improved a bit, specially removing code duplication and simplifying the programmatic / automatic tests to avoid checking things that are already covered in other cases.
ext/opentelemetry-ext-flask/src/opentelemetry/ext/flask/__init__.py
Outdated
Show resolved
Hide resolved
btw, would you mind moving the entry point definitions to setup.cfg file to keep things uniform with other instrumentations? |
…__.py Co-Authored-By: Mauricio Vásquez <[email protected]>
Co-Authored-By: Mauricio Vásquez <[email protected]>
…__.py Co-authored-by: Mauricio Vásquez <[email protected]>
All your comments have been addressed, @mauriciovasquezbernal, thanks for the review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor nits. LGTM now, thanks for handling the feedback.
super().tearDown() | ||
with self.disable_logging(): | ||
FlaskInstrumentor().uninstrument_app(self.app) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth to check that calling (un)-instrument twice doesn't cause any issue?
|
||
trace.get_tracer_provider().add_span_processor( | ||
SimpleExportSpanProcessor(ConsoleSpanExporter()) | ||
) | ||
|
||
|
||
app = flask.Flask(__name__) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not related to this PR, but is this example missing app.run()
, how am I supposed to run it?
app.wsgi_app = app._original_wsgi_app | ||
|
||
# FIXME add support for other Flask blueprints that are not None | ||
app.before_request_funcs[None].remove(_before_request) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have you considered using the instrumented flag to turn off and on behavior, like the pymongo instrumentation?
Or you could remove by value by comparing the id of the function:
for k, v in before_request_funcs.items():
if v is _before_request:
del before_request_funcs[k]
Although the latter feels more error prone as you are relying on the data structure remaining the same across different versions of flask. The checking of the _is_instrumented value feels more robust here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think one small edge case around making sure uninstrument is robust, but all looks good otherwise!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue I raised currently won't affect anyone, since the instrumentation only instruments apps.
…y#601) * chore(plugin-mongodb-core): add missing codecov script * fix(mongodb-plugin): check currentSpan against undefined * chore(scope-managers): return undefined if no scope is found (following open-telemetry#569)
Fixes #599
This is just a separate PR to keep the Flask changes from blocking the instrumentation enhancements.