fix except handling in get_aggregated_resources by munagekar · Pull Request #2464 · open-telemetry/opentelemetry-python

Minor Fix with exception handling in get_aggregated_resources

Description

Fixes

UnboundLocalError: local variable 'detected_resource' referenced before assignment 

This happen only if raise_on_error is True with a resource detector.

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

Run with and without patch.

from opentelemetry.sdk.resources import ResourceDetector
from opentelemetry.sdk.resources import get_aggregated_resources


class ErrorDetector(ResourceDetector):
    def __init__(self, raise_on_error=False):
        super().__init__(raise_on_error)

    def detect(self):
        raise Exception


get_aggregated_resources([ErrorDetector(raise_on_error=True)])

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Does This PR Require a Contrib Repo Change?

  • No.