newrelic / newrelic-python-agent

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

NR cannot instrument tracing with python agent on non-web application #995

Open jonathan-fileread opened 10 months ago

jonathan-fileread commented 10 months ago

Description

Hello! We've setup a python agent in our kubernetes container that runs a worker which polls from a queue.

The dockerfile entrypoint looks something like this -

CMD ["python3", "/app/workerservice"]

We get logs but we do not receive distributed traces.

We have NEW_RELIC_DISTRIBUTED_TRACING_ENABLED set to true in the environment variables.

New relic is injected via our main.py, looking something like this.


import newrelic.agent

newrelic.agent.initialize()

@newrelic.agent.background_task()

async def main():

insert-some-components-here

if __name__ == '__main__':

asyncio.run(main())

Here's our permalink. permalink: https://onenr.io/0EjOoDd18j6

python agent, newrelic==9.1.2 on python,

we ran the CLI diagnostic, but to no avail.

this is also a non-web-app worker we are looking to monitor - there are no frameworks used, just plain python.

Expected Behavior

our goal is to instrument the agent to send distributed traces to the traces directory. we have a lot of dependencies to our worker services that we'd like to monitor.

Troubleshooting or NR Diag results

Steps to Reproduce

Your Environment

hmstepanek commented 9 months ago

If main loops forever and never exits than you need to move the background task decorator into something that has a finite start and end time. We will not record a distributed trace until the thing the background task is wrapping has exited. You may also need to set the startup timeout, startup_timeout = 30 so that the first background task is captured.