Giter Site home page Giter Site logo

moesif / moesifdjango Goto Github PK

View Code? Open in Web Editor NEW
12.0 12.0 9.0 290 KB

Middleware for Python Django

Home Page: https://www.moesif.com

License: Other

Python 100.00%
django-logging django-middleware django-rest-framework interceptor interceptors logger logging middleware python python-django

moesifdjango's People

Contributors

bakennedy avatar dependabot[bot] avatar dgilling avatar dkm199 avatar keyur9 avatar matthewoates avatar matthewtanner91 avatar mpetyx avatar praves77 avatar xinghengwang avatar xinyuluan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

moesifdjango's Issues

Support for Django 3 & Python 3.7+

Currently using Python 3.7/3.8 with Django 3.

Is there any plan to support these any time soon / known workarounds?

I am currently trying to integrate and am stuck in "No data received yet. It may take a few moments...."

Excessive Logging

After installing the Moesif middleware, I got the following polluting my logs every 5 seconds:

INFO 2021-02-09 18:50:49,865 base 4 139721478100736 Running job "Schedule events batch job every 5 second (trigger: interval[0:00:05], next run at: 2021-02-09 18:50:49 UTC)" (scheduled at 2021-02-09 18:50:49.858046+00:00)
INFO 2021-02-09 18:50:50,228 base 4 139721478100736 Job "Schedule events batch job every 5 second (trigger: interval[0:00:05], next run at: 2021-02-09 18:50:54 UTC)" executed successfully

It also appears during interactive sessions.

I believe the following line is overriding the configuration of other loggers:
https://github.com/Moesif/moesifdjango/blob/master/moesifdjango/middleware.py#L33

server error 500: You cannot access body after reading from request's data stream

Hello,

I am trying to upload an image to a post request and I have the following error.
It seems like something is wrong with the middleware in line 66 when the copy.copy happens.
Looking at it, but also sharing it here in order to investigate it further..

Environment:


Request Method: POST
Request URL: http://localhost:8000/v1/s3direct/get_upload_params/

Django Version: 1.11.7
Python Version: 2.7.10
Installed Applications:
['django.contrib.sites',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.humanize',
 'django.contrib.postgres',
 'orfium',
 'django.contrib.admin',
 'allauth',
 'allauth.account',
 'allauth.socialaccount',
 'django.contrib.sitemaps',
 'allauth.socialaccount.providers.facebook',
 'allauth.socialaccount.providers.instagram',
 'allauth.socialaccount.providers.soundcloud',
 'allauth.socialaccount.providers.twitter',
 'allauth.socialaccount.providers.google',
 'allauth.socialaccount.providers.spotify',
 'django.contrib.auth',
 'storages',
 'admin_reorder',
 'side_packages.signals',
 'side_packages.s3direct',
 'side_packages.braintree',
 'oauth2_provider',
 'haystack',
 'playlog',
 'top_charts',
 'labels',
 'upload_manager',
 'orfium_impersonation',
 'impersonate',
 'django_filters',
 'rest_framework',
 'rest_framework.authtoken',
 'rest_framework_swagger',
 'rest_auth',
 'rest_auth.registration',
 'api',
 'corsheaders',
 'celery_haystack',
 'shopping_cart',
 'rest_framework_cache',
 'cacheops',
 'chat']
Installed Middleware:
['django.contrib.sessions.middleware.SessionMiddleware',
 'api.authentication.middleware.OAuth2TokenMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'corsheaders.middleware.CorsMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'moesifdjango.middleware.moesif_middleware',
 'hirefire.contrib.django.middleware.HireFireMiddleware']



Traceback:

File "/Users/apilama/Desktop/projects/venvs/orfium/venv/lib/python2.7/site-packages/django/core/handlers/exception.py" in inner
  41.             response = get_response(request)

File "/Users/apilama/Desktop/projects/venvs/orfium/venv/lib/python2.7/site-packages/moesifdjango/middleware.py" in middleware
  66.         raw_request_body = copy.copy(request.body)

File "/Users/apilama/Desktop/projects/venvs/orfium/venv/lib/python2.7/site-packages/django/http/request.py" in body
  264.                 raise RawPostDataException("You cannot access body after reading from request's data stream")

Exception Type: RawPostDataException at /v1/s3direct/get_upload_params/
Exception Value: You cannot access body after reading from request's data stream

TypeError: moesif_middleware() takes exactly 1 argument (0 given)

Hello, I get the following error.
Any ideas?
I am using python 2.7.11 and django 1.11

Thank you in advance,
Michael.

File "/Users/apilama/Desktop/projects/repos/orfium-django/orfium_project/wsgi.py", line 27, in <module>
    application = get_wsgi_application()
  File "/Users/apilama/Desktop/projects/venvs/orfium/venv/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
    return WSGIHandler()
  File "/Users/apilama/Desktop/projects/venvs/orfium/venv/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 151, in __init__
    self.load_middleware()
  File "/Users/apilama/Desktop/projects/venvs/orfium/venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 58, in load_middleware
    mw_instance = mw_class()
TypeError: moesif_middleware() takes exactly 1 argument (0 given)

is there an ID that I can use in tests?

Hi there!

I want to set up moesif to my Graphql API, but I faced some issues:

  1. is there an ID I can use in my tests?
Unauthorized access getting application configuration. Please check your Appplication Id.
Response bytes body
  1. some my tests failed with this error message, that I have no idea how to fix it:
ERROR    django.request:log.py:228 Internal Server Error: /graphql/
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.7/site-packages/moesifdjango/middleware.py", line 345, in __call__
    self.sampling_percentage = self.app_config.get_sampling_percentage(self.config, username, company_id)
  File "/usr/local/lib/python3.7/site-packages/moesifdjango/app_config.py", line 32, in get_sampling_percentage
    config_body = json.loads(config.raw_body)
AttributeError: 'NoneType' object has no attribute 'raw_body'

can you please help!

Thank you!!

Django 3.2 use HttpResponse.headers in place of ._headers

Django 3.2 use HttpResponse.headers in place of ._headers. update line https://github.com/Moesif/moesifdjango/blob/master/moesifdjango/middleware.py#L191

Error with Django 3.2+
2021-06-26T09:50:48.722684+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.9/site-packages/moesifdjango/middleware.py", line 191, in call
2021-06-26T09:50:48.722686+00:00 app[web.1]: response._headers["x-moesif-transaction-id"] = ("X-Moesif-Transaction-Id", transaction_id)
2021-06-26T09:50:48.722687+00:00 app[web.1]: AttributeError: 'HttpResponse' object has no attribute '_headers'

Downgrading to Django 3.1.12 works

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.