Record spans in Sentry even if they occur while the response is being streamed
Project description
Stream Aware Django Integration for Sentry
Record spans in Sentry even if they occur while the response is being streamed
Installation
-
Install this with the following command
pip install git+https://github.com/nickodell/shr_span_recorder.git -
Add
StreamAwareDjangoIntegration()to your integrations.Example:
from shr_span_recorder import StreamAwareDjangoIntegration sentry_sdk.init( # ... integrations=[ StreamAwareDjangoIntegration(), ], )If you have custom configuration for
DjangoIntegration(), that can be passed toStreamAwareDjangoIntegration(). It understands all of the same options asDjangoIntegration().import sentry_sdk from shr_span_recorder import StreamAwareDjangoIntegration sentry_sdk.init( # ... integrations=[ StreamAwareDjangoIntegration( # Configuration for DjangoIntegration goes here. Any options that # StreamAwareDjangoIntegration does not understand are passed on # unmodified to DjangoIntegration ), ], ) -
Remove
DjangoIntegration()from integrations, if you have explicitly specified it.In other words, you should not do this:
sentry_sdk.init( # ... integrations=[ # WRONG WRONG WRONG StreamAwareDjangoIntegration(), # DO NOT MIX THESE DjangoIntegration(), ], )You should use one or the other. If you use both, Sentry will pick one of them to enable, and the other will be ignored.
-
Remove Django from
disabled_integrations, if you have explicitly disabled it.If
DjangoIntegration()is disabled, this will also disableStreamAwareDjangoIntegration().It is also not required to disable default integrations.
Compatibility
- Compatible with Sentry 2.12.0 to 2.29.1
- I will probably not update this for Sentry 3.x - you're on your own
- Compatibile with WSGI. ASGI probably doesn't work.
Technical Details
This integration is a replacement for DjangoIntegration. It subclasses DjangoIntegration, and so it is able to provide all of the same features as DjangoIntegration. It differs in one major way. Specifically, when DjangoIntegration manages transactions, it begins transactions when calling your app, and ends when your app returns a value.
In contrast, this integration begins the transaction when calling your app, and ends the transaction when your app returns a value AND the WSGI server calls close() on that value.
As a fallback option, the transaction is also closed after five minutes, in case the WSGI server is refusing to close the transaction.
Performance Note
The transaction timeout is implemented by spawning one thread per request. If your application must deal with a high volume of requests, consider whether this performance cost is prohibitive.
License
This project is licensed under the MIT license.
Not an Official Project
This project is not endorsed or approved by Functional Software, Inc, the owners of the Sentry trademark.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file shr_span_recorder-0.1.0.tar.gz.
File metadata
- Download URL: shr_span_recorder-0.1.0.tar.gz
- Upload date:
- Size: 17.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
62425ea77e0372b08c21e73f6894a8c122b652c56c20e7261bde32988956a3a7
|
|
| MD5 |
6f50a37a767fff0185cd40e72162b4ef
|
|
| BLAKE2b-256 |
df9af37fec7736111b11f3eafe3007e5001b3282933e962a3542b168665e1e6f
|
File details
Details for the file shr_span_recorder-0.1.0-py3-none-any.whl.
File metadata
- Download URL: shr_span_recorder-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
294840a283f306dc6f84f7750a1682fd9084e309a6f527c457885dd58bbebe69
|
|
| MD5 |
b54ab8b6bd837adac6b66180bea9eed7
|
|
| BLAKE2b-256 |
2a3a6099e17582b26205044df3ebd4e2b270b9d2fc0f36d7f0188c3b3992a159
|