Skip to main content

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):
    logger.info("Health endpoint called")
    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

  1. Always instrument FastAPI:
FastAPIInstrumentor.instrument_app(app)
  1. Use context managers for activities to ensure proper cleanup:
with Activity.start("operation"):
    ...
  1. Log inside active spans to maintain trace correlation:
logger.info("This log is trace-correlated")
  1. 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

seliseblocks_lmt-0.0.3.tar.gz (39.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

seliseblocks_lmt-0.0.3-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file seliseblocks_lmt-0.0.3.tar.gz.

File metadata

  • Download URL: seliseblocks_lmt-0.0.3.tar.gz
  • Upload date:
  • Size: 39.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for seliseblocks_lmt-0.0.3.tar.gz
Algorithm Hash digest
SHA256 353c733f5c313bcf91f4a41be1ab020c440268b9638e547bcf7f3813c5fc9d48
MD5 d5fe3b676e00737dab335efb05117d25
BLAKE2b-256 93b6b5db2492f991c4b9eb6976cedd9681535778aa37a070fb80b00c7511a51d

See more details on using hashes here.

File details

Details for the file seliseblocks_lmt-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for seliseblocks_lmt-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3ba88f3176a0f3b4be6109bca156eb810861ec8150312548e4c0c6c0f4d93d12
MD5 9b22e2deedac729201c61f82326c845a
BLAKE2b-256 c988409d65a189aec226cbd5085da8e7c7d83da3cd1de0260491d3cb491d9fde

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page