Releases: stephenhillier/starlette_exporter
v0.23.0
Features
Group unhandled paths
You can now get metrics on requests made against unhandled paths (i.e. 404s) using the group_unhandled_paths
option. When this option is set, metrics for unhandled requests will be grouped under the path="__unknown__"
label. From the README:
group_unhandled_paths
: Similar to filter_unhandled_paths
, but instead of ignoring the requests, they are grouped under the __unknown__
path. This option overrides filter_unhandled_paths
by setting it to False
. The default value is False
.
All credit to @piotrhyzy and @Filipoliko!
Bug fixes:
- Fixed a Prometheus client exception that could occur when using the
from_response_header
helper function to create custom labels. Thanks to @lainiwa for reporting an issue.
v0.22.0
from_response_header
: a new helper function for adding metric series labels based on HTTP response header values. See the README for more info. Example:
from starlette_exporter import PrometheusMiddleware, from_header, from_response_header
app.add_middleware(
PrometheusMiddleware,
labels={
"cache": from_response_header("X-FastAPI-Cache", allowed_values=("hit", "miss"))
}
)
Feedback and bug reports welcome - please open an issue.
v0.21.0
You can now access the Request object from an exemplars callback. Example:
def exemplars(r: Request):
return {"trace_id": r.headers.get("x-trace-id", "")}
app.add_middleware(
PrometheusMiddleware,
exemplars=exemplars
)
This will allow you to use header values as exemplars. Note that if you want to use OpenTelemetry traces with exemplars, see this example.
v0.20.0
the skip_paths
option now accepts regular expressions. #89 @bunny-therapist
Notice: most usage of skip_paths should be compatible with regex. If your usage is affected by this change, please update to a regular expression or file an issue.
v0.19.0
Support for uvicorn v0.26.0's updated root_path behavior (see encode/uvicorn#2213). @dolfinus
v0.18.0
v0.17.1
v0.17.0
Changes for v0.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).
Optionally skip methods
v0.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)