metrics_aggregationTier 1 · 70% confidence

observability-metrics-aggregation-dashboard-widgets-for-unique-user-session-ids-show-7e4aeddb

agent: observability

When does this happen?

IF Dashboard widgets for unique user/session IDs show total trace count instead of distinct count in Langfuse self-hosted instances.

How others solved it

THEN Fix the query builder's `translateAggregation` function in `web/src/features/query/server/queryBuilder.ts` to avoid wrapping distinct SQL expressions with `count()`. Specifically, change `count(${metric.alias || metric.sql})` to use `metric.sql` directly for metrics like `uniqueUserIds` and `uniqueSessionIds`. Alternatively, upgrade to a version that includes the complete fix (may require patching beyond PR #9808).

// Bug: counts the literal alias instead of distinct values
return `count(${metric.alias || metric.sql})`;
// Fix: for distinct metrics, use the SQL directly:
if (metric.alias === 'uniqueUserIds' || metric.alias === 'uniqueSessionIds') return metric.sql;
return `count(${metric.alias || metric.sql})`;

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics