Skip to main content

A Django SDK for Monoscope integration

Project description

Monoscope's Logo Monoscope's Logo

Django SDK

Monoscope SDK PyPI - Version PyPI - Downloads Join Discord Server Monoscope Docs

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',
    ...,
]

[!NOTE]

The {ENTER_YOUR_API_KEY_HERE} demo string should be replaced with the API key generated from the Monoscope dashboard.

The {YOUR_DJANGO_SERVER_NAME} demo string should be replaced with the name of your Django server.

[!IMPORTANT]

To learn more configuration options (redacting fields, error reporting, outgoing requests, etc.), please read this SDK documentation.

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:

License

This repository is published under the MIT license.


Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

monoscope-django-1.0.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

monoscope_django-1.0.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file monoscope-django-1.0.0.tar.gz.

File metadata

  • Download URL: monoscope-django-1.0.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for monoscope-django-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3297c4e05b669b07b6a04647c7f0495b0dbc102b7b6425dd08478012f64e000a
MD5 f05d170fc7b2133bf0b7d025279eb33a
BLAKE2b-256 a350d48cef1ad977a8c22a9da27760e0f5a3489984f56e735dcf8c9f8d35b7ba

See more details on using hashes here.

File details

Details for the file monoscope_django-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for monoscope_django-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2c589d64586a7b768b039551f0e14de55af51733bc60b674307d49e0acb8144a
MD5 212bf4153d9166a35b678ab275c5e295
BLAKE2b-256 2709cd336c9c988a6160b127c2982bc894db87e28298f349003416706eecdfd3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page