Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add example query for HTTP requests duration per percentile #103

Merged
merged 2 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)