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

Redis async client breaks when instrumented #818

Closed
marcoaaguiar opened this issue May 25, 2023 · 4 comments
Closed

Redis async client breaks when instrumented #818

marcoaaguiar opened this issue May 25, 2023 · 4 comments

Comments

@marcoaaguiar
Copy link

Description
When I run my code with NR auto instrumentation it wraps redis.asyncio.client.RedisClient.pubsub with an async wrapper which causes an error when I try to invoke a __aenter__ on the object.

Expected Behavior
A regular sync wrapper should have been used to not change the library default behavior.

**Troubleshooting or [NR Diag]
client.subrcibe() => <coroutine object _wrap_AioRedis_method_wrapper.<locals>._nr_wrapper_AioRedis_async_method_ at 0x7fefca629e00>

error on `async with pubsub:

Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/strawberry/subscriptions/protocols/graphql_ws/handlers.py", line 168, in handle_async_results
    async for result in result_source:
File "/usr/local/lib/python3.10/site-packages/graphql/execution/map_async_iterator.py", line 59, in __anext__
    raise error
File "/app/src/schemas/subscription/subscription.py", line 30, in function_name1
    async for message in controller.subscribe_to_updates(
File "/app/src/*internal_path*", line 69, in subscribe_to_updates
    async for message in self.redis_adapter.listen(
File "/app/src/*internal_path*/redis_adapter.py", line 53, in listen
    async with pubsub:
AttributeError: __aenter__

Steps to Reproduce

from redis.asyncio import Redis

async_redis = Redis.from_url(REDIS_URL)

async def redis_test():
    pubsub = async_redis.pubsub()
    async with pubsub:
        pass

Your Environment

newrelic = "^8.8.0"
fastapi = "^0.83.0"
PyJWT = "^2.3.0"
gunicorn = "^20.1.0"
uvicorn = {extras = ["standard"], version = "^0.22.0"}
strawberry-graphql = "^0.178.0"
redis = "^4.5.5"
hiredis = "^2.2.3"
httpx = "^0.23.0"
geopy = "^2.2.0"
pydantic = "^1.10.6"

Additional context
Similar issues have been posted before. #623 was closed but there is still other open (#782, #807) - including PR that might solve this issue (#782, #808).

Unfortunately we will have to disable NR while this is not solved leaving an unmonitored application.

@drewbrew
Copy link

I just wanted to confirm that this breaks channels if you're using the pubsub channel layer with async consumers.

@marcoaaguiar
Copy link
Author

@drewbrew I didn't see you message, but most likely it will break it. I'll try to downgrade to 8.5.0 as you mentioned in the other issue

@drewbrew
Copy link

Thanks, @marcoaaguiar. I can confirm we've been using 8.5.0 in production with no trouble for the past two weeks and change.

@lrafeei
Copy link
Contributor

lrafeei commented Aug 14, 2023

The latest release of the agent should have a fix for this issue. If this is still an issue for you with the latest version (v8.10.0), we can reopen this ticket

@lrafeei lrafeei closed this as completed Aug 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants