Skip to main content

CI Coverage PyPI License

observability_utils

A set of functions to reduce the boilerplate required to add OpenTelemetry based observability to your Python service or module.

At the moment there are not a great amount of util functions provided, but it is hoped that, as more observabilty code is added to our services and modules, this becomes the standard place to put code snippets that are commonly useful.

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.
  • instrument_fastapi_app(app, name) - Sets up basic tracing as above and then turns on automated tracing of FastAPI calls.
  • 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).
  • 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.
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 import instrument_fastapi_app, get_tracer

app = FastAPI(
    docs_url="/docs",
    on_shutdown=[teardown_handler],
    title="My Rest App",
    lifespan=lifespan,
    version=REST_API_VERSION,
)

instrument_fastapi_app(app, "my_rest_app")

TRACER = get_tracer("my_rest_app")

@TRACER.start_as_current_span("my_func",  kind=SpanKind.CLIENT)
def my_func():
    #function body

Metadata

Release files for observability-utils 0.1.1

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.1
File Size Uploaded
observability_utils-0.1.1.tar.gz 25.4 kB Details

Built distribution (wheel)

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

Total release size: 39.4 kB

Release files / observability_utils-0.1.1.tar.gz

Download URL observability_utils-0.1.1.tar.gz
Size 25.4 kB
Tags Source
SHA-256 checksum
How to use checksums
14d7e4479666ec5afc6251682e29e5a5661a6b19885e1dab4945a8877c638e07
BLAKE2b-256 checksum
How to use checksums
208e11ad00ca234453ef516510bcbfc595d926bb460c0ca635aaf605775e6596
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.3

Release files / observability_utils-0.1.1-py3-none-any.whl

Download URL observability_utils-0.1.1-py3-none-any.whl
Size 13.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c2c000438cd561f1327d4ed14a9be0fe057928e319c5acd965c5435c06d10a78
BLAKE2b-256 checksum
How to use checksums
f5304c4033b60692f1f14af5bce3fd9f455839166504d0e70f0d67e7b876c4b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

0.1.5

2 release files

0.1.4

2 release files

0.1.2

2 release files

This release

0.1.1 This release

2 release files

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