-
Notifications
You must be signed in to change notification settings - Fork 212
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
Instrumentation for PyMSSQL #239
Comments
Hi @eliasbrange We already instrument SQL database calls on the DB-API2 level (basically, Do you think there would be a benefit in instrumenting SQLAlchemy directly over the current DB-API2-level instrumentation? |
Hmm. We are using http://pymssql.org/en/stable/ which might explain why I don't receive any captured spans then. I honestly can't answer that. Just started playing around with APM a couple of days ago. |
Yes, that would explain it :) Adding support for additional database drivers is (usually) quite simple, see e.g. #238 for the PyODBC instrumentation that we are currently working on. The most difficult part is getting tests to work, as we like to spin up a database to test that we don't break the actual connection between the driver and the database. I'll have a look how difficult it would be to get pymssql instrumented and tested :) |
Great! I'll try aswell. Got some of my DB calls in by instrumenting |
This seems to work somewhat. Might be a good starting point. from elasticapm.instrumentation.packages.dbapi2 import (ConnectionProxy,
CursorProxy,
DbApi2Instrumentation,
extract_signature)
class SQLAlchemyCursorProxy(CursorProxy):
provider_name = 'SQLAlchemy'
def extract_signature(self, sql):
return extract_signature(sql)
class SQLAlchemyConnectionProxy(ConnectionProxy):
cursor_proxy = SQLAlchemyCursorProxy
class SQLAlchemyInstrumentation(DbApi2Instrumentation):
name = 'SQLAlchemy'
instrument_list = [
("sqlalchemy.pool", "Pool.connect"),
("sqlalchemy.pool", "Pool.unique_connection"),
]
def call(self, module, method, wrapped, instance, args, kwargs):
return SQLAlchemyConnectionProxy(wrapped(*args, **kwargs)) |
@eliasbrange nice! However I'd prefer going forward with the current strategy of directly instrumenting the driver, instead of SQLAlchemy. That ensures that the instrumentation even works when using the driver directly, or a different ORM (e.g. Django's ORM). e.g. something like this (watch out, completely untested as of now :D)
|
That sure seems a lot more clever @beniwohli ... |
@beniwohli. How do I instrument the above instrumentation without adding it |
@eliasbrange we currently have no public API to register custom instrumentations (it's high on my todo list, though). However, I will open a PR with the above code as soon as I've figured out how to integrate it with our Test/CI setup, hopefully we'll have a new release in a few days. In the meantime, for testing and evaluation purposes, you technically could run |
is SQLAlchemy DB Calls logging available for apm? |
We use SQLAlchemy heavily and would like to instrument it. Might be able to find time to make an implementation myself if no one beats me to it.
https://pypi.org/project/SQLAlchemy/
http://www.sqlalchemy.org/
The text was updated successfully, but these errors were encountered: