12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
15
+ import psycopg
15
16
import psycopg2
16
17
from test_psycopg_functional import (
17
18
POSTGRES_DB_NAME ,
21
22
POSTGRES_USER ,
22
23
)
23
24
25
+ from opentelemetry .instrumentation .psycopg import PsycopgInstrumentor
24
26
from opentelemetry .instrumentation .psycopg2 import Psycopg2Instrumentor
25
27
from opentelemetry .test .test_base import TestBase
26
28
27
29
28
- class TestFunctionalPsycopg (TestBase ):
30
+ class TestFunctionalPsycopg2 (TestBase ):
29
31
def setUp (self ):
30
32
super ().setUp ()
31
33
self ._tracer = self .tracer_provider .get_tracer (__name__ )
@@ -52,3 +54,52 @@ def test_commenter_enabled(self):
52
54
self ._cursor .query .decode ("ascii" ),
53
55
r"SELECT 1 /\*db_driver='psycopg2(.*)',dbapi_level='\d.\d',dbapi_threadsafety=\d,driver_paramstyle=(.*),libpq_version=\d*,traceparent='\d{1,2}-[a-zA-Z0-9_]{32}-[a-zA-Z0-9_]{16}-\d{1,2}'\*/;" ,
54
56
)
57
+
58
+
59
+ class TestFunctionalPsycopg (TestBase ):
60
+ def setUp (self ):
61
+ super ().setUp ()
62
+ self ._tracer = self .tracer_provider .get_tracer (__name__ )
63
+ PsycopgInstrumentor ().instrument (enable_commenter = True )
64
+
65
+ def tearDown (self ):
66
+ PsycopgInstrumentor ().uninstrument ()
67
+ super ().tearDown ()
68
+
69
+ def test_commenter_enabled_root_module (self ):
70
+ connection = psycopg .connect (
71
+ dbname = POSTGRES_DB_NAME ,
72
+ user = POSTGRES_USER ,
73
+ password = POSTGRES_PASSWORD ,
74
+ host = POSTGRES_HOST ,
75
+ port = POSTGRES_PORT ,
76
+ )
77
+ connection .set_session (autocommit = True )
78
+ cursor = connection .cursor ()
79
+ cursor .execute ("SELECT 1;" )
80
+ self .assertRegex (
81
+ cursor .query .decode ("ascii" ),
82
+ r"SELECT 1 /\*db_driver='psycopg(.*)',dbapi_level='\d.\d',dbapi_threadsafety=\d,driver_paramstyle=(.*),libpq_version=\d*,traceparent='\d{1,2}-[a-zA-Z0-9_]{32}-[a-zA-Z0-9_]{16}-\d{1,2}'\*/;" ,
83
+ )
84
+
85
+ cursor .close ()
86
+ connection .close ()
87
+
88
+ def test_commenter_enabled_not_root_module (self ):
89
+ connection = psycopg .Connection .connect (
90
+ dbname = POSTGRES_DB_NAME ,
91
+ user = POSTGRES_USER ,
92
+ password = POSTGRES_PASSWORD ,
93
+ host = POSTGRES_HOST ,
94
+ port = POSTGRES_PORT ,
95
+ )
96
+ connection .set_session (autocommit = True )
97
+ cursor = connection .cursor ()
98
+ cursor .execute ("SELECT 1;" )
99
+ self .assertRegex (
100
+ cursor .query .decode ("ascii" ),
101
+ r"SELECT 1 /\*db_driver='psycopg(.*)',dbapi_level='\d.\d',dbapi_threadsafety=\d,driver_paramstyle=(.*),traceparent='\d{1,2}-[a-zA-Z0-9_]{32}-[a-zA-Z0-9_]{16}-\d{1,2}'\*/;" ,
102
+ )
103
+
104
+ cursor .close ()
105
+ connection .close ()
0 commit comments