Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

CI Coverage PyPI License

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_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.
  • JsonObjectSpanExporter - A custom SpanExporter that allows the span content to be examined for use in tests.
  • asserting_span_exporter - A contextmanager that makes use of JsonObjectSpanExporter to allow functions under test to be checked by enclosing them in a with block.
What Where
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.6rc0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for observability-utils 0.1.6rc0
File Size Uploaded Provenance Actions
observability_utils-0.1.6rc0.tar.gz 183.4 kB Without provenance Details for observability_utils-0.1.6rc0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for observability-utils 0.1.6rc0
File Interpreter ABI Platform Actions
observability_utils-0.1.6rc0-py3-none-any.whl Python 3 none any Details for observability_utils-0.1.6rc0-py3-none-any.whl

Total release size: 201.7 kB

Release files / observability_utils-0.1.6rc0.tar.gz

Download URL observability_utils-0.1.6rc0.tar.gz
Size 183.4 kB
Tags Source
SHA-256 checksum
How to use checksums
2cdce0617953b29d36f7c4dca62a5d0991ee8e35fa52d9393cc6781da1249177
BLAKE2b-256 checksum
How to use checksums
c468e7938e681b29beefca727092dd06103f0ca84799cd43e603172cce9a7848
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / observability_utils-0.1.6rc0-py3-none-any.whl

Download URL observability_utils-0.1.6rc0-py3-none-any.whl
Size 18.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
800a553b65a2063bb6ff64383cf6f018463b5582066d9d2985b4ebe9822b52d1
BLAKE2b-256 checksum
How to use checksums
f5dd564cfb2cbd4ae1a9e64bc02be923e02df31d7f6088450f690d3f61c835b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Security for observability-utils 0.1.6rc0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page