-
Notifications
You must be signed in to change notification settings - Fork 666
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
ext/pymysql: Add Instrumentor #611
ext/pymysql: Add Instrumentor #611
Conversation
Unwrap connect restores the original behaviour of the connect method.
- Implement instrumentor interface to be usable by autoinstrumentation - Provide mechanishm to uninstrument
if isinstance(conn, wrapt.ObjectProxy): | ||
setattr(connect_module, connect_method_name, conn.__wrapped__) | ||
|
||
|
||
class DatabaseApiIntegration: |
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.
Any reason to not use BaseInstrumentor in here as well?, people could be using dbapi instrumentor directly
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.
BaseInstrumentor
is used to implement an interface that allows to instrument all the calls made to a given library, for instance pymysql. AFAIU dbapi is a specification and not a library, so having an instrumentor here doesn't make sense. If a person wants to use dpapi directly, they should use the wrap_connect
and unwrap_connect
functions.
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.
Should document this? In the docstrings trace_integration()
is the recommended way to instrument. Perhaps we should expose an API method to uninstrument (since there isn't really a semantic similarity between trace_integration
and unwrap_connect
.
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 PyMySQL docstrings was wrong, trace_integration
doesn't exist anymore.
PymysqlInstrumentor
offers two methods, instrument
and uninstrument
.
I'm not sure what to do with the trace_integration
on dpapi, it's very similar to wrap_connect
but creates a tracer before. Maybe we could remove it and let the user play directly with wrap_connect
...
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.
Just some suggestions. 👍
ext/opentelemetry-ext-dbapi/src/opentelemetry/ext/dbapi/__init__.py
Outdated
Show resolved
Hide resolved
ext/opentelemetry-ext-pymysql/tests/test_pymysql_integration.py
Outdated
Show resolved
Hide resolved
def tearDown(self): | ||
super().tearDown() | ||
# ensure that it's uninstrumented if some of the tests fail | ||
PymysqlInstrumentor().uninstrument() |
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.
Please enclose this between logging.disable
calls to suppress unnecessary logging:
from logging import disable, WARNING, NOTSET
...
def tearDown(self):
...
disable(WARNING)
PymysqlInstrumentor().uninstrument()
disable(NOTSET)
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.
Thanks, I followed a similar approach.
@@ -184,7 +193,7 @@ def get_connection_attributes(self, connection): | |||
self.name += "." + self.database | |||
user = self.connection_props.get("user") | |||
if user is not None: | |||
self.span_attributes["db.user"] = user | |||
self.span_attributes["db.user"] = str(user) |
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.
User is not returned as string in some cases?
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.
Right, PyMySQL returns bytes and it was causing problems in the console exporter. I opened an issue about it #623.
ext/opentelemetry-ext-pymysql/src/opentelemetry/ext/pymysql/__init__.py
Outdated
Show resolved
Hide resolved
pymysql: pip install {toxinidir}/ext/opentelemetry-ext-dbapi | ||
pymysql: pip install {toxinidir}/ext/opentelemetry-ext-pymysql | ||
pymysql: pip install {toxinidir}/ext/opentelemetry-ext-pymysql[test] |
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 the [test] for using TestBase? How does this work?
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.
It's a way to tell pip to install opentelemetry-ext-pymysql and the dependencies on the extra test section: https://github.com/open-telemetry/opentelemetry-python/pull/611/files#diff-3874eac15d9a093a3db07c9283d97d12R48
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. Some non-blocking comments.
…__.py Co-Authored-By: Diego Hurtado <ocelotl@users.noreply.github.com>
- update changelog with link to previous PR - disable logging to avoid noise in teardown - rename to PyMySQLInstrumentor
How to try it:
pymysql_example.py
Run the example:
If everything went fine you see some spans on the terminal.