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

include rows_affected count in dbapi2 instrumentations #614

Merged
merged 6 commits into from
May 7, 2020

Conversation

beniwohli
Copy link
Contributor

@beniwohli beniwohli commented Oct 21, 2019

fixes #613

depends on elastic/apm-server#2802

@beniwohli beniwohli changed the title include affected_rows count in dbapi2 instrumentations include rows_affected count in dbapi2 instrumentations Oct 21, 2019
Copy link
Member

@axw axw left a comment

Choose a reason for hiding this comment

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

nice!

return method(sql, params)
result = method(sql, params)
# store "rows affected", but only for insert/update/delete
if span and self.rowcount not in (-1, None) and signature[:6] in DML_QUERIES:
Copy link
Member

Choose a reason for hiding this comment

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

maybe extract 6 to the top of the file, and compute it from the lengths of the strings in DML_QUERIES? we might end up adding additional dialect-specific statement types

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, this seemed like a cute little optimization at the time ("oh look, all 3 keywords are 6 characters long, nice!"), but probably not worth the hassle. I'll modify to signature.startswith(DML_QUERIES), which, funny story, according to timeit is about 10% faster ¯\_(ツ)_/¯.

But you bring up an interesting point regarding dialects. DML_QUERIES should probably live on the CursorProxy, so that driver-specific subclasses can override it.

Copy link
Member

Choose a reason for hiding this comment

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

Hah :)
Sounds good to me.

# Conflicts:
#	CHANGELOG.md
#	elasticapm/traces.py
#	tests/instrumentation/pymssql_tests.py
@apmmachine
Copy link
Contributor

apmmachine commented May 7, 2020

💚 Build Succeeded

Pipeline View Test View Changes Artifacts preview stats

Expand to view the summary

Build stats

Test stats 🧪

Test Results
Failed 0
Passed 9209
Skipped 6667
Total 15876

@beniwohli beniwohli merged commit a577638 into elastic:master May 7, 2020
@beniwohli beniwohli deleted the fix-613 branch May 7, 2020 14:50
romulorosa pushed a commit to romulorosa/apm-agent-python that referenced this pull request Oct 15, 2020
* include `rows_affected` count in dbapi2 instrumentations

fixes elastic#613

* fix tests

* only capture `rows_affected` for INSERT/UPDATE/DELETE queries

* use `startswith(DML_QUERIES)` instead of relying on all keywords being 6 characters

* update changelog
romulorosa pushed a commit to romulorosa/apm-agent-python that referenced this pull request Oct 15, 2020
* include `rows_affected` count in dbapi2 instrumentations

fixes elastic#613

* fix tests

* only capture `rows_affected` for INSERT/UPDATE/DELETE queries

* use `startswith(DML_QUERIES)` instead of relying on all keywords being 6 characters

* update changelog
beniwohli added a commit to beniwohli/apm-agent-python that referenced this pull request Sep 14, 2021
* include `rows_affected` count in dbapi2 instrumentations

fixes elastic#613

* fix tests

* only capture `rows_affected` for INSERT/UPDATE/DELETE queries

* use `startswith(DML_QUERIES)` instead of relying on all keywords being 6 characters

* update changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Capture rows_affected in DB-API2 integrations
4 participants