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 @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#4494](https://github.com/open-telemetry/opentelemetry-python/pull/4494))
- Improve CI by cancelling stale runs and setting timeouts
([#4498](https://github.com/open-telemetry/opentelemetry-python/pull/4498))
- Fix intermittent `Connection aborted` error when using otlp/http exporters
([#4477](https://github.com/open-telemetry/opentelemetry-python/pull/4477))

## Version 1.31.0/0.52b0 (2025-03-12)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from typing import Dict, Optional, Sequence

import requests
from requests.exceptions import ConnectionError

from opentelemetry.exporter.otlp.proto.common._internal import (
_create_exp_backoff_generator,
Expand Down Expand Up @@ -133,13 +134,27 @@ def _export(self, serialized_data: bytes):
elif self._compression == Compression.Deflate:
data = zlib.compress(serialized_data)

return self._session.post(
url=self._endpoint,
data=data,
verify=self._certificate_file,
timeout=self._timeout,
cert=self._client_cert,
)
# By default, keep-alive is enabled in Session's request
# headers. Backends may choose to close the connection
# while a post happens which causes an unhandled
# exception. This try/except will retry the post on such exceptions
try:
resp = self._session.post(
url=self._endpoint,
data=data,
verify=self._certificate_file,
timeout=self._timeout,
cert=self._client_cert,
)
except ConnectionError:
resp = self._session.post(
url=self._endpoint,
data=data,
verify=self._certificate_file,
timeout=self._timeout,
cert=self._client_cert,
)
return resp

@staticmethod
def _retryable(resp: requests.Response) -> bool:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import requests
from deprecated import deprecated
from requests.exceptions import ConnectionError

from opentelemetry.exporter.otlp.proto.common._internal import (
_create_exp_backoff_generator,
Expand Down Expand Up @@ -175,13 +176,27 @@ def _export(self, serialized_data: bytes):
elif self._compression == Compression.Deflate:
data = zlib.compress(serialized_data)

return self._session.post(
url=self._endpoint,
data=data,
verify=self._certificate_file,
timeout=self._timeout,
cert=self._client_cert,
)
# By default, keep-alive is enabled in Session's request
# headers. Backends may choose to close the connection
# while a post happens which causes an unhandled
# exception. This try/except will retry the post on such exceptions
try:
resp = self._session.post(
url=self._endpoint,
data=data,
verify=self._certificate_file,
timeout=self._timeout,
cert=self._client_cert,
)
except ConnectionError:
resp = self._session.post(
url=self._endpoint,
data=data,
verify=self._certificate_file,
timeout=self._timeout,
cert=self._client_cert,
)
return resp

@staticmethod
def _retryable(resp: requests.Response) -> bool:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from typing import Dict, Optional

import requests
from requests.exceptions import ConnectionError

from opentelemetry.exporter.otlp.proto.common._internal import (
_create_exp_backoff_generator,
Expand Down Expand Up @@ -130,13 +131,27 @@ def _export(self, serialized_data: bytes):
elif self._compression == Compression.Deflate:
data = zlib.compress(serialized_data)

return self._session.post(
url=self._endpoint,
data=data,
verify=self._certificate_file,
timeout=self._timeout,
cert=self._client_cert,
)
# By default, keep-alive is enabled in Session's request
# headers. Backends may choose to close the connection
# while a post happens which causes an unhandled
# exception. This try/except will retry the post on such exceptions
try:
resp = self._session.post(
url=self._endpoint,
data=data,
verify=self._certificate_file,
timeout=self._timeout,
cert=self._client_cert,
)
except ConnectionError:
resp = self._session.post(
url=self._endpoint,
data=data,
verify=self._certificate_file,
timeout=self._timeout,
cert=self._client_cert,
)
return resp

@staticmethod
def _retryable(resp: requests.Response) -> bool:
Expand Down