File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed
opentelemetry-instrumentation
src/opentelemetry/instrumentation Expand file tree Collapse file tree 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:
2222 """
2323 meta .update (** _add_framework_tags ())
2424 comment = _generate_sql_comment (** meta )
25+ # converting to str to handle any type errors
26+ sql = str (sql )
2527 sql = sql .rstrip ()
2628 if sql [- 1 ] == ";" :
2729 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):
208208
209209 self .assertEqual (commented_sql_without_semicolon , "Select 1" )
210210
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+
211226 def test_is_instrumentation_enabled_by_default (self ):
212227 self .assertTrue (is_instrumentation_enabled ())
213228 self .assertTrue (is_http_instrumentation_enabled ())
You can’t perform that action at this time.
0 commit comments