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

Handle null statuses in http_status_to_status_code #823

Merged
merged 5 commits into from
Feb 2, 2022

Conversation

gregbuehler
Copy link
Contributor

@gregbuehler gregbuehler commented Dec 3, 2021

Description

This handles None statuses passed to the http_status_to_status_code utility function. This treats None statuses as StatusCode.UNSET.

Fixes #820

Type of change

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

How Has This Been Tested?

This adds new unit tests.

  • None status codes are interpreted as StatusCode.UNSET.

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

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

@gregbuehler gregbuehler requested a review from a team December 3, 2021 18:18
@linux-foundation-easycla
Copy link

CLA Not Signed

@@ -46,6 +46,8 @@ def http_status_to_status_code(
status (int): HTTP status code
"""
# See: https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/semantic_conventions/http.md#status
if status is None:
return StatusCode.UNSET
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure about encoding knowledge about a special case in this function. IMO we should either have a isinstance(status, int) check or wrap in a try/except block to cover all cases of invalid input

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed.

Would it also make sense to also try to coerce status to an integer in case the status was passed as a string representation while we're looking at this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure about that. We don't necessarily want to work with a wide range of inputs. We just don't ever want to crash. I think the caller should be responsible for converting types.

Copy link
Member

Choose a reason for hiding this comment

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

Is this something common with other http client libraries as well? I personally prefer not to have the input sanitisation part here. And the caller would have the more context when the status is unusual and it can decide to what to do instead of we returning the UNSET here for all such scenarios.

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we should just include the check only for this specific instrumentation.

@linux-foundation-easycla
Copy link

CLA Not Signed

@lzchen
Copy link
Contributor

lzchen commented Dec 7, 2021

@gregbuehler
Please sign the CLA

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jan 11, 2022

CLA Not Signed

@ocelotl
Copy link
Contributor

ocelotl commented Jan 18, 2022

@gregbuehler please fix the lint issues.

Only your latest commit shows the "verified" label. I wonder if that is why the CLA check is not passing. Maybe merging them all in all in one single commit will make this test pass?

@owais owais enabled auto-merge (squash) January 31, 2022 23:42
auto-merge was automatically disabled February 1, 2022 21:20

Head branch was pushed to by a user without write access

@lzchen lzchen merged commit 0e55341 into open-telemetry:main Feb 2, 2022
@gregbuehler gregbuehler deleted the urllib-none-status branch February 2, 2022 19:04
@saez0pub
Copy link

Hello,

Do you know when this fix will be included in a release ?

Thanks

@lzchen
Copy link
Contributor

lzchen commented Feb 22, 2022

@saez0pub
We release on a monthly cadence so this release will probably go out some time next week.

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.

urllib instrumentation fails for local file access
7 participants