Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydvoss committed Jan 22, 2024
1 parent de1a9e8 commit 500d2bc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
3 changes: 0 additions & 3 deletions opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,6 @@ def get_aggregated_resources(
logger.warning(
"Exception %s in detector %s, ignoring", ex, detector
)
print(
"Exception %s in detector %s, ignoring" % (ex, detector)
)
finally:
detectors_merged_resource = detectors_merged_resource.merge(
detected_resource
Expand Down
18 changes: 16 additions & 2 deletions opentelemetry-sdk/tests/resources/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import concurrent.futures
import os
import sys
import unittest
Expand Down Expand Up @@ -412,13 +413,26 @@ def test_resource_detector_ignore_error(self):
),
)

def test_resource_detector_raise_error(self):
@patch("opentelemetry.sdk.resources.logger")
def test_resource_detector_raise_error(self, mock_logger):
resource_detector = Mock(spec=ResourceDetector)
resource_detector.detect.side_effect = Exception()
ex = Exception()
resource_detector.detect.side_effect = ex
resource_detector.raise_on_error = True
self.assertRaises(
Exception, get_aggregated_resources, [resource_detector]
)
mock_logger.warning.assert_called_with("Exception %s in detector %s, ignoring", ex, 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 = concurrent.futures._base.TimeoutError()
resource_detector.raise_on_error = True
self.assertRaises(
Exception, get_aggregated_resources, [resource_detector]
)
mock_logger.warning.assert_called_with("Detector %s took longer than %s seconds, skipping", resource_detector, 5)

@patch.dict(
environ,
Expand Down

0 comments on commit 500d2bc

Please sign in to comment.