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

How to visualise or access manual metrics #633

Open
satwikkansal opened this issue Nov 29, 2024 · 3 comments
Open

How to visualise or access manual metrics #633

satwikkansal opened this issue Nov 29, 2024 · 3 comments
Labels
Question Further information is requested

Comments

@satwikkansal
Copy link

Question

I'm recording some values using logfire.metric_histogram method, where exactly can I access these values in Logfire UI (or data tables). And does logfire have capability to plot them on logfire dashboard? If so, how do I go about doing that. Any help will be appreciated!

@satwikkansal satwikkansal added the Question Further information is requested label Nov 29, 2024
@alexmojaki
Copy link
Contributor

You can use them by querying the metrics table in the explore view, dashboards, and alerts. We still need to work on making this easier. Here's an example:

import logfire

logfire.configure()

hist = logfire.metric_histogram("my_little_histogram2")

for i in range(10):
    for j in range(100):
        hist.record(i * 100 + j)
    logfire.force_flush()  # export a batch of metrics

There's some summary statistics associated with histograms which are easy to work with:

select histogram_min, histogram_max, histogram_count, histogram_sum
from metrics
where metric_name = 'my_little_histogram2'
order by histogram_min
Screenshot 2024-12-04 at 14 54 05
select min(histogram_min), max(histogram_max), sum(histogram_count), sum(histogram_sum)
from metrics
where metric_name = 'my_little_histogram2'
order by min(histogram_min)
Screenshot 2024-12-04 at 14 54 48

The raw data in histogram buckets is stored in a way that is quite difficult to extract, we definitely need to expose this as a user-friendly view:

with indices as (
    select *, unnest(generate_series(1, array_length(exp_histogram_positive_bucket_counts, 1)::integer)) AS bucket_index
    from metrics
),
counts as (
    select *, exp_histogram_positive_bucket_counts[bucket_index] as bucket_count
    from indices
),
bounds as (
    select
        *,
        power(2, (exp_histogram_positive_bucket_counts_offset+bucket_index-1)/power(2.0, exp_histogram_scale)) as lower_bound,
        power(2, (exp_histogram_positive_bucket_counts_offset+bucket_index  )/power(2.0, exp_histogram_scale)) as upper_bound
    from counts
    where bucket_count > 0
)
select lower_bound, upper_bound, bucket_count from bounds
where metric_name = 'my_little_histogram2'
order by lower_bound

Each row here says that there are bucket_count values between lower_bound and upper_bound inclusive.

Unfortunately we also don't currently have a way to plot these histogram buckets in a dashboard.

@satwikkansal
Copy link
Author

I see, thanks! Is it possible to query them in some way via Python?

@alexmojaki
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants