Python
Client for Django, FastAPI, Flask, and Scripts
What it is for
The official DockRay library for Python lets you integrate Python applications with the DockRay monitoring platform. It enables exception and message reporting as well as HTTP request performance monitoring in asyncio-based applications.
Error and Exception Monitoring
DockRay allows you to report caught exceptions and custom messages directly to the monitoring dashboard.
Reported events can include:
- the exception type and message,
- where the exception occurred and the stack trace,
- application environment information,
- data needed to investigate the issue.
Reporting operations are asynchronous and can run in the background without waiting for the event to be sent.
FastAPI and ASGI
DockRay provides ASGI middleware that automatically monitors HTTP requests and reports unhandled exceptions. The integration works with FastAPI, Starlette, and other ASGI-compatible applications.
Each monitored request can include the HTTP method, path, execution time, and response status code. Expected responses handled by FastAPI, such as 404 and 422, are recorded as transactions rather than errors.
Performance Monitoring
DockRay measures HTTP request processing times and allows you to analyze application transactions. Transactions can also be reported manually, for example for background tasks.
Safe Reporting
The library is designed so that problems with the monitoring service do not affect the monitored application. Network errors and rejected events are written to the logger instead of causing exceptions in your application.
When monitoring requests, sensitive headers such as Authorization, Cookie, and X-Api-Key are removed from reported data.
Built for Asynchronous Applications
DockRay works with asyncio and allows events to be sent in the background. This means communication with the monitoring platform does not need to delay application responses for users.
Installation
Install DockRay using pip:
pip install dock-ray
Configuration
Create a DockRay client using your project token and private key:
from dock_ray import DockRayClient
client = DockRayClient(
token="project-token",
private_key="project-private-key",
environment="production",
)
You can find your project token and private key in the DockRay dashboard.
If the client is created without credentials, it will remain inactive and will not make any connections to the monitoring platform.
When shutting down your application, call await client.close() to complete pending operations and close active connections.
How to use it
The integration reports exceptions on its own. This is for the reports you send deliberately.
from dock_ray import DockRayClient
client = DockRayClient(
token="project-token",
private_key="project-private-key",
environment="production",
)
try:
settle(order)
except Exception as error:
await client.capture_exception(error)
raise
Knowledge base articles
Other integrations
All integrationsWordPress and WooCommerce Plugin
Explore integrationModule for PrestaShop 1.7.8+, 8.x, and 9.x
Explore integrationPlugin for Joomla 4, 5, and 6
Explore integrationModule for Drupal 10.2+ and 11
Explore integrationModule for Magento 2.4 and Adobe Commerce
Explore integrationPackage for Laravel 10+
Explore integrationBundle for Symfony 6.4+
Explore integrationLibrary for PHP Applications
Explore integrationStart Monitoring
Connect your first application and get full visibility into what’s happening in production.