Package: matter-observability
matter-observabilityTable of ContentsInstallationLicenseBackgroundThe Matter observability library for Python is a powerful tool for developers looking to improve their observability in Kubernetes environments. Specifically designed to integrate with FastAPI applications, this library offers support for both endpoint and push-gateway integration with Prometheus, allowing developers to easily monitor the performance and behavior of their applications.The library provides a range of logging and metrics functionality, giving developers granular visibility into the inner workings of their applications. With logging, developers can easily track and diagnose errors, warnings, and other issues, while metrics enable them to track performance metrics like response time, request volume, and error rates.In addition to its powerful logging and metrics capabilities, the Python observability library is designed with scalability in mind. Its push-gateway integration allows developers to easily scale up their monitoring capabilities, while its endpoint integration offers a more lightweight option for smaller deployments.Looking towards the future, the Python observability library is committed to expanding its functionality to include tracing, giving developers even more insight into the performance and behavior of their applications. Whether you're a seasoned developer or just getting started with observability in Kubernetes, this library offers a powerful and flexible solution for monitoring and debugging your FastAPI applications.Getting startedIntegrate from FastAPI:# app is a Fast API appapp=FastAPI(root_path=env.PATH_PREFIX,)frommatter_observability.fastapiimportadd_middlewareadd_middleware(app=app)Use for setting Custom Metrics:Set a Gauge:frommatter_observability.metricsimport(LabeledGauge,GAUGE_CUSTOM,)labeled_gauge=LabeledGauge(metric=GAUGE_CUSTOM,label="your-metric-name")labeled_gauge.set(10.0)Measure Duration:frommatter_observability.metricsimport(LabeledGaugeDuration,GAUGE_PROCESSING_TIME,)labeled_gauge=LabeledGaugeDuration(metric=GAUGE_PROCESSING_TIME,label="test")labeled_gauge.start()# ... some operationlabeled_gauge.stop()Set a Counter:frommatter_observability.metricsimport(LabeledCounter,COUNTER_CUSTOM,)labeled_counter=LabeledCounter(metric=COUNTER_CUSTOM,label="your-metric-name")labeled_counter.inc()Use with Decorators:Set a Gauge - Sync:frommatter_observability.metricsimport(gauge_value,)@gauge_value(label="your-metric-name")defmy_func(gauge):gauge.set(10.0)my_func()Set a Gauge - Async:frommatter_observability.metricsimport(gauge_value,)@gauge_value(label="your-metric-name")asyncdefmy_func(gauge):gauge.set(10.0)awaitmy_func()Measure Duration - Sync:frommatter_observability.metricsimport(measure_processing_time,)@measure_processing_time(label="your-metric-name")defmy_func():time.sleep(1)my_func()Measure Duration - Async:frommatter_observability.metricsimport(measure_processing_time,)@measure_processing_time(label="test")asyncdefmy_func():time.sleep(1)awaitmy_func()Set a Counter - Sync:frommatter_observability.metricsimport(count_occurrence,)@count_occurrence(label="your-metric-name")defmy_func():passmy_func()Set a Counter - Async:frommatter_observability.metricsimport(count_occurrence,)@count_occurrence(label="your-metric-name")asyncdefmy_func():passawaitmy_func()InstallationInstall the Library:pip install matter-observabilityMake sure that you have set the following ENV values:SERVER_LOG_LEVEL=debug
PROMETHEUS_PUSH_GATEWAY_HOST=localhost
INSTANCE_NAME=observability_instanceContributingMake sure you have all supported python versions installed in your machine:3.103.11Install hatch in your systemhttps://hatch.pypa.io/latest/install/Create the environmenthatch env createLocate the new environmenthatch env find defaultDo your changes...Run the testshatch run testThe command above will run the tests against all supported python versions
installed in your machine. For testing in other operating system you may use the
configured CI in github.Bump a new versionIn general, you just need to execute:hatch versionThis command will update the minor version. i.e.:
No breaking changes and new feature has been addedWe are usingsemantic version, if you are doing a bug fix:hatch version fix