File tree Expand file tree Collapse file tree 2 files changed +28
-4
lines changed
src/snowflake/connector/aio Expand file tree Collapse file tree 2 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -217,11 +217,19 @@ async def request(
217
217
HTTP_HEADER_USER_AGENT : PYTHON_CONNECTOR_USER_AGENT ,
218
218
}
219
219
try :
220
- from opentelemetry .propagate import inject
220
+ # SNOW-1763555: inject OpenTelemetry headers if available specifically in WC3 format
221
+ # into our request headers in case tracing is enabled. This should make sure that
222
+ # our requests are accounted for properly if OpenTelemetry is used by users.
223
+ from opentelemetry .trace .propagation .tracecontext import (
224
+ TraceContextTextMapPropagator ,
225
+ )
221
226
222
- inject (headers )
223
- except ModuleNotFoundError as e :
224
- logger .debug (f"Opentelemtry otel injection failed because of: { e } " )
227
+ TraceContextTextMapPropagator ().inject (headers )
228
+ except Exception :
229
+ logger .debug (
230
+ "Opentelemtry otel injection failed" ,
231
+ exc_info = True ,
232
+ )
225
233
if self ._connection .service_name :
226
234
headers [HTTP_HEADER_SERVICE_NAME ] = self ._connection .service_name
227
235
if method == "post" :
Original file line number Diff line number Diff line change @@ -551,3 +551,19 @@ async def test_ssl_error_hint(caplog):
551
551
exc .value , OperationalError
552
552
)
553
553
assert "SSL error" in caplog .text and _CONNECTIVITY_ERR_MSG in caplog .text
554
+
555
+
556
+ async def test_otel_error_message_async (caplog , mock_post_requests ):
557
+ """This test assumes that OpenTelemetry is not installed when tests are running."""
558
+ with mock .patch ("snowflake.connector.aio._network.SnowflakeRestful._post_request" ):
559
+ with caplog .at_level (logging .DEBUG ):
560
+ async with fake_connector ():
561
+ ...
562
+ assert caplog .records
563
+ important_records = [
564
+ record
565
+ for record in caplog .records
566
+ if "Opentelemtry otel injection failed" in record .message
567
+ ]
568
+ assert len (important_records ) == 1
569
+ assert important_records [0 ].exc_text is not None
You can’t perform that action at this time.
0 commit comments