-
Notifications
You must be signed in to change notification settings - Fork 144
Fixing broken instrumentation for sqlalchemy >= 1.4.0 #289
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
439f371
Drop version pinning sqlalchemy and flask_sqlalchemy
srprash 4aba946
Check obj type instead of callable for functions
srprash d89eb37
testing
srprash 74b6d8f
Merge branch 'master' into sqlalchemy_140_fix
srprash bf1149d
Adding patch for Session.execute. Removing session.add test
srprash 2f216be
Remove unused variable
srprash 650ac53
Adding 2.0 style test case. Some refactor. Unwrap session.
srprash 8d2956a
Splitting out tests
srprash e1d5075
Typo fix
srprash 173ccdc
Refactored some tests files
srprash 33da1af
Merge branch 'master' into sqlalchemy_140_fix
srprash 335b778
Merge branch 'master' into sqlalchemy_140_fix
srprash 724b301
minor renaming of function
srprash 2d4a1ae
Merge branch 'master' into sqlalchemy_140_fix
srprash File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from __future__ import absolute_import | ||
|
||
import pytest | ||
from sqlalchemy import create_engine, Column, Integer, String | ||
from sqlalchemy.ext.declarative import declarative_base | ||
from sqlalchemy.orm import sessionmaker | ||
|
||
from aws_xray_sdk.core import xray_recorder, patch | ||
from aws_xray_sdk.core.context import Context | ||
|
||
Base = declarative_base() | ||
|
||
|
||
class User(Base): | ||
__tablename__ = 'users' | ||
|
||
id = Column(Integer, primary_key=True) | ||
name = Column(String) | ||
fullname = Column(String) | ||
password = Column(String) | ||
|
||
|
||
@pytest.fixture() | ||
def engine(): | ||
""" | ||
Clean up context storage on each test run and begin a segment | ||
so that later subsegment can be attached. After each test run | ||
it cleans up context storage again. | ||
""" | ||
from aws_xray_sdk.ext.sqlalchemy_core import unpatch | ||
patch(('sqlalchemy_core',)) | ||
engine = create_engine('sqlite:///:memory:') | ||
xray_recorder.configure(service='test', sampling=False, context=Context()) | ||
xray_recorder.begin_segment('name') | ||
Base.metadata.create_all(engine) | ||
xray_recorder.clear_trace_entities() | ||
xray_recorder.begin_segment('name') | ||
yield engine | ||
xray_recorder.clear_trace_entities() | ||
unpatch() | ||
|
||
|
||
@pytest.fixture() | ||
def connection(engine): | ||
return engine.connect() | ||
|
||
|
||
@pytest.fixture() | ||
def session(engine): | ||
Session = sessionmaker(bind=engine) | ||
return Session() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from .test_base import User, session, engine, connection | ||
from sqlalchemy.sql.expression import select | ||
from aws_xray_sdk.core import xray_recorder | ||
|
||
# 2.0 style execution test. see https://docs.sqlalchemy.org/en/14/changelog/migration_14.html#orm-query-is-internally | ||
# -unified-with-select-update-delete-2-0-style-execution-available | ||
def test_orm_style_select_execution(session): | ||
statement = select(User).where( | ||
User.name == 'John' | ||
) | ||
session.execute(statement) | ||
assert len(xray_recorder.current_segment().subsegments) == 1 | ||
sql_meta = xray_recorder.current_segment().subsegments[0].sql | ||
assert sql_meta['sanitized_query'].startswith('SELECT') | ||
assert 'FROM users' in sql_meta['sanitized_query'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.