Skip to content

Commit 8495643

Browse files
committed
audit asyncpg instrumentation with nooptracerprovider
1 parent 73ecf39 commit 8495643

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

instrumentation/opentelemetry-instrumentation-asyncpg/tests/test_asyncpg_wrapper.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from asyncpg import Connection, Record, cursor
66
from wrapt import ObjectProxy
77

8+
from opentelemetry import trace as trace_api
89
from opentelemetry.instrumentation.asyncpg import AsyncPGInstrumentor
910
from opentelemetry.test.test_base import TestBase
1011

@@ -105,3 +106,35 @@ async def exec_mock(*args, **kwargs):
105106
spans = self.memory_exporter.get_finished_spans()
106107
self.assertEqual(len(spans), 2)
107108
self.assertEqual([span.status.is_ok for span in spans], [True, True])
109+
110+
def test_no_op_tracer_provider(self):
111+
AsyncPGInstrumentor().uninstrument()
112+
AsyncPGInstrumentor().instrument(
113+
tracer_provider=trace_api.NoOpTracerProvider()
114+
) # Mock out all interaction with postgres
115+
116+
async def bind_mock(*args, **kwargs):
117+
return []
118+
119+
async def exec_mock(*args, **kwargs):
120+
return [], None, True
121+
122+
conn = mock.Mock()
123+
conn.is_closed = lambda: False
124+
125+
conn._protocol = mock.Mock()
126+
conn._protocol.bind = bind_mock
127+
conn._protocol.execute = exec_mock
128+
conn._protocol.bind_execute = exec_mock
129+
conn._protocol.close_portal = bind_mock
130+
131+
state = mock.Mock()
132+
state.closed = False
133+
134+
# init the cursor and fetch a single record
135+
crs = cursor.Cursor(conn, "SELECT * FROM test", state, [], Record)
136+
asyncio.run(crs._init(1))
137+
asyncio.run(crs.fetch(1))
138+
139+
spans = self.memory_exporter.get_finished_spans()
140+
self.assertEqual(len(spans), 0)

0 commit comments

Comments
 (0)