observability_utils
A set of functions and decorators to reduce the boilerplate required to add OpenTelemetry based observability to your Python service or module.
The decorators allow spans to be initialised which automatically capture identified parameters of the decorated method as Span Attributes. The context propagation helpers provide a pair of standard functions that can be used as parameters to streamline addition of this functionality.
In the initial version the following utils are provided:
setup_tracing(name)- Sets up basic tracing using a standardised naming convebstion so that the application is easily identifiable in visualisation tools.set_console_exporter()- Turns on output of the capturesd traces in a local console/terminal to allow viewing of it without the need for an observability backend such as Jaeger or Promethus. Useful for debugging and testing.get_tracer(name)- Retrieves the currently active Tracer object and labels is using a standard naming convention so that traces it produces are consistent across applications.get_trace_context()- Retrives the current trace context (this is just a more clearly named version of the library function).get_context_propagator- Retrieves the current observability context info in a form suitable for propagating.propagate_context_in_stomp_headers(headers, context)- Simplfies the propagation of the Tracing Context between services that support STOMP communication over a message bus.retrieve_context_from_stomp_headers(frame)- Simplifies th reception of the Tracing Context by services that support STOMP communication over a message bus.add_span_attributes- Simplifies the addition of named attributes to the current span.
| Source | https://github.com/DiamondLightSource/observability-utils |
|---|---|
| PyPI | pip install observability-utils |
| Releases | https://github.com/DiamondLightSource/observability-utils/releases |
Usage examples:
from fastapi import FastAPI
from observability_utils.decorators import start_as_current_span
from observability_utils.tracing import setup_tracing, get_tracer
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
setup_tracing("my_rest_app")
app = FastAPI(
docs_url="/docs",
on_shutdown=[teardown_handler],
title="My Rest App",
lifespan=lifespan,
version=REST_API_VERSION,
)
FastAPIInstrumentor().instrument_app(app)
TRACER = get_tracer("my_rest_app")
start_as_current_span(TRACER, "fruit", "fruit.colour", "amount")
def my_func(fruit : Fruit = "apple", amount : int = 0):
#function body
Metadata
Release files for observability-utils 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| observability_utils-0.1.2.tar.gz | 30.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| observability_utils-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 47.5 kB
Release files / observability_utils-0.1.2.tar.gz
| Download URL | observability_utils-0.1.2.tar.gz |
|---|---|
| Size | 30.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f84f244c530d7b834c2cf2c776b45e0f455f78d63c34340dc326d75fd420bbaa
|
|
BLAKE2b-256 checksum How to use checksums |
1856c776ff01000c4cd96bfa64d1023ba4f0e01b026baf53e426782f39265967
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|
Release files / observability_utils-0.1.2-py3-none-any.whl
| Download URL | observability_utils-0.1.2-py3-none-any.whl |
|---|---|
| Size | 16.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
35c49d261b7b32653d8b24e54af983b787e2790225b1e66bda4e312bf62f5949
|
|
BLAKE2b-256 checksum How to use checksums |
88799f496639400dbcdbe3b692e9098cf010b2abb227fc044cae6437a71fa4b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.7
|