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

[dbapi] Trace db fetch and session methods #664

Merged
merged 21 commits into from
Nov 14, 2018

Conversation

labbati
Copy link
Member

@labbati labbati commented Oct 22, 2018

In addition to execute, executemany and callproc methods, we want to trace also the various fetch methods to provide users with a more powerful set of information.
In the process of doing so, we realized that the django integration was using a custom tailored version of the dbapi traced cursor that could be replaced with the generic dbapi traced cursor.

Further, we want to create spans for the session-level commit and rollback methods.

@brettlangdon
Copy link
Member

do you have any sample traces? mostly curious to see what these look like, it is usually a 1:1 of sql.query to sql.query.fetch* method?

@labbati
Copy link
Member Author

labbati commented Oct 23, 2018

do you have any sample traces? mostly curious to see what these look like, it is usually a 1:1 of sql.query to sql.query.fetch* method?

Sure here it is

image

To answer you question, correct, there is one sql.query.fetch* (or more in the case of multiple calls to fetchone/fetchmany ) for each sql.query (of course when a fetch is called).

@brettlangdon
Copy link
Member

cool, looks great. I think my concern was if we end up with a library that calls .fetchmany(1) like 1k times to pull in 1k items or something funky... but.... lets hope that no one does that :)

@labbati
Copy link
Member Author

labbati commented Oct 25, 2018

Your concern is absolutely reasonable. I would say that in the real world if someone calls .fetchmany(1) (or .execute()) 1k times, both the span overhead in terms of cpu and IO (to transfer spans to the agent) would still be (probably) irrelevant compared to the DB interactions. But good thing we are thinking about it.

@brettlangdon
Copy link
Member

is this still considered a WIP?

@labbati
Copy link
Member Author

labbati commented Oct 25, 2018

@brettlangdon I need to take some time to go through it for final checks. Will do asap!

ddtrace/contrib/dbapi/__init__.py Outdated Show resolved Hide resolved
ddtrace/contrib/django/db.py Show resolved Hide resolved
ddtrace/contrib/django/db.py Outdated Show resolved Hide resolved
@majorgreys majorgreys changed the title Trace fetch methods Trace dbapi fetch and session methods Nov 7, 2018
Copy link
Member

@brettlangdon brettlangdon left a comment

Choose a reason for hiding this comment

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

big picture looks pretty good, few minor changes.

ddtrace/contrib/dbapi/__init__.py Outdated Show resolved Hide resolved
tests/contrib/dbapi/test_unit.py Outdated Show resolved Hide resolved
tests/contrib/dbapi/test_unit.py Outdated Show resolved Hide resolved
tests/contrib/dbapi/test_unit.py Outdated Show resolved Hide resolved
tests/contrib/dbapi/test_unit.py Outdated Show resolved Hide resolved
tests/contrib/sqlite3/test_sqlite3.py Outdated Show resolved Hide resolved
tox.ini Outdated Show resolved Hide resolved
tox.ini Outdated Show resolved Hide resolved
@majorgreys majorgreys self-assigned this Nov 8, 2018
@brettlangdon brettlangdon reopened this Nov 9, 2018
@brettlangdon brettlangdon added this to the 0.17.0 milestone Nov 9, 2018
@brettlangdon brettlangdon changed the base branch from 0.16-dev to 0.17-dev November 12, 2018 17:31
labbati and others added 13 commits November 12, 2018 16:25
* [core] add Tracer.on and Tracer.emit for span hooks

* [core] rename Tracer.emit to Tracer._emit

* [core] fix mispelling of Tracer._hooks

* [core] do not raise an exception or error log

* [falcon] add span hook documentation for Falcon

* [core] add tests for Tracer.on/Tracer._emit

* [core] add tracer hook argument tests

* [core] register span hooks on config object instead

* [core] fix flake8 issues

* Update ddtrace/settings.py

* Update ddtrace/settings.py

* Update ddtrace/settings.py

* [core] remove Hooks.__getattr__, add Hooks.on alias for Hooks.register
tox.ini Outdated Show resolved Hide resolved
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.

Just a couple things to clean-up. Looks good otherwise.

ddtrace/contrib/dbapi/__init__.py Outdated Show resolved Hide resolved
tests/contrib/dbapi/__init__.py Outdated Show resolved Hide resolved
@majorgreys majorgreys changed the title Trace dbapi fetch and session methods [dbapi] Trace db fetch and session methods Nov 13, 2018
Kyle-Verhoog
Kyle-Verhoog previously approved these changes Nov 14, 2018
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.

Good stuff. Caught a find and replace mistake, but isn't show stopping.

tests/contrib/sqlite3/test_sqlite3.py Outdated Show resolved Hide resolved
@majorgreys majorgreys merged commit 04da524 into 0.17-dev Nov 14, 2018
@majorgreys majorgreys deleted the labbati/dbapi-trace-fetch branch November 14, 2018 16:03
Kyle-Verhoog pushed a commit that referenced this pull request Nov 23, 2018
* [dbapi] Trace fetch methods

* [dbapi] Fix unit tests after adding the row count as a tag for django integration backward compatibilityè

* [dbapi] Minor fixes to the the dbapi tracing implementation

* Add tracing to commit and rollback to dbapi

* Add tests for dbapi TracedConnections

* [core] add support for integration span hooks (#679)

* [core] add Tracer.on and Tracer.emit for span hooks

* [core] rename Tracer.emit to Tracer._emit

* [core] fix mispelling of Tracer._hooks

* [core] do not raise an exception or error log

* [falcon] add span hook documentation for Falcon

* [core] add tests for Tracer.on/Tracer._emit

* [core] add tracer hook argument tests

* [core] register span hooks on config object instead

* [core] fix flake8 issues

* Update ddtrace/settings.py

* Update ddtrace/settings.py

* Update ddtrace/settings.py

* [core] remove Hooks.__getattr__, add Hooks.on alias for Hooks.register

* Add tests to dbapi for commit/rollback

* Update test for fetch tracing

* Update tests for changes to commit/rollback tracing

* Replace double quotes

* Replace pytest+fixtures with unittest

* Add tracer to pin

* Convert double quotes to single

* Remove unnecessary tox changes

* Update tests

* Clean-up

* Remove duplicate test

* Update tests/contrib/sqlite3/test_sqlite3.py

Co-Authored-By: majorgreys <tahir@tahirbutt.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants