-
Notifications
You must be signed in to change notification settings - Fork 658
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
Adding DB API integration + MySQL connector integration #264
Conversation
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 approach looks good, but is this wrapping the right library?
ext/opentelemetry-ext-mysql/src/opentelemetry/ext/mysql/version.py
Outdated
Show resolved
Hide resolved
ext/opentelemetry-ext-mysql/src/opentelemetry/ext/mysql/__init__.py
Outdated
Show resolved
Hide resolved
raise Exception("Test Exception") | ||
|
||
|
||
class MockSpan: |
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.
are MockSpan and MockTracer needed? I feel like we have a no-op tracer now with the API.
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 wanted to test the integration code is creating the span correctly, API tracer is no-op so it will not create anything, are you suggesting to use unittest.Mock with a side effect or some other pattern to test 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.
Using no-op tracer in tests but still using MockSpan to check all attributes are set up correctly
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.
could use a Mock object which takes the Tracer as as a spec: https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock
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.
if the purpose here is to provide a general test utility for tracers, I guess I'd rather see it shared in something like opentelemetry-api. But I'm not sure if sharing test fixtures across projects is an accepted policy.
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.
Mocking tracer using mock library now, for Span I prefer to create my own mock class so is easier to test the integration adding correct attributes to the Span
@c24t I decided to use wrapt library to monkey patch because it was easy to understand and apply it here, I was interested in not altering original code including signatures and types, I gave a try with functools as well, some other integration is using it already in this project, but had some issues patching the cursor methods. I'm open to suggestions and ideas for this |
Added dbapi extension to be shared by all libraries using Python Database API specification |
Adding executemany and callproc wrap
Codecov Report
@@ Coverage Diff @@
## master #264 +/- ##
=======================================
Coverage 84.82% 84.82%
=======================================
Files 38 38
Lines 1839 1839
Branches 217 217
=======================================
Hits 1560 1560
Misses 214 214
Partials 65 65
Continue to review full report at Codecov.
|
@c24t we talked about using wrapt in today OT SIG meeting, everyone agreed it was fine to use this library, is actually heavily used in OpenTracing integrations https://github.com/opentracing-contrib?utf8=%E2%9C%93&q=python&type=&language= |
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.
Two blocking comments:
- Connection properties being potentially overriden when calling
connect
multiple times: Adding DB API integration + MySQL connector integration #264 (comment) - Accidental exception swallowing: Adding DB API integration + MySQL connector integration #264 (comment)
ext/opentelemetry-ext-dbapi/src/opentelemetry/ext/dbapi/__init__.py
Outdated
Show resolved
Hide resolved
ext/opentelemetry-ext-dbapi/src/opentelemetry/ext/dbapi/__init__.py
Outdated
Show resolved
Hide resolved
ext/opentelemetry-ext-mysql/src/opentelemetry/ext/mysql/__init__.py
Outdated
Show resolved
Hide resolved
ext/opentelemetry-ext-dbapi/src/opentelemetry/ext/dbapi/__init__.py
Outdated
Show resolved
Hide resolved
ext/opentelemetry-ext-dbapi/src/opentelemetry/ext/dbapi/__init__.py
Outdated
Show resolved
Hide resolved
ext/opentelemetry-ext-dbapi/src/opentelemetry/ext/dbapi/__init__.py
Outdated
Show resolved
Hide resolved
ext/opentelemetry-ext-dbapi/src/opentelemetry/ext/dbapi/__init__.py
Outdated
Show resolved
Hide resolved
ext/opentelemetry-ext-dbapi/src/opentelemetry/ext/dbapi/__init__.py
Outdated
Show resolved
Hide resolved
other integrations Updated versions Added capabilities to specify connection attribute names
I don't have time to look into this currently.
@Oberon00 all comments have been resolved now, let me know if you have more feedback, thanks |
"""Integrate with MySQL Connector/Python library. | ||
https://dev.mysql.com/doc/connector-python/en/ | ||
""" | ||
connection_attributes = { |
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.
Maybe put this outside the function so it doesn't have to be defined more than once?
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! Thanks for powering through this.
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 really good! There's a couple small things (like using the global logging module) that I think should be addressed, but by and large the code (and tests) look great.
ext/opentelemetry-ext-dbapi/src/opentelemetry/ext/dbapi/__init__.py
Outdated
Show resolved
Hide resolved
if tracer is None: | ||
raise ValueError("The tracer is not provided.") | ||
self.connection_attributes = connection_attributes | ||
if self.connection_attributes is None: |
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.
Just to clarify: is it possible that these connection_attributes don't reflect the actual connection established, since this is wrapping the connect method and different args can be passed there?
should there be some documentation added about what the attribute names should be, in that case? I could imagine people using slightly different names for the attributes which could lead to quite a mismatch in key names.
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.
Well the attributes names depends entirely on the dbapi library being used, if we support more popular libraries the less likely people will make mistakes, I agree having more documentation is always good so I added more details
ext/opentelemetry-ext-dbapi/src/opentelemetry/ext/dbapi/__init__.py
Outdated
Show resolved
Hide resolved
ext/opentelemetry-ext-dbapi/src/opentelemetry/ext/dbapi/__init__.py
Outdated
Show resolved
Hide resolved
ext/opentelemetry-ext-dbapi/src/opentelemetry/ext/dbapi/__init__.py
Outdated
Show resolved
Hide resolved
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.
Great! Thanks for addressing feedback.
amazing! Thanks @hectorhdzg! |
Took OpenCensus implementation as starting point for this, there are significant changes now including different fields to store in the Span object and monkey patching process.
https://github.com/census-instrumentation/opencensus-python/tree/master/contrib/opencensus-ext-mysql
MySQL Connector docs
https://dev.mysql.com/doc/connector-python/en/