Skip to content

Commit

Permalink
feat: include endpoint in grpc logs (#3362)
Browse files Browse the repository at this point in the history
Co-authored-by: Srikanth Chekuri <srikanth.chekuri92@gmail.com>
  • Loading branch information
sk- and srikanthccv committed Jul 5, 2023
1 parent 84357bf commit 570d27e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#3341](https://github.com/open-telemetry/opentelemetry-python/pull/3341))
- Upgrade opentelemetry-proto to 0.20 and regen
[#3355](https://github.com/open-telemetry/opentelemetry-python/pull/3355))
- Include endpoint in Grpc transient error warning
[#3362](https://github.com/open-telemetry/opentelemetry-python/pull/3362))

## Version 1.18.0/0.39b0 (2023-05-04)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,11 @@ def __init__(
):
super().__init__()

endpoint = endpoint or environ.get(
self._endpoint = endpoint or environ.get(
OTEL_EXPORTER_OTLP_ENDPOINT, "http://localhost:4317"
)

parsed_url = urlparse(endpoint)
parsed_url = urlparse(self._endpoint)

if parsed_url.scheme == "https":
insecure = False
Expand All @@ -197,7 +197,7 @@ def __init__(
insecure = False

if parsed_url.netloc:
endpoint = parsed_url.netloc
self._endpoint = parsed_url.netloc

self._headers = headers or environ.get(OTEL_EXPORTER_OTLP_HEADERS)
if isinstance(self._headers, str):
Expand All @@ -223,14 +223,16 @@ def __init__(

if insecure:
self._client = self._stub(
insecure_channel(endpoint, compression=compression)
insecure_channel(self._endpoint, compression=compression)
)
else:
credentials = _get_credentials(
credentials, OTEL_EXPORTER_OTLP_CERTIFICATE
)
self._client = self._stub(
secure_channel(endpoint, credentials, compression=compression)
secure_channel(
self._endpoint, credentials, compression=compression
)
)

self._export_lock = threading.Lock()
Expand Down Expand Up @@ -304,18 +306,20 @@ def _export(
logger.warning(
(
"Transient error %s encountered while exporting "
"%s, retrying in %ss."
"%s to %s, retrying in %ss."
),
error.code(),
self._exporting,
self._endpoint,
delay,
)
sleep(delay)
continue
else:
logger.error(
"Failed to export %s, error code: %s",
"Failed to export %s to %s, error code: %s",
self._exporting,
self._endpoint,
error.code(),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def _exporting(self) -> str:
otlp_mock_exporter._export(Mock())
self.assertEqual(
warning.records[0].message,
"Failed to export mock, error code: None",
"Failed to export mock to localhost:4317, error code: None",
)

def code(self): # pylint: disable=function-redefined
Expand All @@ -112,7 +112,7 @@ def trailing_metadata(self):
warning.records[0].message,
(
"Transient error StatusCode.CANCELLED encountered "
"while exporting mock, retrying in 0s."
"while exporting mock to localhost:4317, retrying in 0s."
),
)

Expand Down

0 comments on commit 570d27e

Please sign in to comment.