newrelic / newrelic-python-agent

New Relic Python Agent
https://docs.newrelic.com/docs/agents/python-agent
Apache License 2.0
175 stars 99 forks source link

Fast API Websocket coroutines throw attribute error when run with newrelic admin #742

Open sankarpa opened 1 year ago

sankarpa commented 1 year ago

Description I am using newrelic agent 8.5.0 with my fastapi which houses both rest and websocket apis. The app get deployed in kubernetes and here is how the container command looks like

   containers:
        - name: a-service
          image: 'a-service:latest'
          command:
            - newrelic-admin
            - run-program
            - uvicorn
            - app.main:app
            - --port=8000
            - --host=0.0.0.0
          resources:
            requests:
              memory: "512Mi"
              cpu: "500m"
            limits:
              memory: "512Mi"
              cpu: "500m"
          ports:
            - containerPort: 8000
              protocol: TCP

The container comes up healthy and runs , but the coroutines throws error with attribute not found error when calling async functions. The same is working fine when i run the container without newrelic-admin

TimPansino commented 1 year ago

Hello,

Could you perhaps supply a reproduction or at least some more specifics?

I was unable to reproduce any issue with the latest version of the agent. FastAPI has a minimalist example that I ran some testing against. I was using an async websocket endpoint and both sync and async HTTP routes were working alongside it with no issues.

Ak-x commented 1 year ago

Hello @sankarpa, without reproduction steps we will close this ticket in 30 days.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

sankarpa commented 1 year ago

Hi @Ak-x @TimPansino Sorry for responding late, I am using aioredis pubsub in the websocket functions and the code looks like below.

pubsub = redis.pubsub()       
await pubsub.subscribe(f"{channel_id}")
await websocket.accept()

if I don't use newrelic agent , the subscribe function call works fine .

I get below error if I initialise the newrelic agent and connect to the websocket

AttributeError: 'coroutine' object has no attribute 'subscribe'
sankarpa commented 1 year ago

@TimPansino Any updates on this?