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

fix except handling in get_aggregated_resources #2464

Merged
merged 4 commits into from
Feb 22, 2022
Merged

fix except handling in get_aggregated_resources #2464

merged 4 commits into from
Feb 22, 2022

Conversation

munagekar
Copy link
Contributor

@munagekar munagekar commented Feb 17, 2022

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.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Feb 17, 2022

CLA Signed

The committers are authorized under a signed CLA.

@munagekar munagekar marked this pull request as ready for review February 17, 2022 08:59
@munagekar munagekar requested a review from a team February 17, 2022 08:59
@munagekar munagekar marked this pull request as draft February 17, 2022 09:00
@munagekar munagekar marked this pull request as ready for review February 17, 2022 09:10
Avoids UnboundLocalError: local variable 'detected_resource' referenced before assignment if raise_on_error is True
Copy link
Member

@srikanthccv srikanthccv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@lzchen lzchen merged commit 50413be into open-telemetry:main Feb 22, 2022
@munagekar munagekar deleted the patch-1 branch February 22, 2022 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants