Skip to content

Commit

Permalink
docs: add example query for HTTP requests duration per percentile (#103)
Browse files Browse the repository at this point in the history
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
  • Loading branch information
frankie567 and Kludex authored May 6, 2024
1 parent cc8a7f9 commit d2e687d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions docs/integrations/use_cases/web_frameworks.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit d2e687d

Please sign in to comment.