Logging, Monitoring, and Tracing library for Selise Blocks applications using Azure Service Bus.
Project description
Selise Blocks LMT
Selise Blocks LMT (Logging, Monitoring, and Tracing) library for Selise Blocks applications. It sends logs and traces to Azure Service Bus for centralized processing.
Installation
Using pip:
pip install seliseblocks-lmt
Using uv:
uv add seliseblocks-lmt
Add to pyproject.toml:
[project]
dependencies = [
"seliseblocks-lmt>=0.0.1",
]
Complete Example
import logging
from fastapi import FastAPI, Request
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
from blocks_lmt.log_config import configure_logger
from blocks_lmt.tracing import configure_tracing
from blocks_lmt.activity import Activity
app = FastAPI(title="Example Service with LMT")
FastAPIInstrumentor.instrument_app(app)
configure_logger(
x_blocks_key="default-tenant",
blocks_service_id="example-service",
connection_string="Endpoint=sb://your-namespace.servicebus.windows.net/;..."
)
configure_tracing(
x_blocks_key="default-tenant",
blocks_service_id="example-service",
connection_string="Endpoint=sb://your-namespace.servicebus.windows.net/;..."
)
logger = logging.getLogger(__name__)
@app.get("/")
async def root():
logger.info("Root endpoint called")
with Activity.start("handle_root_request") as activity:
activity.set_property("endpoint", "/")
return {"message": "Hello World"}
@app.get("/health")
async def health(request: Request):
Activity.set_current_properties({
"http.query": str(dict(request.query_params)),
"http.headers": str(dict(request.headers))
})
return {"status": "healthy"}
Activity API Reference
Context Manager
with Activity.start("operation_name") as activity:
activity.set_property("key", "value")
activity.set_properties({"key1": "val1", "key2": "val2"})
Status Handling
from opentelemetry.trace import StatusCode
Activity.set_current_status(StatusCode.ERROR, "Error message")
Best Practices
- Always instrument FastAPI:
FastAPIInstrumentor.instrument_app(app)
- Use context managers for activities to ensure proper cleanup:
with Activity.start("operation"):
...
- Log inside active spans to maintain trace correlation:
logger.info("This log is trace-correlated")
- Add meaningful properties to activities:
activity.set_property("user_id", user_id)
Dependencies
azure-servicebus = ">=7.14.2"
opentelemetry-api = ">=1.33.1"
opentelemetry-sdk = ">=1.33.1"
opentelemetry-instrumentation-fastapi = ">=0.54b1"
Project details
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 seliseblocks_lmt-0.0.2.tar.gz.
File metadata
- Download URL: seliseblocks_lmt-0.0.2.tar.gz
- Upload date:
- Size: 39.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb2e405f7d981fec58988f1b4d434ca4793ac66f8ffd0272d97453e86a991782
|
|
| MD5 |
e5f8ac5fc789645a766cb43ce5592621
|
|
| BLAKE2b-256 |
32cf1066237898d256bf316d7c920f8d38dc1f01ebbcfe5c93e957bcb2fa53f1
|
File details
Details for the file seliseblocks_lmt-0.0.2-py3-none-any.whl.
File metadata
- Download URL: seliseblocks_lmt-0.0.2-py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73791297c7b5aa25f103a72b86f452ed9c9070ee26ccb7ac387dfd8675e74f76
|
|
| MD5 |
3870b72ed4fe588a21a9f147ba2ed4bf
|
|
| BLAKE2b-256 |
3f6abf5e328b0de41f562d6c37d091c20ae9c9d6d1ea2aac5417b24330c6d0dc
|