@@ -67,16 +67,84 @@ def test_instrumented_execute_method_without_arguments(self, *_, **__):
67
67
spans [0 ].attributes [SpanAttributes .DB_STATEMENT ], "SELECT 42;"
68
68
)
69
69
70
+ def test_instrumented_execute_method_error (self , * _ , ** __ ):
71
+ with self .assertRaises (AttributeError ):
72
+ async_call (self ._connection .execute ("" ))
73
+ spans = self .memory_exporter .get_finished_spans ()
74
+ self .assertEqual (len (spans ), 1 )
75
+ self .assertIs (StatusCode .ERROR , spans [0 ].status .status_code )
76
+ self .check_span (spans [0 ])
77
+ self .assertEqual (spans [0 ].name , POSTGRES_DB_NAME )
78
+ self .assertEqual (
79
+ spans [0 ].attributes [SpanAttributes .DB_STATEMENT ], ""
80
+ )
81
+
70
82
def test_instrumented_fetch_method_without_arguments (self , * _ , ** __ ):
71
83
async_call (self ._connection .fetch ("SELECT 42;" ))
72
84
spans = self .memory_exporter .get_finished_spans ()
73
85
self .assertEqual (len (spans ), 1 )
86
+ self .assertIs (StatusCode .UNSET , spans [0 ].status .status_code )
74
87
self .check_span (spans [0 ])
75
88
self .assertEqual (spans [0 ].name , "SELECT" )
76
89
self .assertEqual (
77
90
spans [0 ].attributes [SpanAttributes .DB_STATEMENT ], "SELECT 42;"
78
91
)
79
92
93
+ def test_instrumented_fetch_method_empty_query (self , * _ , ** __ ):
94
+ async_call (self ._connection .fetch ("" ))
95
+ spans = self .memory_exporter .get_finished_spans ()
96
+ self .assertEqual (len (spans ), 1 )
97
+ self .assertIs (StatusCode .UNSET , spans [0 ].status .status_code )
98
+ self .check_span (spans [0 ])
99
+ self .assertEqual (spans [0 ].name , POSTGRES_DB_NAME )
100
+ self .assertEqual (
101
+ spans [0 ].attributes [SpanAttributes .DB_STATEMENT ], ""
102
+ )
103
+
104
+ def test_instrumented_fetchval_method_without_arguments (self , * _ , ** __ ):
105
+ async_call (self ._connection .fetchval ("SELECT 42;" ))
106
+ spans = self .memory_exporter .get_finished_spans ()
107
+ self .assertEqual (len (spans ), 1 )
108
+ self .assertIs (StatusCode .UNSET , spans [0 ].status .status_code )
109
+ self .check_span (spans [0 ])
110
+ self .assertEqual (spans [0 ].name , "SELECT" )
111
+ self .assertEqual (
112
+ spans [0 ].attributes [SpanAttributes .DB_STATEMENT ], "SELECT 42;"
113
+ )
114
+
115
+ def test_instrumented_fetchval_method_empty_query (self , * _ , ** __ ):
116
+ async_call (self ._connection .fetchval ("" ))
117
+ spans = self .memory_exporter .get_finished_spans ()
118
+ self .assertEqual (len (spans ), 1 )
119
+ self .assertIs (StatusCode .UNSET , spans [0 ].status .status_code )
120
+ self .check_span (spans [0 ])
121
+ self .assertEqual (spans [0 ].name , POSTGRES_DB_NAME )
122
+ self .assertEqual (
123
+ spans [0 ].attributes [SpanAttributes .DB_STATEMENT ], ""
124
+ )
125
+
126
+ def test_instrumented_fetchrow_method_without_arguments (self , * _ , ** __ ):
127
+ async_call (self ._connection .fetchval ("SELECT 42;" ))
128
+ spans = self .memory_exporter .get_finished_spans ()
129
+ self .assertEqual (len (spans ), 1 )
130
+ self .assertIs (StatusCode .UNSET , spans [0 ].status .status_code )
131
+ self .check_span (spans [0 ])
132
+ self .assertEqual (spans [0 ].name , "SELECT" )
133
+ self .assertEqual (
134
+ spans [0 ].attributes [SpanAttributes .DB_STATEMENT ], "SELECT 42;"
135
+ )
136
+
137
+ def test_instrumented_fetchrow_method_empty_query (self , * _ , ** __ ):
138
+ async_call (self ._connection .fetchrow ("" ))
139
+ spans = self .memory_exporter .get_finished_spans ()
140
+ self .assertEqual (len (spans ), 1 )
141
+ self .assertIs (StatusCode .UNSET , spans [0 ].status .status_code )
142
+ self .check_span (spans [0 ])
143
+ self .assertEqual (spans [0 ].name , POSTGRES_DB_NAME )
144
+ self .assertEqual (
145
+ spans [0 ].attributes [SpanAttributes .DB_STATEMENT ], ""
146
+ )
147
+
80
148
def test_instrumented_remove_comments (self , * _ , ** __ ):
81
149
async_call (self ._connection .fetch ("/* leading comment */ SELECT 42;" ))
82
150
async_call (
@@ -88,18 +156,21 @@ def test_instrumented_remove_comments(self, *_, **__):
88
156
spans = self .memory_exporter .get_finished_spans ()
89
157
self .assertEqual (len (spans ), 3 )
90
158
self .check_span (spans [0 ])
159
+ self .assertIs (StatusCode .UNSET , spans [0 ].status .status_code )
91
160
self .assertEqual (spans [0 ].name , "SELECT" )
92
161
self .assertEqual (
93
162
spans [0 ].attributes [SpanAttributes .DB_STATEMENT ],
94
163
"/* leading comment */ SELECT 42;" ,
95
164
)
96
165
self .check_span (spans [1 ])
166
+ self .assertIs (StatusCode .UNSET , spans [1 ].status .status_code )
97
167
self .assertEqual (spans [1 ].name , "SELECT" )
98
168
self .assertEqual (
99
169
spans [1 ].attributes [SpanAttributes .DB_STATEMENT ],
100
170
"/* leading comment */ SELECT 42; /* trailing comment */" ,
101
171
)
102
172
self .check_span (spans [2 ])
173
+ self .assertIs (StatusCode .UNSET , spans [2 ].status .status_code )
103
174
self .assertEqual (spans [2 ].name , "SELECT" )
104
175
self .assertEqual (
105
176
spans [2 ].attributes [SpanAttributes .DB_STATEMENT ],
@@ -245,7 +316,7 @@ def test_instrumented_executemany_method_with_arguments(self, *_, **__):
245
316
async_call (self ._connection .executemany ("SELECT $1;" , [["1" ], ["2" ]]))
246
317
spans = self .memory_exporter .get_finished_spans ()
247
318
self .assertEqual (len (spans ), 1 )
248
-
319
+ self . assertIs ( StatusCode . UNSET , spans [ 0 ]. status . status_code )
249
320
self .check_span (spans [0 ])
250
321
self .assertEqual (
251
322
spans [0 ].attributes [SpanAttributes .DB_STATEMENT ], "SELECT $1;"
@@ -259,11 +330,25 @@ def test_instrumented_execute_interface_error_method(self, *_, **__):
259
330
async_call (self ._connection .execute ("SELECT 42;" , 1 , 2 , 3 ))
260
331
spans = self .memory_exporter .get_finished_spans ()
261
332
self .assertEqual (len (spans ), 1 )
262
-
333
+ self . assertIs ( StatusCode . ERROR , spans [ 0 ]. status . status_code )
263
334
self .check_span (spans [0 ])
264
335
self .assertEqual (
265
336
spans [0 ].attributes [SpanAttributes .DB_STATEMENT ], "SELECT 42;"
266
337
)
267
338
self .assertEqual (
268
339
spans [0 ].attributes ["db.statement.parameters" ], "(1, 2, 3)"
269
340
)
341
+
342
+ def test_instrumented_executemany_method_empty_query (self , * _ , ** __ ):
343
+ async_call (self ._connection .executemany ("" , []))
344
+ spans = self .memory_exporter .get_finished_spans ()
345
+ self .assertEqual (len (spans ), 1 )
346
+ self .assertIs (StatusCode .UNSET , spans [0 ].status .status_code )
347
+ self .check_span (spans [0 ])
348
+ self .assertEqual (spans [0 ].name , POSTGRES_DB_NAME )
349
+ self .assertEqual (
350
+ spans [0 ].attributes [SpanAttributes .DB_STATEMENT ], ""
351
+ )
352
+ self .assertEqual (
353
+ spans [0 ].attributes ["db.statement.parameters" ], "([],)"
354
+ )
0 commit comments