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(async-io): check for __name__ attribute when tracing coroutine #2521

Merged
merged 1 commit into from
May 22, 2024

Conversation

povilasv
Copy link
Contributor

@povilasv povilasv commented May 13, 2024

Description

This PR takes over stale PR #2353.

Basically we need to check if coroutine has name attribute before trying to trace, as not all coroutines have this attribute. More details are in the issue.

I've applied suggestions from @xrmx comment in here #2353 (review)

Fixes #2340

Type of change

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

How Has This Been Tested?

Added unit test. Ran the test without the fix and it fails with the following error:

self = <opentelemetry.instrumentation.asyncio.AsyncioInstrumentor object at 0x79c618a75d60>
coro = <async_generator_asend object at 0x79c618a6d0c0>

    async def trace_coroutine(self, coro):
        start = default_timer()

        attr = {
            "type": "coroutine",
>           "name": coro.__name__,
        }
E       AttributeError: 'async_generator_asend' object has no attribute '__name__'. Did you mean: '__ne__'?

instrumentation/opentelemetry-instrumentation-asyncio/src/opentelemetry/instrumentation/asyncio/__init__.py:268: AttributeError

With the fix the unit test passes.

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

@povilasv povilasv force-pushed the fix-coroutine-name branch 7 times, most recently from 7c8f5f7 to 5f0a3ed Compare May 13, 2024 09:21
@povilasv povilasv marked this pull request as ready for review May 13, 2024 09:29
@povilasv povilasv requested a review from a team as a code owner May 13, 2024 09:29
@povilasv povilasv changed the title fix(async-io): check for __name__ atribute when tracing coroutine fix(async-io): check for __name__ attribute when tracing coroutine May 13, 2024
@xrmx
Copy link
Contributor

xrmx commented May 14, 2024

@povilasv please fix conflicts

@povilasv
Copy link
Contributor Author

@xrmx done 👍

@povilasv
Copy link
Contributor Author

Anything I can do to help move this forward? Would appreciate if this would make it to next release 🙇

@aabmass
Copy link
Member

aabmass commented May 20, 2024

Thanks for the fix!

@lzchen lzchen merged commit f4f3042 into open-telemetry:main May 22, 2024
314 checks passed
@povilasv povilasv deleted the fix-coroutine-name branch May 22, 2024 07:13
@@ -261,6 +261,8 @@ def trace_item(self, coro_or_future):
return coro_or_future

async def trace_coroutine(self, coro):
if not hasattr(coro, "__name__"):
return
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't return coro here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, wip -> #2541

somehow demo app (python anext.py) works in both cases 🤔

shadchin pushed a commit to shadchin/opentelemetry-python-contrib that referenced this pull request May 29, 2024
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.

AttributeError: 'async_generator_asend' object has no attribute '__name__'
4 participants