Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1763555 update how HTTP headers are requested from OpenTelemetry #2106

Merged
merged 6 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Source code is also available at: https://github.com/snowflakedb/snowflake-conne

- v3.12.4(TBD)
- Fixed a bug where multipart uploads to Azure would be missing their MD5 hashes.
- Fixed a bug where OpenTelemetry header injection would sometimes cause Exceptions to be thrown.

- v3.12.3(October 25,2024)
- Improved the error message for SSL-related issues to provide clearer guidance when an SSL error occurs.
Expand Down
16 changes: 12 additions & 4 deletions src/snowflake/connector/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,11 +481,19 @@ def request(
HTTP_HEADER_USER_AGENT: PYTHON_CONNECTOR_USER_AGENT,
}
try:
from opentelemetry.propagate import inject
# SNOW-1763555: inject OpenTelemetry headers if available specifically in WC3 format
# into our request headers in case tracing is enabled. This should make sure that
# our requests are accounted for properly if OpenTelemetry is used by users.
from opentelemetry.trace.propagation.tracecontext import (
TraceContextTextMapPropagator,
)

inject(headers)
except ModuleNotFoundError as e:
logger.debug(f"Opentelemtry otel injection failed because of: {e}")
TraceContextTextMapPropagator().inject(headers)
except Exception:
logger.debug(
"Opentelemtry otel injection failed",
exc_info=True,
)
sfc-gh-mkeller marked this conversation as resolved.
Show resolved Hide resolved
if self._connection.service_name:
headers[HTTP_HEADER_SERVICE_NAME] = self._connection.service_name
if method == "post":
Expand Down
16 changes: 16 additions & 0 deletions test/unit/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,3 +572,19 @@ def test_ssl_error_hint(caplog):
exc.value, OperationalError
)
assert "SSL error" in caplog.text and _CONNECTIVITY_ERR_MSG in caplog.text


def test_otel_error_message(caplog, mock_post_requests):
"""This test assumes that OpenTelemetry is not installed when tests are running."""
with mock.patch("snowflake.connector.network.SnowflakeRestful._post_request"):
with caplog.at_level(logging.DEBUG):
with fake_connector():
...
assert caplog.records
important_records = [
record
for record in caplog.records
if "Opentelemtry otel injection failed" in record.message
]
assert len(important_records) == 1
assert important_records[0].exc_text is not None
Loading