Query what you send

Note: Metrics is in open alpha. Any team can turn it on. Open Metrics and select Enable metrics in the onboarding view. The details on this page describe current behavior and may change before general availability.

This page shows how a metric you record with posthog.metrics in posthog-js, posthog-node, or posthog-python reads back when you query it. The most important thing to know first: counters and histograms arrive as deltas, not running totals.

What the SDKs send

The SDKs pre-aggregate in memory and flush one OTLP data point per series every 10 seconds by default. Each type is sent like this:

CallOTLP typeTemporalityWhat one data point holds
metrics.count()Monotonic sumDeltaThe total added in that flush window
metrics.gauge()Gauge–The last value recorded in that window
metrics.histogram()HistogramDeltaThe count, sum, min, max, and per-bucket counts for that window

Delta temporality means each flush carries only what happened in that interval. It isn't a running total since process start. The viewer and its increase and rate aggregations account for this. In PromQL, counters and histograms need different functions, as Query with PromQL explains.

Resource attributes and names

Everything you set in serviceName, environment, serviceVersion, and resourceAttributes becomes an OpenTelemetry resource attribute (service.name, deployment.environment, service.version, plus your own). The SDK also adds telemetry.sdk.* attributes. Attributes you pass on individual calls become data point attributes.

Metric names are sent as you write them, so http.client.request.duration stays dotted. The default name from posthog-js metrics.network and its attributes (url.template, http.request.method) use dotted OpenTelemetry names too.

Default histogram buckets

Histograms use these bucket boundaries, in the unit you record (milliseconds for durations):

text
0, 5, 10, 25, 50, 75, 100, 250, 500, 750, 1000, 2500, 5000, 7500, 10000

There's one more bucket above the last boundary, so values over 10000 are still counted. In posthog-node (5.63.0 or later) and posthog-js (1.447.0 or later), you can pass bounds when you record to use different boundaries:

JavaScript
posthog.metrics.histogram('job.duration', 42, {
unit: 'ms',
bounds: [10, 50, 100, 500, 1000],
})

The first sample of a histogram (its name and unit) fixes the bounds until the client resets. A later sample with different bounds is recorded in the fixed buckets and logs a warning, and a sample with invalid bounds is dropped.

posthog-python has no bounds option. Its histogram() takes only unit and attributes, so Python histograms always use the default boundaries above. If you need other boundaries in Python, record the histogram with an OpenTelemetry SDK instead.

Query with SQL

Every data point lands in the posthog.metrics table, scoped to your project. Use the SQL tab in Metrics to read it back directly. See Use your metrics for the viewer and SQL tab.

Query with PromQL

When you read metrics back as Prometheus series, expect this:

  • A histogram named dash_query_duration_ms reads back as dash_query_duration_ms_bucket, dash_query_duration_ms_count, and dash_query_duration_ms_sum, plus a bare dash_query_duration_ms series.
  • A counter keeps its name. PostHog doesn't add _total.
  • Resource attributes become labels, so you can filter on service_name or region (from resourceAttributes). Each series carries both the dotted OpenTelemetry label (service.name) and an underscore form (service_name), plus job (set to the service name), deployment.environment, and telemetry.sdk.*.
  • Dotted metric and label names work as you write them, for example http.client.request.duration_count{service.name="checkout"} or sum by (url.template, le). Quoted forms such as {"deployment.environment"="production"} work too. Use the quoted form if another tool parses the query before it reaches PostHog, because a standard Prometheus parser rejects bare dots.

Counters and histograms read back differently:

TypeWhat PromQL readsUseDon't use
CounterEach delta as its own samplesum_over_time()rate(), increase()
Histogram (_bucket, _count, _sum)A running total of the deltas, from the start of the query rangerate(), increase()sum_over_time()
GaugeThe last value in each windowThe value as is, or avg_over_time()–

Counters: sum the deltas

Because each counter point is a delta, rate() and increase() give wrong answers without an error. Sum the points instead:

promql
sum_over_time(checkout_completed{plan="pro"}[$__interval])

Histograms: use rate() or increase()

PostHog turns the delta points of a histogram into a running total when it builds the _bucket, _count, and _sum series. Use them like Prometheus counters:

promql
histogram_quantile(
0.95,
sum by (le) (rate(dash_query_duration_ms_bucket[5m]))
)

For the average duration, divide the increase of _sum by the increase of _count:

promql
sum(increase(dash_query_duration_ms_sum[5m]))
/ sum(increase(dash_query_duration_ms_count[5m]))

Don't use sum_over_time() on these series. It adds up running totals, so the result grows over the query range.

Gauges

A gauge is the last value in each window, so you can query it as is, or smooth it:

promql
avg_over_time(queue_depth{service_name="billing-worker"}[5m])

Still have questions?

Was this page useful?