A set of function to reduce the boilerplate required to add observability to your service of module
Project description
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
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file observability_utils-0.1.1.tar.gz
.
File metadata
- Download URL: observability_utils-0.1.1.tar.gz
- Upload date:
- Size: 25.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14d7e4479666ec5afc6251682e29e5a5661a6b19885e1dab4945a8877c638e07 |
|
MD5 | 9df36a367d4413ce2f9cebff25d5916c |
|
BLAKE2b-256 | 208e11ad00ca234453ef516510bcbfc595d926bb460c0ca635aaf605775e6596 |
File details
Details for the file observability_utils-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: observability_utils-0.1.1-py3-none-any.whl
- Upload date:
- Size: 13.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2c000438cd561f1327d4ed14a9be0fe057928e319c5acd965c5435c06d10a78 |
|
MD5 | fb5c4941b267f915dc25ff5653d484dd |
|
BLAKE2b-256 | f5304c4033b60692f1f14af5bce3fd9f455839166504d0e70f0d67e7b876c4b7 |