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

Improve Resource Detector timeout messaging #3645

Merged
merged 8 commits into from
Jan 24, 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- Improve Resource Detector timeout messaging
([#3645](https://github.com/open-telemetry/opentelemetry-python/pull/3645))

## Version 1.22.0/0.43b0 (2023-12-15)

- Prometheus exporter sanitize info metric ([#3572](https://github.com/open-telemetry/opentelemetry-python/pull/3572))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,14 @@ def get_aggregated_resources(
detected_resource: Resource = _EMPTY_RESOURCE
try:
detected_resource = future.result(timeout=timeout)
except concurrent.futures.TimeoutError as ex:
if detector.raise_on_error:
raise ex
logger.warning(
lzchen marked this conversation as resolved.
Show resolved Hide resolved
"Detector %s took longer than %s seconds, skipping",
detector,
timeout,
)
# pylint: disable=broad-except
except Exception as ex:
if detector.raise_on_error:
Expand Down
18 changes: 18 additions & 0 deletions opentelemetry-sdk/tests/resources/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import sys
import unittest
import uuid
from concurrent.futures import TimeoutError
from logging import ERROR, WARNING
from os import environ
from unittest.mock import Mock, patch
Expand Down Expand Up @@ -420,6 +421,23 @@ def test_resource_detector_raise_error(self):
Exception, get_aggregated_resources, [resource_detector]
)

@patch("opentelemetry.sdk.resources.logger")
def test_resource_detector_timeout(self, mock_logger):
resource_detector = Mock(spec=ResourceDetector)
resource_detector.detect.side_effect = TimeoutError()
resource_detector.raise_on_error = False
self.assertEqual(
get_aggregated_resources([resource_detector]),
_DEFAULT_RESOURCE.merge(
Resource({SERVICE_NAME: "unknown_service"}, "")
),
)
mock_logger.warning.assert_called_with(
"Detector %s took longer than %s seconds, skipping",
resource_detector,
5,
)

@patch.dict(
environ,
{"OTEL_RESOURCE_ATTRIBUTES": "key1=env_value1,key2=env_value2"},
Expand Down
Loading