question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

APM agent not sending event requests to the APM server with gunicorn wsgi.

See original GitHub issue

I’m running a flask application and everything works fine if I’m running the application in dev environment i.e. directly from command line or my IDE aka Pycharm.

But when I run the same app on production via gunicorn, it only sends agents requests and no events requests so in APM in kibana, no service shows up.

Reproduction steps:

  1. Create a basic flask app and call client.begin_transaction and client.end_transaction before and after each request so as to log time of each request.
  2. Run the app via gunicorn.
  3. Make a request to the app via browser or postman.

Expected behavior:

The apm server logs show /intake/v2/events requests as well as /config/v1/agents request.

Environment/

  • OS: macOS
  • Python version: 3.5
  • Framework and version: Flask 1.0.2
  • Elasticsearch version: 7.4.1
  • Kibana version: 7.4.1
  • APM Server version: 7.4.1
  • Agent version: 5.2.2

Additional context

I’m running Elasticsearch on 0.0.0.0:9200, Kibana on 0.0.0.0:5601, and APM on 0.0.0.0.8200.

A curl request to all these shows the desired result.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
basepicommented, Dec 9, 2019

Thanks for the update. Forking models for concurrency have long given the agent issues, as we lose the background threads on fork. Rather than trying to come up with a solution for each implementation, we’re going to focus on #636 so that we will automatically detect forks and re-create those background threads. This should fix the majority of issues like this one.

1reaction
wodCZcommented, Jan 14, 2020

I can confirm that disabling preloading in gunicorn fixes the issue - transactions are now properly saved.

We’re using this docker CMD with no configuration file:

CMD ["gunicorn", "--bind", ":8000", "--worker-tmp-dir", "/dev/shm/", "--workers", "2", "--threads", "4", "--worker-class", "eventlet", "--log-file", "-", "project.wsgi"]

I also had to switch the transaction type to request in the APM UI: image

Read more comments on GitHub >

github_iconTop Results From Across the Web

APM not showing data in Kibana when running app ...
No data is being shown in Kibana UI or APM server logs if I run the app in production using gunicorn WSGI but...
Read more >
Python agent not uploading data from gunicorn. ...
I'm curious to know if you have the app actually connected to the APM? If not, you might want to check this portion...
Read more >
django - Elastic Apm python agent connection problem
On my APM server, I'm not receiving any requests from my agent. I checked the APM server log files. django · elasticsearch ·...
Read more >
NGINX 502 Bad Gateway: Gunicorn
NGINX will return a 502 Bad Gateway error if it can't successfully proxy a request to Gunicorn or if Gunicorn fails to respond....
Read more >
Advanced Usage — ddtrace documentation - Read the Docs
If the Datadog Agent is on a separate host from your application, you can modify the default ddtrace.tracer object to utilize another hostname...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found