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.

Unable to run on uwsgi

See original GitHub issue

Describe the bug: Middleware not sending data to the server

To Reproduce

  1. Setup a django project (2.0) with python 3.5
  2. Configure elastic-apm: Service name is set, good job!
  • optional SECRET_TOKEN not set

SERVER_URL http://blablabla.com looks fine

DEBUG mode is disabled! Looking good!

Tracing middleware is configured! Awesome!

Looks like everything should be ready!

Expected behavior: Metrics and transactions should be recorded in kibana dashboard. The test (python manage.py test) error is recorded successfully.

Environment (please complete the following information)

  • OS: Ubuntu 16.04
  • Python version: 3.5
  • Framework and version [e.g. Django 2.1]: 2.0
  • APM Server version: 6.7.0
  • Agent version: 4.2.1

Additional context

Add any other context about the problem here.

  • Agent config options

Nothing out of the ordinary. In my settings, a dictionary with SERVER_URL (http) and SERVICE_NAME

- `requirements.txt`:
Click to expand
```

amqp==2.4.2 argon2-cffi==19.1.0 Babel==2.6.0 billiard==3.5.0.5 boto3==1.9.114 botocore==1.12.114 celery==4.2.2 certifi==2019.3.9 cffi==1.12.2 chardet==3.0.4 Collectfast==0.6.2 coreapi==2.3.3 coreschema==0.0.4 defusedxml==0.5.0 Django==2.0.13 django-allauth==0.38.0 django-anymail==5.0 django-crispy-forms==1.7.2 django-environ==0.4.5 django-model-utils==3.1.2 django-redis==4.10.0 django-storages==1.7.1 djangorestframework==3.9.1 docutils==0.14 elastic-apm==4.2.1 flower==0.9.2 gunicorn==19.9.0 idna==2.8 itypes==1.1.0 Jinja2==2.10 jmespath==0.9.4 kombu==4.3.0 MarkupSafe==1.1.1 oauthlib==3.0.1 Pillow==5.4.1 pkg-resources==0.0.0 psutil==5.6.1 psycopg2==2.7.4 pycparser==2.19 python-dateutil==2.8.0 python-slugify==2.0.1 python3-openid==3.1.0 pytz==2018.9 pyzmq==16.0.4 redis==2.10.6 requests==2.21.0 requests-oauthlib==1.2.0 s3transfer==0.2.0 six==1.12.0 tornado==4.5.3 Unidecode==1.0.23 uritemplate==3.0.0 urllib3==1.24.1 vine==1.3.0 ```

Edit: I was able to send data to the apm-server using django’s dev server, so the issue is not there. I am trying to check if there is an issue with uwsgi. I enabled threads, as mentioned in the docs, but still no luck: Thu Mar 28 02:16:41 2019 - Python main interpreter initialized at 0x1f7f750 Thu Mar 28 02:16:41 2019 - python threads support enabled Thu Mar 28 02:16:41 2019 - your server socket listen backlog is limited to 100 connections Thu Mar 28 02:16:41 2019 - your mercy for graceful operations on workers is 60 seconds Thu Mar 28 02:16:41 2019 - mapped 166144 bytes (162 KB) for 2 cores Thu Mar 28 02:16:41 2019 - *** Operational MODE: threaded ***

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jstockwincommented, Feb 18, 2020

I am having the same problem as above (not fixed by installing uwsgidecorators or by lazy-apps=true), which I put down to this issue.

I’ve just redeployed using elastic-apm==5.4.1 (I’m django==1.11.28 and still have lazy-apps=true, enable-threads = true, and single-interpreter = true), but still have the same issue.

I can see only the first few requests to my health-check endpoint in APM, and then nothing. The test error from manage.py gets through fine, as in the original report. I’ll wait for someone else to confirm before re-opening in case it’s me doing something else wrong.

0reactions
ghostcommented, Jan 18, 2021

Just a quick test, follow my…

api.py

app.config[‘ELASTIC_APM’] = { ‘SERVICE_NAME’: __service_name, # ‘SECRET_TOKEN’: ‘’, ‘SERVER_URL’: os.environ.get(‘ELASTIC_APM_URL’, ‘http://localhost:8200’) } apm = ElasticAPM(app)

wsgi.py

import os

from elasticapm.handlers.logging import LoggingHandler from api import app, apm

if name == ‘main’: # Create a logging handler and attach it. handler = LoggingHandler(client=apm.client) # handler.setLevel(logging.WARN) app.logger.addHandler(handler) app.run( host = os.environ.get(“GATEWAYAPI_HOST”, “localhost”), port = os.environ.get(“GATEWAYAPI_PORT”, “5000”), debug = False, threaded = True )

wsgi.ini

[uwsgi] project = gateway_api module = wsgi:app master = true processes = 5 http = 0.0.0.0:5000 die-on-term = true enable-threads = true lazy-apps = true

It works for me! I hope to help someone! =]

Read more comments on GitHub >

github_iconTop Results From Across the Web

unable to start uwsgi with encodings error in uwsgi 2.0.18 and ...
I'm having serious trouble to start uwsgi in django project with nginx. I even tried to run plugins=python36 but still failed.
Read more >
Unable to load configuration from uwsgi - nginx - Server Fault
I am trying to run UWSGI under nginx with a very simple uwsgi.ini file. The file is being pointed to correctly.
Read more >
Quickstart for Python/WSGI applications - uWSGI
Quickstart for Python/WSGI applications¶. This quickstart will show you how to deploy simple WSGI applications and common web frameworks.
Read more >
Managing the uWSGI server - Read the Docs
If you have the uWSGI process running in the foreground for some reason, you can just hit CTRL+C to kill it off. When...
Read more >
Things to know (best practices and “issues”) READ IT - uWSGI
Common sense: do not run uWSGI instances as root. You can start your uWSGIs as root, but be sure to drop privileges with...
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