File tree Expand file tree Collapse file tree 3 files changed +31
-1
lines changed
instrumentation/opentelemetry-instrumentation-django/tests
opentelemetry-instrumentation/src/opentelemetry/instrumentation Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4646 ([ #3249 ] ( https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3249 ) )
4747- ` opentelemetry-instrumentation-asyncpg ` Fix fallback for empty queries.
4848 ([ #3253 ] ( https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3253 ) )
49+ - ` opentelemetry-instrumentation ` Fix a traceback in sqlcommenter when psycopg connection pooling is enabled.
50+ ([ #3309 ] ( https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3309 ) )
4951- ` opentelemetry-instrumentation-threading ` Fix broken context typehints
5052 ([ #3322 ] ( https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3322 ) )
5153- ` opentelemetry-instrumentation-requests ` always record span status code in duration metric
Original file line number Diff line number Diff line change @@ -146,3 +146,31 @@ def test_multiple_connection_support(self, query_wrapper):
146146
147147 # check if query_wrapper is added to the context for 2 databases
148148 self .assertEqual (query_wrapper .call_count , 2 )
149+
150+ @patch (
151+ "opentelemetry.instrumentation.django.middleware.sqlcommenter_middleware._get_opentelemetry_values"
152+ )
153+ def test_empty_sql (self , trace_capture ):
154+ requests_mock = MagicMock ()
155+ requests_mock .resolver_match .view_name = "view"
156+ requests_mock .resolver_match .route = "route"
157+ requests_mock .resolver_match .app_name = "app"
158+
159+ trace_capture .return_value = {
160+ "traceparent" : "*traceparent='00-000000000000000000000000deadbeef-000000000000beef-00"
161+ }
162+ qw_instance = _QueryWrapper (requests_mock )
163+ execute_mock_obj = MagicMock ()
164+ qw_instance (
165+ execute_mock_obj ,
166+ "" ,
167+ MagicMock ("test" ),
168+ MagicMock ("test1" ),
169+ MagicMock (),
170+ )
171+ output_sql = execute_mock_obj .call_args [0 ][0 ]
172+ self .assertEqual (
173+ output_sql ,
174+ " /*app_name='app',controller='view',route='route',traceparent='%%2Atraceparent%%3D%%2700-0000000"
175+ "00000000000000000deadbeef-000000000000beef-00'*/" ,
176+ )
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ def _add_sql_comment(sql, **meta) -> str:
2323 meta .update (** _add_framework_tags ())
2424 comment = _generate_sql_comment (** meta )
2525 sql = sql .rstrip ()
26- if sql [ - 1 ] == ";" :
26+ if sql . endswith ( ";" ) :
2727 sql = sql [:- 1 ] + comment + ";"
2828 else :
2929 sql = sql + comment
You can’t perform that action at this time.
0 commit comments