File tree 3 files changed +31
-1
lines changed
instrumentation/opentelemetry-instrumentation-django/tests
opentelemetry-instrumentation/src/opentelemetry/instrumentation
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
46
46
([ #3249 ] ( https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3249 ) )
47
47
- ` opentelemetry-instrumentation-asyncpg ` Fix fallback for empty queries.
48
48
([ #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 ) )
49
51
- ` opentelemetry-instrumentation-threading ` Fix broken context typehints
50
52
([ #3322 ] ( https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3322 ) )
51
53
- ` 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):
146
146
147
147
# check if query_wrapper is added to the context for 2 databases
148
148
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:
23
23
meta .update (** _add_framework_tags ())
24
24
comment = _generate_sql_comment (** meta )
25
25
sql = sql .rstrip ()
26
- if sql [ - 1 ] == ";" :
26
+ if sql . endswith ( ";" ) :
27
27
sql = sql [:- 1 ] + comment + ";"
28
28
else :
29
29
sql = sql + comment
You can’t perform that action at this time.
0 commit comments