Skip to main content

OpenTelemetry Instrumentation for Django

Project description

pypi

This library allows tracing requests for Django applications.

Installation

pip install opentelemetry-instrumentation-django

Configuration

Exclude lists

To exclude certain URLs from being tracked, set the environment variable OTEL_PYTHON_DJANGO_EXCLUDED_URLS with comma delimited regexes representing which URLs to exclude.

For example,

export OTEL_PYTHON_DJANGO_EXCLUDED_URLS="client/.*/info,healthcheck"

will exclude requests such as https://site/client/123/info and https://site/xyz/healthcheck.

Request attributes

To extract certain attributes from Django’s request object and use them as span attributes, set the environment variable OTEL_PYTHON_DJANGO_TRACED_REQUEST_ATTRS to a comma delimited list of request attribute names.

For example,

export OTEL_PYTHON_DJANGO_TRACED_REQUEST_ATTRS='path_info,content_type'

will extract path_info and content_type attributes from every traced request and add them as span attritbues.

Django Request object reference: https://docs.djangoproject.com/en/3.1/ref/request-response/#attributes

Request and Response hooks

The instrumentation supports specifying request and response hooks. These are functions that get called back by the instrumentation right after a Span is created for a request and right before the span is finished while processing a response. The hooks can be configured as follows:

def request_hook(span, request):
    pass

def response_hook(span, request, response):
    pass

DjangoInstrumentation().instrument(request_hook=request_hook, response_hook=response_hook)

References

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

Built Distribution

File details

Details for the file opentelemetry-instrumentation-django-0.20b0.tar.gz.

File metadata

  • Download URL: opentelemetry-instrumentation-django-0.20b0.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.10

File hashes

Hashes for opentelemetry-instrumentation-django-0.20b0.tar.gz
Algorithm Hash digest
SHA256 c32c11a73fb3915d13eb1e77f4b281d9f19bbcb38b4a9373c40c8d5d08ce7eb4
MD5 fb571a37cb6a950cdc9103fbb0793b51
BLAKE2b-256 0695f9e52a987594718ac12cb3d856f04f2de8a5a8ea71b14f7ae13cbf508687

See more details on using hashes here.

File details

Details for the file opentelemetry_instrumentation_django-0.20b0-py3-none-any.whl.

File metadata

File hashes

Hashes for opentelemetry_instrumentation_django-0.20b0-py3-none-any.whl
Algorithm Hash digest
SHA256 8880cb5d8d326103f16861341bba44d795fe9977f52a9465c90bc9d140c35292
MD5 000a48b42408ea35b9d1665596393559
BLAKE2b-256 628ef65d167aa34acad0b6aed453fb0d36308f295fd10993fe69fa0676131404

See more details on using hashes here.

Supported by

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