diff --git a/docs/images/integrations/use_cases/web_frameworks/logfire-screenshot-chart-percentiles.png b/docs/images/integrations/use_cases/web_frameworks/logfire-screenshot-chart-percentiles.png new file mode 100644 index 00000000..bee4b571 Binary files /dev/null and b/docs/images/integrations/use_cases/web_frameworks/logfire-screenshot-chart-percentiles.png differ diff --git a/docs/integrations/use_cases/web_frameworks.md b/docs/integrations/use_cases/web_frameworks.md index d76a34bd..f7e9c56a 100644 --- a/docs/integrations/use_cases/web_frameworks.md +++ b/docs/integrations/use_cases/web_frameworks.md @@ -41,3 +41,34 @@ To replace the `Authorization` header value with `[REDACTED]` to avoid leaking u ``` OTEL_INSTRUMENTATION_HTTP_CAPTURE_HEADERS_SANITIZE_FIELDS="Authorization" ``` + +## Query HTTP requests duration per percentile + +It's usually interesting to visualize HTTP requests duration per percentile. Instead of having an average, which may be influenced by extreme values, percentiles allow us know the maximum duration for 50%, 90%, 95% or 99% of the requests. + +Here is a sample query to compute those percentiles for HTTP requests duration: + +```sql +WITH dataset AS ( + SELECT + time_bucket('%time_bucket_duration%', start_timestamp) AS x, + (extract(epoch from end_timestamp - start_timestamp) * 1000) as duration_ms + FROM records + WHERE attributes ? 'http.method' +) +SELECT + x, + percentile_cont(0.99) WITHIN GROUP (ORDER BY duration_ms) as percentile_99, + percentile_cont(0.95) WITHIN GROUP (ORDER BY duration_ms) as percentile_95, + percentile_cont(0.90) WITHIN GROUP (ORDER BY duration_ms) as percentile_90, + percentile_cont(0.50) WITHIN GROUP (ORDER BY duration_ms) as percentile_50 +FROM dataset +GROUP BY x +ORDER BY x DESC; +``` + +Notice how we filtered on records that have the `http.method` attributes set. It's a good starting point to retrieve traces that are relevant for HTTP requests, but depending on your setup, you might need to add more filters. + +This query is a good candidate for a Time Series chart in a dashboard: + +![Requests duration per percentile as Time Series chart](../../images/integrations/use_cases/web_frameworks/logfire-screenshot-chart-percentiles.png)