Python

Client for Django, FastAPI, Flask, and Scripts

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:

python
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.

Articles in this category

DockRay newsletter

Application security in your inbox

Important vulnerabilities, actionable guidance and practical advice for your applications. Choose your technologies and follow what matters to your project.

  • A daily digest of new vulnerabilities, critical ones included.
  • Notifications about important updates.
  • Practical advice on application security and monitoring.

Leave empty to receive updates for every technology.

Free to subscribe. Unsubscribe with one click in any email.