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

bugfix(exporter): ensure response is closed #4477

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#4458](https://github.com/open-telemetry/opentelemetry-python/pull/4458))
- pylint-ci updated python version to 3.13
([#4450](https://github.com/open-telemetry/opentelemetry-python/pull/4450))
- Fix intermittent `Connection aborted` error when using otlp/http exporters
([#4477](https://github.com/open-telemetry/opentelemetry-python/pull/4477))

## Version 1.30.0/0.51b0 (2025-02-03)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,12 @@ def export(self, batch: Sequence[LogData]) -> LogExportResult:
resp = self._export(serialized_data)
# pylint: disable=no-else-return
if resp.ok:
if resp.raw is not None:
Copy link
Contributor

@xrmx xrmx Mar 26, 2025

Choose a reason for hiding this comment

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

Do you know if moving this right after getting resp will make resp.ok and self._retryable(resp) change behavior? If not would be nice to do this just once.

Copy link
Contributor

Choose a reason for hiding this comment

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

From a quick test it looks like it should be fine

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for the suggestion, updated the code and tested it locally, seems ok

resp.close()
return LogExportResult.SUCCESS
elif self._retryable(resp):
if resp.raw is not None:
resp.close()
_logger.warning(
"Transient error %s encountered while exporting logs batch, retrying in %ss.",
resp.reason,
Expand All @@ -177,6 +181,8 @@ def export(self, batch: Sequence[LogData]) -> LogExportResult:
sleep(delay)
continue
else:
if resp.raw is not None:
resp.close()
_logger.error(
"Failed to export logs batch code: %s, reason: %s",
resp.status_code,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,12 @@ def export(
resp = self._export(serialized_data.SerializeToString())
# pylint: disable=no-else-return
if resp.ok:
if resp.raw is not None:
resp.close()
return MetricExportResult.SUCCESS
elif self._retryable(resp):
if resp.raw is not None:
resp.close()
_logger.warning(
"Transient error %s encountered while exporting metric batch, retrying in %ss.",
resp.reason,
Expand All @@ -217,6 +221,8 @@ def export(
sleep(delay)
continue
else:
if resp.raw is not None:
resp.close()
_logger.error(
"Failed to export batch code: %s, reason: %s",
resp.status_code,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,12 @@ def _export_serialized_spans(self, serialized_data):
resp = self._export(serialized_data)
# pylint: disable=no-else-return
if resp.ok:
if resp.raw is not None:
resp.close()
return SpanExportResult.SUCCESS
elif self._retryable(resp):
if resp.raw is not None:
resp.close()
_logger.warning(
"Transient error %s encountered while exporting span batch, retrying in %ss.",
resp.reason,
Expand All @@ -169,6 +173,8 @@ def _export_serialized_spans(self, serialized_data):
sleep(delay)
continue
else:
if resp.raw is not None:
resp.close()
_logger.error(
"Failed to export batch code: %s, reason: %s",
resp.status_code,
Expand Down