Wraps the default Django SMTP Email Backend with trace instrumentation to the OpenTelemetry.
This small package provides a wrapper for the default django.core.mail.backends.smtp.EmailBackend
adapter to provide better tracing instrumentation for OpenTelemetry.
- django >= 4.2
- opentelemetry-api
Install, from PyPI, using your package manager:
pip install django-otel-smtp-backend
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.
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.
attribute | description |
---|---|
raised | indicate if the send_messages() method raises a exception. |
stack | stack trace of the raised exception (when raised=True). |
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). |
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). |
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). |