Skip to content

Commit

Permalink
Merge pull request #363 from maykinmedia/feature/add-django-log-outgo…
Browse files Browse the repository at this point in the history
…ing-requests

➕ Add django-log-outgoing-requests
  • Loading branch information
Coperh authored Apr 23, 2024
2 parents b819418 + db6c915 commit 6fe150c
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/installation/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ Other settings
* ``DISABLE_2FA``: whether to disable two-factor authentication. Defaults to ``False``.
If set to ``False``, 2FA will be required if not using OIDC.

* ``LOG_REQUESTS``: whether to enable logging of outgoing HTTP requests. Defaults to ``False``.

* ``LOG_OUTGOING_REQUESTS_DB_SAVE``: whether to save logged requests to the database. Defaults to ``False``.

Initial superuser creation
--------------------------

Expand Down
1 change: 1 addition & 0 deletions requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ open-api-framework
# Core python libraries
glom # data represenation based on spec
jsonschema
django-log-outgoing-requests

# Common ground libraries
notifications-api-common
8 changes: 8 additions & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ django==4.2.11
# via
# commonground-api-common
# django-admin-index
# django-appconf
# django-axes
# django-cors-headers
# django-filter
# django-formtools
# django-jsonform
# django-log-outgoing-requests
# django-markup
# django-otp
# django-phonenumber-field
Expand All @@ -99,6 +101,8 @@ django==4.2.11
# zgw-consumers
django-admin-index==3.1.0
# via open-api-framework
django-appconf==1.0.6
# via django-log-outgoing-requests
django-axes==6.3.0
# via open-api-framework
django-cors-headers==4.3.1
Expand All @@ -113,6 +117,8 @@ django-jsonform==2.21.4
# via
# mozilla-django-oidc-db
# open-api-framework
django-log-outgoing-requests==0.6.1
# via -r requirements/base.in
django-markup==1.8.1
# via open-api-framework
django-ordered-model==3.7.4
Expand All @@ -136,6 +142,7 @@ django-simple-certmanager==1.4.1
django-solo==2.2.0
# via
# commonground-api-common
# django-log-outgoing-requests
# mozilla-django-oidc-db
# notifications-api-common
# zgw-consumers
Expand Down Expand Up @@ -276,6 +283,7 @@ requests==2.31.0
# via
# commonground-api-common
# coreapi
# django-log-outgoing-requests
# gemma-zds-client
# mozilla-django-oidc
# open-api-framework
Expand Down
10 changes: 10 additions & 0 deletions requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,13 @@ django==4.2.11
# -r requirements/base.txt
# commonground-api-common
# django-admin-index
# django-appconf
# django-axes
# django-cors-headers
# django-filter
# django-formtools
# django-jsonform
# django-log-outgoing-requests
# django-markup
# django-otp
# django-phonenumber-field
Expand All @@ -141,6 +143,10 @@ django-admin-index==3.1.0
# via
# -r requirements/base.txt
# open-api-framework
django-appconf==1.0.6
# via
# -r requirements/base.txt
# django-log-outgoing-requests
django-axes==6.3.0
# via
# -r requirements/base.txt
Expand All @@ -163,6 +169,8 @@ django-jsonform==2.21.4
# -r requirements/base.txt
# mozilla-django-oidc-db
# open-api-framework
django-log-outgoing-requests==0.6.1
# via -r requirements/base.txt
django-markup==1.8.1
# via
# -r requirements/base.txt
Expand Down Expand Up @@ -207,6 +215,7 @@ django-solo==2.2.0
# via
# -r requirements/base.txt
# commonground-api-common
# django-log-outgoing-requests
# mozilla-django-oidc-db
# notifications-api-common
# zgw-consumers
Expand Down Expand Up @@ -440,6 +449,7 @@ requests==2.31.0
# -r requirements/base.txt
# commonground-api-common
# coreapi
# django-log-outgoing-requests
# gemma-zds-client
# mozilla-django-oidc
# open-api-framework
Expand Down
10 changes: 10 additions & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,15 @@ django==4.2.11
# -r requirements/ci.txt
# commonground-api-common
# django-admin-index
# django-appconf
# django-axes
# django-cors-headers
# django-debug-toolbar
# django-extensions
# django-filter
# django-formtools
# django-jsonform
# django-log-outgoing-requests
# django-markup
# django-otp
# django-phonenumber-field
Expand All @@ -163,6 +165,10 @@ django-admin-index==3.1.0
# via
# -r requirements/ci.txt
# open-api-framework
django-appconf==1.0.6
# via
# -r requirements/ci.txt
# django-log-outgoing-requests
django-axes==6.3.0
# via
# -r requirements/ci.txt
Expand All @@ -189,6 +195,8 @@ django-jsonform==2.21.4
# -r requirements/ci.txt
# mozilla-django-oidc-db
# open-api-framework
django-log-outgoing-requests==0.6.1
# via -r requirements/ci.txt
django-markup==1.8.1
# via
# -r requirements/ci.txt
Expand Down Expand Up @@ -233,6 +241,7 @@ django-solo==2.2.0
# via
# -r requirements/ci.txt
# commonground-api-common
# django-log-outgoing-requests
# mozilla-django-oidc-db
# notifications-api-common
# zgw-consumers
Expand Down Expand Up @@ -507,6 +516,7 @@ requests==2.31.0
# -r requirements/ci.txt
# commonground-api-common
# coreapi
# django-log-outgoing-requests
# gemma-zds-client
# mozilla-django-oidc
# open-api-framework
Expand Down
21 changes: 21 additions & 0 deletions src/objects/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from django.urls import reverse_lazy

