Skip to main content

Wraps the default Django SMTP Email Backend with trace instrumentation to the OpenTelemetry

Project description

Wraps the default Django SMTP Email Backend with trace instrumentation to the OpenTelemetry.

PyPI - Version License

Description

This small package provides a wrapper for the default django.core.mail.backends.smtp.EmailBackend adapter to provide better tracing instrumentation for OpenTelemetry.

Dependencies

  • django >= 4.2
  • opentelemetry-api

Usage

Installation

Install, from PyPI, using your package manager:

pip install django-otel-smtp-backend

Configuration

Change the EMAIL_BACKEND field on settings.py file:

EMAIL_BACKEND = "django_otel_smtp_backend.backend.EmailBackend"
EMAIL_HOST = ...
EMAIL_USE_TLS = ...
EMAIL_PORT = ...
EMAIL_USE_SSL = ...
EMAIL_HOST_USER = ...
EMAIL_HOST_PASSWORD = ...

The configuration of OpenTelemetry is not a subject of this readme.

OpenTelemetry

The traces captured from the EmailBackend is structured as shown below (the times was taken from a real example):

  - send_messages (2.89s)
  | - open (1.55s)
  | - send_message_item (1.17s)
  | - close (168.43ms)

The send_messages() method from the BaseEmailBackend receives various e-mails and, in SMTP backend, send one by one using a for-iterator (reference). The send_messages span is opened when the send_messages() method is called, the open span is opened when the connection is opened and close span is opened when the connection is closed. The send_message_item span is opened when each e-mail is sent using the SMTP connection.

Span Attributes

send_messages

attribute description
raised indicate if the send_messages() method raises a exception.
stack stack trace of the raised exception (when raised=True).

open

attribute description
connection_already_open indicate if the connection is already opened when open() is called.
connection_opened indicate if the connection is opened.
fail_silently indicate if the used value of fail_silently property.
raised indicate if the open() method raises a exception.
stack stack trace of the raised exception (when raised=True).

send_message_item

attribute description
from_email the origin email.
recipients the destination email's.
sent indicate if the email is sent.
raised indicate if the method raises a exception.
stack stack trace of the raised exception (when raised=True).

close

attribute description
has_connection indicate if the connection is opened when call close().
raised indicate if the open() method raises a exception.
stack stack trace of the raised exception (when raised=True).

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

django_otel_smtp_backend-0.0.4.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

django_otel_smtp_backend-0.0.4-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file django_otel_smtp_backend-0.0.4.tar.gz.

File metadata

File hashes

Hashes for django_otel_smtp_backend-0.0.4.tar.gz
Algorithm Hash digest
SHA256 d28d4e2925ad1b490b8531ad701eed80fb5758818254928b6df15ef0d51334f5
MD5 d6b7d2d74c5ee399be4128ed7336bab9
BLAKE2b-256 665f4cbbc56fb14508a5074b3671a3bd07a7d7e358ec4da6b7b9247094d6f13c

See more details on using hashes here.

File details

Details for the file django_otel_smtp_backend-0.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for django_otel_smtp_backend-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c2865ee8366473a0a27c7de582ac86c51cb4e6aa2d4cbd49b97af6364e02c6aa
MD5 6186d7ab4c70f814e0eb7bbed3ed0b71
BLAKE2b-256 349c956b3b65c7ad22c95c3e4a3ae69d9eb78ebc73c63a2cd4568944d77da6b5

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