File tree 2 files changed +17
-0
lines changed
opentelemetry-instrumentation
src/opentelemetry/instrumentation
2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,8 @@ def _add_sql_comment(sql, **meta) -> str:
22
22
"""
23
23
meta .update (** _add_framework_tags ())
24
24
comment = _generate_sql_comment (** meta )
25
+ # converting to str to handle any type errors
26
+ sql = str (sql )
25
27
sql = sql .rstrip ()
26
28
if sql [- 1 ] == ";" :
27
29
sql = sql [:- 1 ] + comment + ";"
Original file line number Diff line number Diff line change @@ -208,6 +208,21 @@ def test_add_sql_comments_without_comments(self):
208
208
209
209
self .assertEqual (commented_sql_without_semicolon , "Select 1" )
210
210
211
+ def test_psycopg2_sql_composable (self ):
212
+ """Test handling of psycopg2.sql.Composable input"""
213
+ # Mock psycopg2.sql.Composable object
214
+ class MockComposable :
215
+ def __str__ (self ):
216
+ return "SELECT * FROM table_name"
217
+
218
+ sql_query = MockComposable ()
219
+ comments = {"trace_id" : "abc123" }
220
+
221
+ result = _add_sql_comment (sql_query , ** comments )
222
+ expected = "SELECT * FROM table_name /*trace_id='abc123'*/"
223
+
224
+ self .assertEqual (result , expected )
225
+
211
226
def test_is_instrumentation_enabled_by_default (self ):
212
227
self .assertTrue (is_instrumentation_enabled ())
213
228
self .assertTrue (is_http_instrumentation_enabled ())
You can’t perform that action at this time.
0 commit comments