from log_outgoing_requests.formatters import HttpFormatter
from sentry_sdk.integrations import django, redis

from .api import * # noqa
Expand Down Expand Up @@ -98,6 +99,7 @@
# External applications.
"axes",
"drf_spectacular",
"log_outgoing_requests",
"mozilla_django_oidc",
"mozilla_django_oidc_db",
"django_jsonform",
Expand Down Expand Up @@ -231,6 +233,8 @@
FIXTURE_DIRS = (os.path.join(DJANGO_PROJECT_DIR, "fixtures"),)

LOGGING_DIR = os.path.join(BASE_DIR, "log")
LOG_REQUESTS = config("LOG_REQUESTS", default=False)
LOG_OUTGOING_REQUESTS_DB_SAVE = config("LOG_OUTGOING_REQUESTS_DB_SAVE", default=False)

LOGGING = {
"version": 1,
Expand All @@ -244,6 +248,7 @@
"performance": {
"format": "%(asctime)s %(process)d | %(thread)d | %(message)s",
},
"outgoing_requests": {"()": HttpFormatter},
},
"filters": {
"require_debug_false": {"()": "django.utils.log.RequireDebugFalse"},
Expand Down Expand Up @@ -287,6 +292,15 @@
"maxBytes": 1024 * 1024 * 10, # 10 MB
"backupCount": 10,
},
"log_outgoing_requests": {
"level": "DEBUG",
"formatter": "outgoing_requests",
"class": "logging.StreamHandler",
},
"save_outgoing_requests": {
"level": "DEBUG",
"class": "log_outgoing_requests.handlers.DatabaseOutgoingRequestsHandler",
},
},
"loggers": {
"objects": {
Expand All @@ -308,6 +322,13 @@
"handlers": ["project"],
"level": "DEBUG",
},
"log_outgoing_requests": {
"handlers": ["log_outgoing_requests", "save_outgoing_requests"]
if LOG_REQUESTS
else [],
"level": "DEBUG",
"propagate": True,
},
},
}

Expand Down
8 changes: 8 additions & 0 deletions src/objects/fixtures/default_admin_index.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@
[
"mozilla_django_oidc_db",
"openidconnectconfig"
],
[
"log_outgoing_requests",
"outgoingrequestslog"
],
[
"log_outgoing_requests",
"outgoingrequestslogconfig"
]
]
}
Expand Down

0 comments on commit 6fe150c

Please sign in to comment.