-
Notifications
You must be signed in to change notification settings - Fork 641
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
Fix sqlalchemy uninstrument #1581
Changes from all commits
8cd9168
3536964
0975434
0bac6a0
8edb72a
df24e6b
7fca774
c85c256
c883c48
e12a2b2
2a0e744
ec12619
1f8b2a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -248,12 +248,41 @@ def test_uninstrument(self): | |||
|
||||
self.memory_exporter.clear() | ||||
SQLAlchemyInstrumentor().uninstrument() | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please dont call def test_uninstrument(self):
engine = create_engine("sqlite:///:memory:")
instrumentor = SQLAlchemyInstrumentor()
instrumentor.instrument(
engine=engine,
tracer_provider=self.tracer_provider,
)
cnx = engine.connect()
cnx.execute("SELECT 1 + 1;").fetchall()
spans = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans), 2)
# first span - the connection to the db
self.assertEqual(spans[0].name, "connect")
self.assertEqual(spans[0].kind, trace.SpanKind.CLIENT)
# second span - the query itself
self.assertEqual(spans[1].name, "SELECT :memory:")
self.assertEqual(spans[1].kind, trace.SpanKind.CLIENT)
self.memory_exporter.clear()
instrumentor.uninstrument()
cnx.execute("SELECT 2 + 2;").fetchall()
spans = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans), 0) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure, can you explain what's the difference? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We dont want to create additional instrumentor class with new connection and new engine, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will not create another sqlalchemy instrumentor, if I understand this correctly it's like Singelton: Line 50 in c92ba14
What do you think? |
||||
cnx.execute("SELECT 1 + 1;").fetchall() | ||||
engine2 = create_engine("sqlite:///:memory:") | ||||
cnx2 = engine2.connect() | ||||
cnx2.execute("SELECT 2 + 2;").fetchall() | ||||
spans = self.memory_exporter.get_finished_spans() | ||||
self.assertEqual(len(spans), 0) | ||||
|
||||
SQLAlchemyInstrumentor().instrument( | ||||
engine=engine, | ||||
tracer_provider=self.tracer_provider, | ||||
) | ||||
cnx = engine.connect() | ||||
cnx.execute("SELECT 1 + 1;").fetchall() | ||||
spans = self.memory_exporter.get_finished_spans() | ||||
self.assertEqual(len(spans), 2) | ||||
|
||||
def test_uninstrument_without_engine(self): | ||||
SQLAlchemyInstrumentor().instrument( | ||||
tracer_provider=self.tracer_provider | ||||
) | ||||
from sqlalchemy import create_engine | ||||
|
||||
engine = create_engine("sqlite:///:memory:") | ||||
|
||||
cnx = engine.connect() | ||||
cnx.execute("SELECT 1 + 1;").fetchall() | ||||
spans = self.memory_exporter.get_finished_spans() | ||||
self.assertEqual(len(spans), 2) | ||||
|
||||
self.memory_exporter.clear() | ||||
SQLAlchemyInstrumentor().uninstrument() | ||||
cnx.execute("SELECT 1 + 1;").fetchall() | ||||
spans = self.memory_exporter.get_finished_spans() | ||||
self.assertEqual(len(spans), 0) | ||||
|
||||
def test_no_op_tracer_provider(self): | ||||
engine = create_engine("sqlite:///:memory:") | ||||
SQLAlchemyInstrumentor().instrument( | ||||
|
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.
suggestion: maybe drop the 'remove'
like, call it
event_listener_params
, or evenevent_listeners
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.
but the params are for the remove function
I called the list like this so it will be clear that I keep the params only for remove
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.
i agree with the
event_listeners
name convention because that what you store in this listand it would be better name to use:
unregister_event_listeners
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.
Not exactly... I don't store the event listeners params, its without args and kwargs, for exmaple its without(retval=True)
I store the remove event listernes params