Django SDK
APIToolkit Django SDK is a middleware that can be used to monitor HTTP requests. It is provides additional functionalities on top of the open telemetry instrumentation which creates a custom span for each request capturing details about the request including request, response bodies errors and outgoing requests.
Table of Contents
Installation
Kindly run the command below to install the apitoolkit django sdks and necessary opentelemetry packages:
pip install monoscope-django opentelemetry-distro opentelemetry-exporter-otlp
# then install the bootstrap script
opentelemetry-bootstrap -a install
Setup Open Telemetry
Setting up open telemetry allows you to send traces, metrics and logs to the APIToolkit platform. To setup open telemetry, you need to configure the following environment variables:
export OTEL_EXPORTER_OTLP_ENDPOINT="http://otelcol.apitoolkit.io:4317"
export OTEL_SERVICE_NAME="my-service" # Specifies the name of the service.
export OTEL_RESOURCE_ATTRIBUTES="at-project-key={ENTER_YOUR_API_KEY_HERE}" # Adds your API KEY to the resource.
export OTEL_EXPORTER_OTLP_PROTOCOL="grpc" # Specifies the protocol to use for the OpenTelemetry exporter.
export DJANGO_SETTINGS_MODULE="{YOUR_DJANGO_SERVER_NAME}.settings" # Specifies the Django settings module to use.
Then run the command below to start your server with opentelemetry instrumented:
opentelemetry-instrument python3 manage.py runserver --noreload
Monoscope Django Configuration
After setting up open telemetry, you can now configure the apitoolkit django middleware.
By adding the following Monoscope variables to your Django settings (settings.py) file:
from pathlib import Path
from dotenv import load_dotenv
import os
load_dotenv()
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
MONOSCOPE_SERVICE_NAME= "my-service"
MONOSCOPE_CAPTURE_REQUEST_BODY = True
MONOSCOPE_CAPTURE_RESPONSE_BODY = True
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.sessions',
]
...
Then add the monoscope_django.MonoscopeMiddleware middleware into the settings.py middleware list, like so:
MIDDLEWARE = [
'monoscope_django.MonoscopeMiddleware', # Initialize Monoscope
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
...,
]
Contributing and Help
To contribute to the development of this SDK or request help from the community and our team, kindly do any of the following:
- Read our Contributors Guide.
- Join our community Discord Server.
- Create a new issue in this repository.
License
This repository is published under the MIT license.
Metadata
Release files for monoscope-django 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| monoscope_django-1.0.3.tar.gz | 4.6 kB | Without provenance | Details for monoscope_django-1.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| monoscope_django-1.0.3-py3-none-any.whl | Python 3 | none | any | Details for monoscope_django-1.0.3-py3-none-any.whl |
Total release size: 9.4 kB
Release files / monoscope_django-1.0.3.tar.gz
| Download URL | monoscope_django-1.0.3.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ad31b77b109bdcfa28118a9e48c33359bcbedd55d83102957dff621b0f600838
|
|
BLAKE2b-256 checksum How to use checksums |
8c869e2647d20a49833a22d408284a17834f0e50516b01ace03cdc0ef2204773
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.8
|
Release files / monoscope_django-1.0.3-py3-none-any.whl
| Download URL | monoscope_django-1.0.3-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
92682581a44a82cc64c2c4bbe22e36f186ee7dd98b3af9b0bf18563b67b8e499
|
|
BLAKE2b-256 checksum How to use checksums |
09606b318540d4e370403c6031faf2911396a03b2276aa06e253950e3d956479
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.8
|
Security for monoscope-django 1.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.