Lightweight Python SDK for application observability (TrustVault)
Project description
TrustVault SDK
TrustVault SDK is a lightweight Python library for application observability. It provides simple decorators and context managers to automatically trace function calls, capture timing, inputs, outputs, and errors, and emit structured JSON logs to stdout.
Features
@vault_itdecorator to automatically create spans around function calls- Manual instrumentation via the
Spancontext manager - Context propagation with nested spans and trace IDs
- JSON-based structured logging to stdout
- No external dependencies beyond the Python standard library
Installation
You can install the SDK via PyPI (once published):
pip install trustvault-sdk
Or install directly from source:
git clone https://github.com/<your-org>/trustvault-sdk.git
cd trustvault-sdk
pip install .
For development (editable install):
pip install -e .
Quickstart
Automatic instrumentation
from trustvault_sdk import vault_it
@vault_it
def fetch_data(url):
# Your logic here...
return {"status": "ok", "url": url}
if __name__ == "__main__":
fetch_data("https://example.com")
The SDK will emit a JSON log record similar to:
{
"trace_id": "e4b11f8a...",
"span_id": "a1c9d4f2...",
"parent_id": null,
"name": "fetch_data",
"start_time": 1625246109.123456,
"end_time": 1625246109.234567,
"duration": 0.111111,
"result": "{\"status\": \"ok\", \"url\": \"https://example.com\"}",
"error": null
}
Manual instrumentation
from trustvault_sdk.tracer import Span
def process_items(items):
with Span(name="process_items"):
# Your custom logic here...
pass
Customizing span names
from trustvault_sdk import vault_it
@vault_it(name="custom_name")
def compute(...):
...
Configuration
The SDK uses a logger named trustvault configured to log INFO-level JSON messages to stdout. You can customize it:
import logging
logger = logging.getLogger("trustvault")
logger.setLevel(logging.DEBUG)
# Add additional handlers/formatters if needed
API Reference
- vault_it(func=None, *, name=None): Decorator to trace functions. Optional
nameargument overrides the span name. - Span(name, trace_id=None, parent_id=None): Context manager for manual span creation. Records timing, result, and errors.
- get_logger(): Returns the internal SDK logger.
- safe_log(record): Safely logs a JSON record, catching any logger errors.
Contributing
Contributions are welcome! Please open an issue or submit a pull request.
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 trustvault_sdk-0.1.0.tar.gz.
File metadata
- Download URL: trustvault_sdk-0.1.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6779b5e215646760a710d4618aabe75a5a06bc0f97d4f7eee6404f06ec503218
|
|
| MD5 |
e73128db25d4f48bbc14f50f465a475d
|
|
| BLAKE2b-256 |
e96912027f3e9f3ff0d779d2b9e8a08b58dc587af4832a3b765e3f5cb9533794
|
File details
Details for the file trustvault_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: trustvault_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4407a62d7bb69e8b8a0ef6cf14d5c9b90e825f8de8f372e4fc90074822d41d9
|
|
| MD5 |
5f158aeed10034c6a0bc3d9b6cad56da
|
|
| BLAKE2b-256 |
fee6ea71fc340fb1b1c7241680f68a7c7bebef3e6cd6c6bc9a81a6e9fa1d6b31
|