# dock-thor-client
`dock-thor-client` is a Python client for **DockTHOR error reporting**, designed to easily capture and send application errors, exceptions, and messages to the DockTHOR API. It supports asynchronous operation so that sending errors does not block your main application flow.
## Features
- Capture exceptions and messages from your Python application.
- Send events asynchronously to avoid slowing down your application.
- Fully compatible with DockTHOR API.
- Serialize events, stack traces, and context data automatically.
- Supports user, environment, and custom metadata.
## Installation
```bash
pip install dock-thor-client
```
## Usage
Initialize the client
```python
from dock_thor import DockThorClient
client = DockThorClient(token="your-token", private_key="your-private-key")
```
## Capture an exception
```python
try:
1 / 0
except Exception as e:
client.capture_exception(e)
```
## Capture a message
```python
client.capture_message("Something happened!", level="error")
```
## Automatic FastAPI Integration
If you’re using FastAPI, the client can automatically measure request durations, capture errors, and send transaction data.
```python
from fastapi import FastAPI
from dock_thor import DockThorClient, DockThorFastAPIMiddleware
client = DockThorClient(token="your-token", private_key="your-private-key")
app = FastAPI()
# Add DockTHOR middleware with optional exclusions
app.add_middleware(
DockThorFastAPIMiddleware,
client=client,
exclude_paths=["/api/health", "/metrics"]
)
```
Now every request will automatically:
- Generate a transaction (trace_id, span_id, duration, HTTP status)
- Send it to DockTHOR
- Capture and report any unhandled exceptions
## Manual Transaction Capture
You can also manually capture custom transactions (e.g. background jobs):
```python
import time
from dock_thor import Span
start = time.time()
# your process here
end = time.time()
span = Span(
span_id="abc123",
trace_id="xyz789",
start_timestamp=start,
end_timestamp=end,
description="Background job",
op="worker.task",
status="200",
data={"duration_ms": round((end - start) * 1000, 2)},
)
await client.capture_transaction(
name="job:daily_cleanup",
spans=[span]
)
```
## Contributing
Contributions are welcome! Please open issues or pull requests on [GitHub](https://github.com/dockcodes/dock-thor/issues)
Raw data
{
"_id": null,
"home_page": null,
"name": "dock-thor-client",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "error reporting, monitoring, async, fastapi, logging",
"author": "Jacek Labudda",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/6a/e9/008d9df58f6000dcd65ed4bd519d993375dd9199e3ff923f46f0c342d8fb/dock_thor_client-1.0.7.tar.gz",
"platform": null,
"description": "# dock-thor-client\n\n`dock-thor-client` is a Python client for **DockTHOR error reporting**, designed to easily capture and send application errors, exceptions, and messages to the DockTHOR API. It supports asynchronous operation so that sending errors does not block your main application flow.\n\n## Features\n\n- Capture exceptions and messages from your Python application.\n- Send events asynchronously to avoid slowing down your application.\n- Fully compatible with DockTHOR API.\n- Serialize events, stack traces, and context data automatically.\n- Supports user, environment, and custom metadata.\n\n## Installation\n\n```bash\npip install dock-thor-client\n```\n\n## Usage\nInitialize the client\n```python\nfrom dock_thor import DockThorClient\n\nclient = DockThorClient(token=\"your-token\", private_key=\"your-private-key\")\n```\n\n## Capture an exception\n```python\ntry:\n 1 / 0\nexcept Exception as e:\n client.capture_exception(e)\n```\n\n## Capture a message\n```python\nclient.capture_message(\"Something happened!\", level=\"error\")\n```\n\n## Automatic FastAPI Integration\nIf you\u2019re using FastAPI, the client can automatically measure request durations, capture errors, and send transaction data.\n```python\nfrom fastapi import FastAPI\nfrom dock_thor import DockThorClient, DockThorFastAPIMiddleware\n\nclient = DockThorClient(token=\"your-token\", private_key=\"your-private-key\")\n\napp = FastAPI()\n\n# Add DockTHOR middleware with optional exclusions\napp.add_middleware(\n DockThorFastAPIMiddleware,\n client=client,\n exclude_paths=[\"/api/health\", \"/metrics\"]\n)\n```\nNow every request will automatically:\n- Generate a transaction (trace_id, span_id, duration, HTTP status)\n- Send it to DockTHOR\n- Capture and report any unhandled exceptions\n\n## Manual Transaction Capture\nYou can also manually capture custom transactions (e.g. background jobs):\n```python\nimport time\nfrom dock_thor import Span\n\nstart = time.time()\n# your process here\nend = time.time()\n\nspan = Span(\n span_id=\"abc123\",\n trace_id=\"xyz789\",\n start_timestamp=start,\n end_timestamp=end,\n description=\"Background job\",\n op=\"worker.task\",\n status=\"200\",\n data={\"duration_ms\": round((end - start) * 1000, 2)},\n)\n\nawait client.capture_transaction(\n name=\"job:daily_cleanup\",\n spans=[span]\n)\n```\n## Contributing\nContributions are welcome! Please open issues or pull requests on [GitHub](https://github.com/dockcodes/dock-thor/issues)\n",
"bugtrack_url": null,
"license": null,
"summary": "Python client for DockTHOR error reporting",
"version": "1.0.7",
"project_urls": null,
"split_keywords": [
"error reporting",
" monitoring",
" async",
" fastapi",
" logging"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "ab1d24fc99c85fdf93ef9019fbd9b656c493d947520196963bdc8d197d955edc",
"md5": "e6a02b784050e20db3b08d817c8d4194",
"sha256": "9b9cbbeb7f03fec8fef2c67a2f07ef6c17f62d550fd0bfba82b7f22acd1a7f81"
},
"downloads": -1,
"filename": "dock_thor_client-1.0.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e6a02b784050e20db3b08d817c8d4194",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 8276,
"upload_time": "2025-10-26T15:53:47",
"upload_time_iso_8601": "2025-10-26T15:53:47.744984Z",
"url": "https://files.pythonhosted.org/packages/ab/1d/24fc99c85fdf93ef9019fbd9b656c493d947520196963bdc8d197d955edc/dock_thor_client-1.0.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "6ae9008d9df58f6000dcd65ed4bd519d993375dd9199e3ff923f46f0c342d8fb",
"md5": "e67009a62f214dc0c02bfecc2f26deac",
"sha256": "e2f45d989d71ce4aa35f2e5652859d72a956f32fcd7016a2f982012b3732d7c6"
},
"downloads": -1,
"filename": "dock_thor_client-1.0.7.tar.gz",
"has_sig": false,
"md5_digest": "e67009a62f214dc0c02bfecc2f26deac",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 7605,
"upload_time": "2025-10-26T15:53:48",
"upload_time_iso_8601": "2025-10-26T15:53:48.778714Z",
"url": "https://files.pythonhosted.org/packages/6a/e9/008d9df58f6000dcd65ed4bd519d993375dd9199e3ff923f46f0c342d8fb/dock_thor_client-1.0.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-10-26 15:53:48",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "dock-thor-client"
}