File tree Expand file tree Collapse file tree 3 files changed +29
-4
lines changed Expand file tree Collapse file tree 3 files changed +29
-4
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ Source code is also available at: https://github.com/snowflakedb/snowflake-conne
10
10
11
11
- v3.12.4(TBD)
12
12
- Fixed a bug where multipart uploads to Azure would be missing their MD5 hashes.
13
+ - Fixed a bug where OpenTelemetry header injection would sometimes cause Exceptions to be thrown.
13
14
14
15
- v3.12.3(October 25,2024)
15
16
- Improved the error message for SSL-related issues to provide clearer guidance when an SSL error occurs.
Original file line number Diff line number Diff line change @@ -481,11 +481,19 @@ def request(
481
481
HTTP_HEADER_USER_AGENT : PYTHON_CONNECTOR_USER_AGENT ,
482
482
}
483
483
try :
484
- from opentelemetry .propagate import inject
484
+ # SNOW-1763555: inject OpenTelemetry headers if available specifically in WC3 format
485
+ # into our request headers in case tracing is enabled. This should make sure that
486
+ # our requests are accounted for properly if OpenTelemetry is used by users.
487
+ from opentelemetry .trace .propagation .tracecontext import (
488
+ TraceContextTextMapPropagator ,
489
+ )
485
490
486
- inject (headers )
487
- except ModuleNotFoundError as e :
488
- logger .debug (f"Opentelemtry otel injection failed because of: { e } " )
491
+ TraceContextTextMapPropagator ().inject (headers )
492
+ except Exception :
493
+ logger .debug (
494
+ "Opentelemtry otel injection failed" ,
495
+ exc_info = True ,
496
+ )
489
497
if self ._connection .service_name :
490
498
headers [HTTP_HEADER_SERVICE_NAME ] = self ._connection .service_name
491
499
if method == "post" :
Original file line number Diff line number Diff line change @@ -572,3 +572,19 @@ def test_ssl_error_hint(caplog):
572
572
exc .value , OperationalError
573
573
)
574
574
assert "SSL error" in caplog .text and _CONNECTIVITY_ERR_MSG in caplog .text
575
+
576
+
577
+ def test_otel_error_message (caplog , mock_post_requests ):
578
+ """This test assumes that OpenTelemetry is not installed when tests are running."""
579
+ with mock .patch ("snowflake.connector.network.SnowflakeRestful._post_request" ):
580
+ with caplog .at_level (logging .DEBUG ):
581
+ with fake_connector ():
582
+ ...
583
+ assert caplog .records
584
+ important_records = [
585
+ record
586
+ for record in caplog .records
587
+ if "Opentelemtry otel injection failed" in record .message
588
+ ]
589
+ assert len (important_records ) == 1
590
+ assert important_records [0 ].exc_text is not None
You can’t perform that action at this time.
0 commit comments