Skip to content

Commit

Permalink
Merge branch 'main' into loosen-responses
Browse files Browse the repository at this point in the history
  • Loading branch information
ocelotl authored Jan 25, 2024
2 parents d8a8cb0 + 8b262d3 commit 56ce7f2
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
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
2 changes: 0 additions & 2 deletions docs/examples/opencensus-exporter-tracer/collector.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python3
#
# Copyright The OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
8 changes: 8 additions & 0 deletions opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py
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(
"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
2 changes: 0 additions & 2 deletions tests/w3c_tracecontext_validation_server.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#!/usr/bin/env python3
#
# Copyright The OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand Down

0 comments on commit 56ce7f2

Please sign in to comment.