Skip to content
Open
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
3 changes: 2 additions & 1 deletion src/snowflake/connector/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,8 @@ def close(self, retry: bool = True) -> None:

# close telemetry first, since it needs rest to send remaining data
logger.debug("closed")
self._telemetry.close(send_on_close=bool(retry and self.telemetry_enabled))
if self.telemetry_enabled:
self._telemetry.close(retry=retry)
if (
self._all_async_queries_finished()
and not self._server_session_keep_alive
Expand Down
8 changes: 4 additions & 4 deletions src/snowflake/connector/telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def try_add_log_to_batch(self, telemetry_data: TelemetryData) -> None:
except Exception:
logger.warning("Failed to add log to telemetry.", exc_info=True)

def send_batch(self) -> None:
def send_batch(self, retry: bool = False) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to add tests - to make sure no additional requests are done if retry is False - e.g. using Wiremock or simpler mocks?

if self.is_closed:
raise Exception("Attempted to send batch when TelemetryClient is closed")
elif not self._enabled:
Expand Down Expand Up @@ -186,6 +186,7 @@ def send_batch(self) -> None:
method="post",
client=None,
timeout=5,
_no_retry=not retry,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to investigate if the underlying requests library won't execute its built in requests in this case? I think by default there is 1, but we decreased it to 0 for e.g. platform detection.

Fyi HttpConfig can propagate max_retries option there.

)
if not ret["success"]:
logger.info(
Expand All @@ -204,11 +205,10 @@ def send_batch(self) -> None:
def is_closed(self) -> bool:
return self._rest is None

def close(self, send_on_close: bool = True) -> None:
def close(self, retry: bool = False) -> None:
if not self.is_closed:
logger.debug("Closing telemetry client.")
if send_on_close:
self.send_batch()
self.send_batch(retry=retry)
self._rest = None

def disable(self) -> None:
Expand Down
Loading