You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -11,6 +12,7 @@ Integration with the following frameworks is **now** implemented:
11
12
12
13
* FastAPI_
13
14
* Starlette_
15
+
* Litestar_
14
16
15
17
But other integrations are planned in the near future, and you can also implement your own through **PR**.
16
18
@@ -65,3 +67,78 @@ These frameworks have the **same** integration api, so here I will show you how
65
67
For **Starlette**, simply replace ``fastapi``with``starlette``in the **integration**import line.
66
68
67
69
Check out the real_world_ example to figure out how it works.
70
+
71
+
72
+
Litestar
73
+
====================
74
+
75
+
.. important::
76
+
77
+
The API is incompatible with FastAPI and Starlette, the rules for determining the path are different, the type of error is not detected.
78
+
79
+
Litestar out of the box has many add-ons:
80
+
81
+
1. **Prometheus** support
82
+
2. **OpenTelemetry** support
83
+
3. **Structlog** plugin
84
+
85
+
But they all have disadvantages, for example, you can use only **global metrics** with a **global registry**, metrics are not compatible with the trace context, logs also do not support the trace context.
86
+
87
+
So **asgi-monitor** is rushing to the rescue.
88
+
89
+
.. code-block:: python
90
+
:caption: Configuring monitoring for the Litestar
91
+
92
+
import logging
93
+
94
+
from asgi_monitor.integrations.litestar import (
95
+
MetricsConfig,
96
+
TracingConfig,
97
+
add_metrics_endpoint,
98
+
build_metrics_middleware,
99
+
build_tracing_middleware,
100
+
)
101
+
from asgi_monitor.logging import configure_logging
102
+
from asgi_monitor.logging.uvicorn import build_uvicorn_log_config
103
+
from litestar import Litestar
104
+
from opentelemetry import trace
105
+
from opentelemetry.sdk.resources import Resource
106
+
from opentelemetry.sdk.trace import TracerProvider
If you want to use **StructlogPlugin**from``litestar.plugins.structlog`` together with tracing, you can embed a processor in the structlog processor chain to export the trace context to the log.
140
+
141
+
.. code-block:: python
142
+
:caption: Import processor for extract trace meta
143
+
144
+
from asgi_monitor.logging.trace_processor import extract_opentelemetry_trace_meta
Copy file name to clipboardExpand all lines: docs/monitoring/metrics.rst
+1-3Lines changed: 1 addition & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,8 +50,6 @@ The ``BaseMetricsConfig`` class is used to configure metrics, and it accepts the
50
50
51
51
4. ``include_trace_exemplar`` (**bool**) - Whether to include trace exemplars in the metrics. Default is ``False``. This is only necessary if **tracing** is configured and metrics are collected in the ``OpenMetrics`` format.
52
52
53
-
5. ``include_metrics_endpoint`` (**bool**) Whether to include a **/metrics** endpoint. Default is ``True``. Collecting metrics in ``text/plain`` format.
54
-
55
53
You can also set up a **global** ``prometheus_client.REGISTRY`` in ``MetricsConfig`` to support your **global** metrics,
56
54
but it is better to use your own **non-global** registry or leave the **default** registry.
57
55
@@ -71,7 +69,7 @@ but it is better to use your own **non-global** registry or leave the **default*
71
69
Exporting
72
70
~~~~~~~~~~~~~~~~~~
73
71
74
-
If you are using integration with the web framework, you can add metric exports via the config by setting ``include_metrics_endpoint`` to ``True``. In this case, the metrics will be exported via the **/metrics** endpoint in ``text/plain`` format.
72
+
If you are using integration with the web framework, you can add metric exports via the config by setting ``include_metrics_endpoint`` to ``True`` or by explicitly calling ``add_metrics_endpoint``. In this case, the metrics will be exported via the **/metrics** endpoint in ``text/plain`` format.
75
73
76
74
In case you need to **customize the endpoint**, add **protection**, use the **OpenMetrics** format, or just use **another method for delivering** metrics, then you should use the built-in ``get_latest_metrics`` function.
0 commit comments