Starlette-exporter

Latest version: v0.23.0

Safety actively analyzes 682244 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 2 of 5

0.17.1

Add FutureWarnings for group_paths and filter_unhandled_paths indicating that the default values will change next release (see 79 )

0.17.0

* include headers in app scope when matching request path 76 evstratbg
* callback functions used to populate labels can now be async 70 YiuRULE

**Potentially impactful changes:**
* the status code reported for client disconnections will now be 499 instead of 500 77 Alexander-N
* note: some users may notice a new status_code=499 timeseries if a client disconnects before response is written (previously this would be erroneously reported as a 500 status).

0.16.0

skip_methods option

This releases adds the `skip_methods` option, which allows you to avoid recording metrics for any requests with the specified methods. Use this if you do not want certain types of requests (e.g. `OPTIONS`) to appear in your metrics. The argument should be a list of strings corresponding to method names.

Usage:

app.add_middleware(
PrometheusMiddleware,
app_name="hello_world",
skip_methods=['OPTIONS']
)


Credit to adinsoon for this new feature.

Bug fixes
Fix for `Module "starlette_exporter" does not explicitly export attribute "PrometheusMiddleware"` (63) poofeg

README fixes: fixed references to the `handle_metrics` function in example (elatomo ), and fixed the exemplars example (camerondavison)

0.15.1

This small release updates the type hint for the `buckets` param from `List` to `Sequence` to match the type hint in the Prometheus client library.
Credit to sbrandtb (59)

0.15.0

Adds exemplar support for the request counter and request latency histograms. This is intended to be used with tracing (e.g. OpenTelemetry).

You must supply your own callback function that returns a trace id to be used as the exemplar. PRs welcome with an example, or a simple OpenTelemetry-based helper function.

Example:

python
must use `handle_openmetrics` instead of `handle_metrics` for exemplars to appear in /metrics output.
from starlette_exporter import PrometheusMiddleware, handle_openmetrics

app.add_middleware(
PrometheusMiddleware,
exemplars={"trace_id": get_trace_id} supply your own callback function
)

app.add_route("/metrics", handle_openmetrics)


Exemplars are only supported by the openmetrics-text exposition format. A new handle_openmetrics handler function is provided (see above example).

For more information, see the [Grafana exemplar documentation](https://grafana.com/docs/grafana/latest/fundamentals/exemplars/).

0.14.0

This release adds a `labels` argument to PrometheusMiddleware that accepts a dict of labels/values that will be added to all metrics.

Each label's value can be either a static value or, optionally, a callback function that takes the Request instance as its argument and returns a string.

Example:
python
app.add_middleware(
PrometheusMiddleware,
labels={
"service": "api",
"env": os.getenv("ENV"),
"my_header": lambda r: r.headers.get("X-My-Header")
}
)


Reminder: always evaluate the cardinality of sets of labels before using them, and do not use user-supplied values (e.g. untrusted headers) or unconstrained values to populate labels. See this for more information: https://grafana.com/blog/2022/02/15/what-are-cardinality-spikes-and-why-do-they-matter/

Thank you to intelroman for helping contribute to this feature.

Page 2 of 5

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.