Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(billing): read usage counters from real-time records (#105356)

Alex Mays00c70a7bd3e5
diff --git a/docs/internal/feature-flags/billing.md b/docs/internal/feature-flags/billing.md
index 1b929faa8e5a..14f76b4279e0 100644
--- a/docs/internal/feature-flags/billing.md
+++ b/docs/internal/feature-flags/billing.md
@@ -227,6 +227,37 @@ The usage report task queries ClickHouse for aggregated billing data.
**Source file:** `posthog/tasks/usage_report.py`
+Daily reports, usage reports v2, and quota limiting read the billed request counters through `posthog.usage_counters.UsageCounterService`.
+Each counter's feature flag selects `legacy`, `both`, or `realtime`.
+A counter in `RECORD_REALTIME_BLOCKERS` resolves `realtime` to `both` until its producer discrepancy is resolved or confirmed as intended billing behavior.
+All record-backed counters are guarded for the initial comparison rollout.
+These guards cover event, enhanced-person, and exception timestamp attribution, Django local-evaluation requests, replay sessions, and workflow invocations.
+Feature-flag request records use Rust flush time, while legacy billing events use the later Celery export time.
+That counter remains guarded until cutover reconciles requests across those dates.
+CDP and workflow dispatches use independent flush-time clocks for legacy app metrics and usage records.
+Their counters remain guarded until cutover reconciles dispatches across those dates.
+They also cover producer gaps in the exemptions for product-tour survey responses, wallet-billed AI gateway events, and sponsored relay events.
+Guarded counters still collect comparisons while legacy totals remain authoritative.
+`legacy` queries billing events. `both` queries billing events and `billing_usage_records`, and keeps the legacy count authoritative.
+`realtime` uses the usage record count. A report for a complete day also queries billing events, for the comparison. Each caller states whether its period is a complete day. The daily report and finalized usage reports v2 runs pass a complete day. Intraday usage reports v2 runs and quota limiting pass a partial day and skip that query.
+Reports retain both totals in `counter_comparisons` for every counter that ran both queries. Both totals count each team under its current organization, the same as the report fields. A failed comparison query omits that counter's pair. A failure in a query needed for normal report fields still fails the report.
+The usage record query checks units separately for each usage key and discards all totals for a key with incompatible units.
+A mismatch in a comparison-only source omits that counter's pair and records a shadow validation failure; other counters remain available.
+A mismatch in a source used for a realtime total fails the report.
+Removing the complete-day legacy query will be a later code change.
+The mode selects the authoritative count for every caller and time window.
+Each run keeps its resolved plan, and flag lookups are cached for 60 seconds per process.
+Usage reports v2 saves each completed legacy query in S3 under its workflow run.
+Each legacy counter runs in its own activity, sharing the workflow's four-query limit with other queries.
+Activity retries reuse checkpoints and rerun only unfinished legacy queries.
+The counter-report activity reads those checkpoints before its shared usage-record scan, without rerunning legacy queries.
+Cancellation stops the counter worker between queries and before checkpoint or report writes; an in-flight query or write can still finish.
+Usage reports v2 records query latency and failures under the existing query names, plus `usage_records` for the shared scan and `usage_counters` for the combined activity.
+A failed counter activity or remaining query fails the workflow without waiting for the other queries to finish.
+Quota runs log resolved sources as `usage_counter_sources` and successful comparisons as `usage_counter_comparison`.
+Each comparison includes both totals, the number of differing teams, and the sum of absolute differences, so opposite discrepancies cannot cancel each other out.
+Missing-organization diagnostics use size-bounded events. Temporal runs their capture and flush outside the event loop.
+
### Billable calculation
Local evaluation requests are weighted 10x compared to decide requests:
@@ -242,7 +273,7 @@ This reflects the higher resource cost of local evaluation requests, which retur
### Token validation
-Queries filter events by the billing token to ensure only legitimate usage events are counted:
+Legacy queries filter events by the billing token to ensure only legitimate usage events are counted:
```sql
AND has([%(validity_token)s], replaceRegexpAll(JSONExtractRaw(properties, 'token'), '^"|"$', ''))
diff --git a/ee/billing/quota_limiting.py b/ee/billing/quota_limiting.py
index 4f7cd3138bce..2f6241b86656 100644
--- a/ee/billing/quota_limiting.py
+++ b/ee/billing/quota_limiting.py
@@ -18,7 +18,7 @@ import posthoganalytics
from posthog.cache_utils import cache_for
from posthog.clickhouse.query_tagging import Feature, Product, tag_queries
-from posthog.constants import AvailableFeature, FlagRequestType
+from posthog.constants import AvailableFeature
from posthog.dataclasses import frozen
from posthog.event_usage import report_organization_action
from posthog.exceptions_capture import capture_exception
@@ -30,26 +30,9 @@ from posthog.tasks.usage_report import (
convert_team_usage_rows_to_dict,
get_self_driving_credits_used_in_period_for_org,
get_signals_credited_refund_credits_for_org,
- get_teams_with_ai_credits_used_in_period,
- get_teams_with_ai_event_count_in_period,
get_teams_with_api_queries_metrics,
- get_teams_with_billable_event_count_in_period,
- get_teams_with_billable_sandbox_compute_usage_in_period,
- get_teams_with_cdp_billable_invocations_in_period,
- get_teams_with_exceptions_captured_in_period,
- get_teams_with_feature_flag_requests_count_in_period,
- get_teams_with_logs_bytes_in_period,
- get_teams_with_posthog_code_credits_used_in_period,
- get_teams_with_recording_count_in_period,
- get_teams_with_replay_vision_credits_used_in_period,
- get_teams_with_rows_exported_in_period,
- get_teams_with_rows_synced_in_period,
- get_teams_with_signals_credits_used_in_period,
- get_teams_with_survey_responses_count_in_period,
- get_teams_with_workflow_billable_invocations_in_period,
- get_teams_with_workflow_emails_sent_in_period,
- get_teams_with_workflow_push_sent_in_period,
)
+from posthog.usage_counters import UsageCounter, UsageCounterService, log_usage_counter_comparisons
from posthog.utils import get_current_day
logger = structlog.get_logger(__name__)
@@ -1211,115 +1194,84 @@ def update_all_orgs_billing_quotas(
"""
total_start = time()
period = get_current_day()
+ service = UsageCounterService()
+ plan = service.resolve_plan(
+ period,
+ caller="quota_limiting",
+ complete=False,
+ counters=(
+ UsageCounter.EVENTS,
+ UsageCounter.EXCEPTIONS,
+ UsageCounter.RECORDINGS,
+ UsageCounter.FEATURE_FLAG_REQUESTS,
+ UsageCounter.FEATURE_FLAG_LOCAL_EVALUATION_REQUESTS,
+ UsageCounter.CDP_INVOCATIONS,
+ UsageCounter.SURVEY_RESPONSES,
+ UsageCounter.AI_EVENTS,
+ UsageCounter.WORKFLOW_EMAILS,
+ UsageCounter.WORKFLOW_PUSH,
+ UsageCounter.WORKFLOW_INVOCATIONS,
+ UsageCounter.ROWS_SYNCED,
+ UsageCounter.ROWS_EXPORTED,
+ UsageCounter.LOGS_BYTES,
+ UsageCounter.AI_CREDITS,
+ UsageCounter.SIGNALS_CREDITS,
+ UsageCounter.POSTHOG_CODE_CREDITS,
+ UsageCounter.SANDBOX_COMPUTE_CREDITS,
+ UsageCounter.REPLAY_VISION_CREDITS,
+ ),
+ )
tag_queries(product=Product.BILLING, feature=Feature.QUOTA_LIMITING)
logger.info("quota_limiting_run", phase="queries", status="start")
queries_start = time()
+ counter_report = _timed_query("usage_counters", service.fetch_report, period, plan=plan)
+ log_usage_counter_comparisons(counter_report, caller="quota_limiting", date=period.start.date().isoformat())
api_queries_usage = _timed_query(
"api_queries_metrics", get_teams_with_api_queries_metrics, period.start, period.end
)
- _, exception_metrics = _timed_query(
- "exceptions_captured", get_teams_with_exceptions_captured_in_period, period.start, period.end
- )
- token_credits = convert_team_usage_rows_to_dict(
- _timed_query(
- "posthog_code_token_credits",
- get_teams_with_posthog_code_credits_used_in_period,
- period.start,
- period.end,
- )
- )
- sandbox_compute_usage = _timed_query(
- "sandbox_compute", get_teams_with_billable_sandbox_compute_usage_in_period, period.start, period.end
- )
- compute_credits = convert_team_usage_rows_to_dict(sandbox_compute_usage.credits)
+ token_credits = dict(counter_report.counts[UsageCounter.POSTHOG_CODE_CREDITS])
+ compute_credits = dict(counter_report.counts[UsageCounter.SANDBOX_COMPUTE_CREDITS])
# Clickhouse is good at counting things so we count across all teams rather than doing it one by one
all_data = {
- "teams_with_event_count_in_period": convert_team_usage_rows_to_dict(
- _timed_query("billable_events", get_teams_with_billable_event_count_in_period, period.start, period.end)
- ),
- "teams_with_exceptions_captured_in_period": convert_team_usage_rows_to_dict(exception_metrics),
- "teams_with_recording_count_in_period": convert_team_usage_rows_to_dict(
- _timed_query("recordings", get_teams_with_recording_count_in_period, period.start, period.end)
- ),
- "teams_with_rows_synced_in_period": convert_team_usage_rows_to_dict(
- _timed_query("rows_synced", get_teams_with_rows_synced_in_period, period.start, period.end)
- ),
- "teams_with_decide_requests_count": convert_team_usage_rows_to_dict(
- _timed_query(
- "decide_requests",
- get_teams_with_feature_flag_requests_count_in_period,
- period.start,
- period.end,
- FlagRequestType.DECIDE,
- )
- ),
- "teams_with_local_evaluation_requests_count": convert_team_usage_rows_to_dict(
- _timed_query(
- "local_evaluation_requests",
- get_teams_with_feature_flag_requests_count_in_period,
- period.start,
- period.end,
- FlagRequestType.LOCAL_EVALUATION,
- )
+ "teams_with_event_count_in_period": dict(counter_report.counts[UsageCounter.EVENTS]),
+ "teams_with_exceptions_captured_in_period": dict(counter_report.counts[UsageCounter.EXCEPTIONS]),
+ "teams_with_recording_count_in_period": dict(counter_report.counts[UsageCounter.RECORDINGS]),
+ "teams_with_rows_synced_in_period": dict(counter_report.counts[UsageCounter.ROWS_SYNCED]),
+ "teams_with_decide_requests_count": dict(counter_report.counts[UsageCounter.FEATURE_FLAG_REQUESTS]),
+ "teams_with_local_evaluation_requests_count": dict(
+ counter_report.counts[UsageCounter.FEATURE_FLAG_LOCAL_EVALUATION_REQUESTS]
),
"teams_with_api_queries_read_bytes": convert_team_usage_rows_to_dict(api_queries_usage["read_bytes"]),
- "teams_with_cdp_trigger_events_metrics": convert_team_usage_rows_to_dict(
- _timed_query("cdp_invocations", get_teams_with_cdp_billable_invocations_in_period, period.start, period.end)
- ),
- "teams_with_rows_exported_in_period": convert_team_usage_rows_to_dict(
- _timed_query("rows_exported", get_teams_with_rows_exported_in_period, period.start, period.end)
- ),
- "teams_with_survey_responses_count_in_period": convert_team_usage_rows_to_dict(
- _timed_query("survey_responses", get_teams_with_survey_responses_count_in_period, period.start, period.end)
- ),
- "teams_with_ai_event_count_in_period": convert_team_usage_rows_to_dict(
- _timed_query("ai_events", get_teams_with_ai_event_count_in_period, period.start, period.end)
- ),
- "teams_with_ai_credits_used_in_period": convert_team_usage_rows_to_dict(
- _timed_query("ai_credits", get_teams_with_ai_credits_used_in_period, period.start, period.end)
- ),
- "teams_with_signals_credits_used_in_period": convert_team_usage_rows_to_dict(
- _timed_query("signals_credits", get_teams_with_signals_credits_used_in_period, period.start, period.end)
- ),
+ "teams_with_cdp_trigger_events_metrics": dict(counter_report.counts[UsageCounter.CDP_INVOCATIONS]),
+ "teams_with_rows_exported_in_period": dict(counter_report.counts[UsageCounter.ROWS_EXPORTED]),
+ "teams_with_survey_responses_count_in_period": dict(counter_report.counts[UsageCounter.SURVEY_RESPONSES]),
+ "teams_with_ai_event_count_in_period": dict(counter_report.counts[UsageCounter.AI_EVENTS]),
+ "teams_with_ai_credits_used_in_period": dict(counter_report.counts[UsageCounter.AI_CREDITS]),
+ "teams_with_signals_credits_used_in_period": dict(counter_report.counts[UsageCounter.SIGNALS_CREDITS]),
"teams_with_posthog_code_credits_used_in_period": {
team_id: combine_posthog_code_credits(token_credits.get(team_id, 0), compute_credits.get(team_id, 0))
for team_id in token_credits.keys() | compute_credits.keys()
},
"teams_with_posthog_code_token_credits_used_in_period": token_credits,
"teams_with_sandbox_compute_credits_used_in_period": compute_credits,
- "teams_with_sandbox_compute_cpu_millicore_seconds_in_period": convert_team_usage_rows_to_dict(
- sandbox_compute_usage.cpu_millicore_seconds
+ "teams_with_sandbox_compute_cpu_millicore_seconds_in_period": dict(
+ counter_report.counts["teams_with_sandbox_compute_cpu_millicore_seconds_in_period"]
),
- "teams_with_sandbox_compute_memory_mib_seconds_in_period": convert_team_usage_rows_to_dict(
- sandbox_compute_usage.memory_mib_seconds
+ "teams_with_sandbox_compute_memory_mib_seconds_in_period": dict(
+ counter_report.counts["teams_with_sandbox_compute_memory_mib_seconds_in_period"]
),
- "teams_with_workflow_emails_sent_in_period": convert_team_usage_rows_to_dict(
- _timed_query("workflow_emails", get_teams_with_workflow_emails_sent_in_period, period.start, period.end)
- ),
- "teams_with_workflow_push_sent_in_period": convert_team_usage_rows_to_dict(
- _timed_query("workflow_push", get_teams_with_workflow_push_sent_in_period, period.start, period.end)
- ),
- "teams_with_workflow_destinations_in_period": convert_team_usage_rows_to_dict(
- _timed_query(
- "workflow_invocations", get_teams_with_workflow_billable_invocations_in_period, period.start, period.end
- )
- ),
- "teams_with_replay_vision_credits_used_in_period": convert_team_usage_rows_to_dict(
- _timed_query(
- "replay_vision_credits",
- get_teams_with_replay_vision_credits_used_in_period,
- period.start,
- period.end,
- )
+ "teams_with_workflow_emails_sent_in_period": dict(counter_report.counts[UsageCounter.WORKFLOW_EMAILS]),
+ "teams_with_workflow_push_sent_in_period": dict(counter_report.counts[UsageCounter.WORKFLOW_PUSH]),
+ "teams_with_workflow_destinations_in_period": dict(counter_report.counts[UsageCounter.WORKFLOW_INVOCATIONS]),
+ "teams_with_replay_vision_credits_used_in_period": dict(
+ counter_report.counts[UsageCounter.REPLAY_VISION_CREDITS]
),
"teams_with_logs_mb_in_period": {
team_id: int(bytes_val // 1_000_000)
- for team_id, bytes_val in convert_team_usage_rows_to_dict(
- _timed_query("logs_bytes", get_teams_with_logs_bytes_in_period, period.start, period.end)
- ).items()
+ for team_id, bytes_val in counter_report.counts[UsageCounter.LOGS_BYTES]
},
}
diff --git a/ee/billing/test/test_quota_limiting.py b/ee/billing/test/test_quota_limiting.py
index bdc6c65313ae..106cd51eb668 100644
--- a/ee/billing/test/test_quota_limiting.py
+++ b/ee/billing/test/test_quota_limiting.py
@@ -4,7 +4,7 @@ from uuid import uuid4
import time_machine
from posthog.test.base import BaseTest, FuzzyInt, _create_event, flush_persons_and_events
-from unittest.mock import patch
+from unittest.mock import ANY, patch
from django.apps import apps
from django.db import DatabaseError
@@ -16,9 +16,11 @@ from dateutil.relativedelta import relativedelta
from parameterized import parameterized
from posthog.api.test.test_team import create_team
+from posthog.constants import FlagRequestType
from posthog.models.organization import Organization
from posthog.models.team.team import Team
from posthog.redis import get_client
+from posthog.usage_counters import UsageRecordTotal, UsageRecordTotals
from ee.billing.quota_limiting import (
INFORMATIONAL_USAGE_RESOURCES,
@@ -109,7 +111,30 @@ class TestQuotaLimiting(BaseTest):
org_id = str(self.organization.id)
flush_persons_and_events()
- result = update_all_orgs_billing_quotas()
+ with (
+ self.settings(USAGE_COUNTER_REALTIME_MODES="events:both"),
+ patch(
+ "posthog.tasks.usage_report.get_usage_records_in_period",
+ return_value=UsageRecordTotals(
+ totals=[
+ UsageRecordTotal(team_id=self.team.id, organization_id=org_id, usage_key="events", quantity=3)
+ ]
+ ),
+ ),
+ patch("posthog.usage_counters.logger.info") as counter_log,
+ ):
+ result = update_all_orgs_billing_quotas()
+ counter_log.assert_any_call(
+ "usage_counter_comparison",
+ caller="quota_limiting",
+ date="2021-01-25",
+ counter="event_count_in_period",
+ source="both",
+ legacy=ANY,
+ realtime=3,
+ differing_teams=ANY,
+ absolute_difference=ANY,
+ )
# feature_enabled will be called for AI billing check and then for data retention flag
patch_feature_enabled.assert_any_call(
QUOTA_LIMIT_DATA_RETENTION_FLAG,
@@ -301,6 +326,42 @@ class TestQuotaLimiting(BaseTest):
assert self.redis_client.zrange(f"@posthog/quota-limits/survey_responses", 0, -1) == []
assert self.redis_client.zrange(f"@posthog/quota-limits/rows_exported", 0, -1) == []
+ @patch("posthoganalytics.capture")
+ def test_todays_usage_reads_every_legacy_row_shape(self, _capture) -> None:
+ def flag_requests(_begin, _end, request_type):
+ return [(str(self.team.id), 7 if request_type == FlagRequestType.DECIDE else 2)]
+
+ with (
+ self.settings(USE_TZ=False),
+ time_machine.travel("2021-01-25T00:00:00Z", tick=False),
+ patch(
+ "posthog.tasks.usage_report.get_teams_with_feature_flag_requests_count_in_period",
+ side_effect=flag_requests,
+ ),
+ patch(
+ "posthog.tasks.usage_report.get_teams_with_rows_synced_in_period",
+ return_value=[{"team_id": self.team.id, "total": 5}],
+ ),
+ patch(
+ "posthog.tasks.usage_report.get_teams_with_rows_exported_in_period",
+ return_value=[{"team_id": self.team.id, "total": 3}],
+ ),
+ ):
+ self.organization.usage = {
+ "period": ["2021-01-01T00:00:00Z", "2021-01-31T23:59:59Z"],
+ "feature_flag_requests": {"usage": 0, "limit": None, "todays_usage": 0},
+ "rows_synced": {"usage": 0, "limit": None, "todays_usage": 0},
+ "rows_exported": {"usage": 0, "limit": None, "todays_usage": 0},
+ }
+ self.organization.save()
+ update_all_orgs_billing_quotas()
+
+ self.organization.refresh_from_db()
+ assert self.organization.usage is not None
+ assert self.organization.usage["feature_flag_requests"]["todays_usage"] == 7 + 2 * 10
+ assert self.organization.usage["rows_synced"]["todays_usage"] == 5
+ assert self.organization.usage["rows_exported"]["todays_usage"] == 3
+
@patch("posthoganalytics.capture")
def test_billing_rate_limit(self, patch_capture) -> None:
def create_usage_summary(**kwargs) -> dict[str, Any]:
@@ -3184,7 +3245,7 @@ class TestRefreshOrgSelfDrivingQuota(BaseTest):
)
with (
patch(
- "ee.billing.quota_limiting.get_teams_with_signals_credits_used_in_period",
+ "posthog.tasks.usage_report.get_teams_with_signals_credits_used_in_period",
return_value=[(self.team.id, 100)],
),
patch(
@@ -3234,7 +3295,7 @@ class TestRefreshOrgSelfDrivingQuota(BaseTest):
with (
patch("ee.billing.quota_limiting.list_limited_team_attributes", side_effect=snapshot) as snapshot_mock,
- patch("ee.billing.quota_limiting.get_teams_with_signals_credits_used_in_period", return_value=[]),
+ patch("posthog.tasks.usage_report.get_teams_with_signals_credits_used_in_period", return_value=[]),
patch("ee.billing.quota_limiting.get_self_driving_credits_used_in_period_for_org", return_value=0),
):
update_all_orgs_billing_quotas()
diff --git a/nodejs/src/ingestion/common/steps/usage-records-steps.test.ts b/nodejs/src/ingestion/common/steps/usage-records-steps.test.ts
index dce355b659a4..d277e82b9516 100644
--- a/nodejs/src/ingestion/common/steps/usage-records-steps.test.ts
+++ b/nodejs/src/ingestion/common/steps/usage-records-steps.test.ts
@@ -43,7 +43,13 @@ describe('usage-records-steps', () => {
async function queueEventUsage(
ingested: Promise<IngestedEventInfo | null>[],
- event: Partial<{ event: string; eventUuid: string; distinctId: string; properties: Properties }> = {},
+ event: Partial<{
+ event: string
+ eventUuid: string
+ distinctId: string
+ timestamp: string
+ properties: Properties
+ }> = {},
personProcessing: { processPerson?: boolean; person?: Person } = {},
headers: { now?: Date } = {}
): Promise<void> {
@@ -169,20 +175,28 @@ describe('usage-records-steps', () => {
])
})
- it('uses trusted capture time when an event flushes six hours later', async () => {
- const capturedAtMs = FLUSH_TIMESTAMP_MS
+ it.each([
+ ['same day', '2026-07-01T00:01:00.000Z'],
+ ['closed month', '2026-05-15T12:00:00.000Z'],
+ ['future source date', '2026-08-01T00:00:00.000Z'],
+ ])('bills receipt time and preserves the source date for %s', async (_name, timestamp) => {
+ const capturedAtMs = Date.parse('2026-07-01T23:59:00.000Z')
jest.setSystemTime(capturedAtMs)
await queueEventUsage(
[Promise.resolve({ topic: 'events', partition: 0 })],
- {},
- {},
+ { timestamp },
+ { processPerson: true },
{ now: new Date(capturedAtMs) }
)
jest.advanceTimersByTime(6 * 60 * 60 * 1000)
await eventUsageBatch.flush()
- expect(ingestedUsage[0]).toEqual(expect.objectContaining({ timestampMs: capturedAtMs }))
+ expect(ingestedUsage.map((record) => record.usageKey)).toEqual(['events', 'enhanced_person_events'])
+ for (const record of ingestedUsage) {
+ expect(record.timestampMs).toBe(capturedAtMs)
+ expect(record.recordId).toMatch(new RegExp(`^${timestamp.slice(0, 10)}:[0-9a-f]{32}$`))
+ }
})
// The meters have to match `person_mode` in the nightly report's two billable-event queries,
diff --git a/nodejs/src/ingestion/common/steps/usage-records-steps.ts b/nodejs/src/ingestion/common/steps/usage-records-steps.ts
index aa5afb3f205c..ab0c894083f1 100644
--- a/nodejs/src/ingestion/common/steps/usage-records-steps.ts
+++ b/nodejs/src/ingestion/common/steps/usage-records-steps.ts
@@ -50,7 +50,7 @@ export interface RecordEventUsageInput {
* Hashed rather than joined: event names and distinct IDs are client-supplied and together
* exceed the 512-byte identifier the service accepts, and one oversized record makes the
* service reject the whole request. The timestamp is UTC-normalized upstream, so its first
- * ten characters are the day `toDate` resolves in the billing table's sorting key.
+ * ten characters are the source day used in the events table's sorting key.
*/
function hashedRecordId(timestamp: string, identity: string[]): string {
const day = timestamp.slice(0, 10)
@@ -106,15 +106,9 @@ export interface EventUsageRecordContext {
* separates, and it waits on the same acknowledgement: an event that never lands should not bill
* for the person work either.
*
- * TODO: decide how usage records should treat events dated in the past. This step bills every
- * billable event at the moment it is processed, including a historical migration. The nightly
- * report does not: `get_teams_with_billable_event_count_in_period` filters the events table on
- * the event's own `timestamp`, so an event backdated outside the current period lands in a
- * period that has already been billed and is charged for nowhere. The two systems therefore
- * disagree on exactly the imports customers run deliberately, and the choice — bill regardless
- * of event age, or mirror the report and skip old events — is a pricing decision rather than an
- * implementation one. `historicalMigration` is available upstream in the pipeline if we pick
- * the second.
+ * Capture time assigns usage to the period that receives it, including historical imports.
+ * Source event time cannot move newly received usage into a closed billing period.
+ * The record ID retains the source date for event identity and comparison with legacy reports.
*/
export function createRecordEventUsageStep<T extends RecordEventUsageInput>(
resolveUsageKey: UsageKeyResolver
diff --git a/posthog/settings/payments.py b/posthog/settings/payments.py
index ff78ae2cef03..e674c0b70837 100644
--- a/posthog/settings/payments.py
+++ b/posthog/settings/payments.py
@@ -1,3 +1,4 @@
from posthog.settings.utils import get_from_env
STRIPE_PUBLIC_KEY = get_from_env("STRIPE_PUBLIC_KEY", None, optional=True)
+USAGE_COUNTER_REALTIME_MODES = get_from_env("USAGE_COUNTER_REALTIME_MODES", "")
diff --git a/posthog/tasks/test/__snapshots__/test_usage_report.ambr b/posthog/tasks/test/__snapshots__/test_usage_report.ambr
index dbf4a52f00ed..ffb9598c5a37 100644
--- a/posthog/tasks/test/__snapshots__/test_usage_report.ambr
+++ b/posthog/tasks/test/__snapshots__/test_usage_report.ambr
@@ -3,170 +3,66 @@
'''
SELECT team_id,
- multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node-mcp', 'node_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python-mcp', 'python_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-edge', 'edge_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-convex', 'convex_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-kmp', 'kmp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rails', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-aspnetcore', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,
- count(1) as count
- FROM events PREWHERE timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 02:00:00'
- WHERE (event LIKE 'helicone%'
- OR event LIKE 'langfuse%'
- OR event LIKE 'keywords_ai%'
- OR event LIKE 'traceloop%'
- OR replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('web',
- 'js',
- 'posthog-node',
- 'posthog-node-mcp',
- 'posthog-python-mcp',
- 'posthog-edge',
- 'posthog-convex',
- 'posthog-android',
- 'posthog-kmp',
- 'posthog-flutter',
- 'posthog-ios',
- 'posthog-go',
- 'posthog-java',
- 'posthog-server',
- 'posthog-react-native',
- 'posthog-ruby',
- 'posthog-rails',
- 'posthog-python',
- 'posthog-php',
- 'posthog-dotnet',
- 'posthog-aspnetcore',
- 'posthog-elixir',
- 'posthog-unity',
- 'posthog-rs'))
- GROUP BY team_id,
- metric
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events
+ WHERE timestamp >= '2022-01-10 00:00:00'
+ AND timestamp < '2022-01-10 02:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.1
'''
SELECT team_id,
- multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node-mcp', 'node_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python-mcp', 'python_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-edge', 'edge_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-convex', 'convex_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-kmp', 'kmp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rails', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-aspnetcore', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,
- count(1) as count
- FROM events PREWHERE timestamp >= '2022-01-10 02:00:00'
- AND timestamp < '2022-01-10 04:00:00'
- WHERE (event LIKE 'helicone%'
- OR event LIKE 'langfuse%'
- OR event LIKE 'keywords_ai%'
- OR event LIKE 'traceloop%'
- OR replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('web',
- 'js',
- 'posthog-node',
- 'posthog-node-mcp',
- 'posthog-python-mcp',
- 'posthog-edge',
- 'posthog-convex',
- 'posthog-android',
- 'posthog-kmp',
- 'posthog-flutter',
- 'posthog-ios',
- 'posthog-go',
- 'posthog-java',
- 'posthog-server',
- 'posthog-react-native',
- 'posthog-ruby',
- 'posthog-rails',
- 'posthog-python',
- 'posthog-php',
- 'posthog-dotnet',
- 'posthog-aspnetcore',
- 'posthog-elixir',
- 'posthog-unity',
- 'posthog-rs'))
- GROUP BY team_id,
- metric
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events
+ WHERE timestamp >= '2022-01-10 02:00:00'
+ AND timestamp < '2022-01-10 04:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.10
'''
SELECT team_id,
- multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node-mcp', 'node_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python-mcp', 'python_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-edge', 'edge_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-convex', 'convex_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-kmp', 'kmp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rails', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-aspnetcore', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,
- count(1) as count
- FROM events PREWHERE timestamp >= '2022-01-10 20:00:00'
- AND timestamp < '2022-01-10 22:00:00'
- WHERE (event LIKE 'helicone%'
- OR event LIKE 'langfuse%'
- OR event LIKE 'keywords_ai%'
- OR event LIKE 'traceloop%'
- OR replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('web',
- 'js',
- 'posthog-node',
- 'posthog-node-mcp',
- 'posthog-python-mcp',
- 'posthog-edge',
- 'posthog-convex',
- 'posthog-android',
- 'posthog-kmp',
- 'posthog-flutter',
- 'posthog-ios',
- 'posthog-go',
- 'posthog-java',
- 'posthog-server',
- 'posthog-react-native',
- 'posthog-ruby',
- 'posthog-rails',
- 'posthog-python',
- 'posthog-php',
- 'posthog-dotnet',
- 'posthog-aspnetcore',
- 'posthog-elixir',
- 'posthog-unity',
- 'posthog-rs'))
- GROUP BY team_id,
- metric
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events
+ WHERE timestamp >= '2022-01-10 20:00:00'
+ AND timestamp < '2022-01-10 22:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.11
'''
SELECT team_id,
- multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node-mcp', 'node_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python-mcp', 'python_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-edge', 'edge_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-convex', 'convex_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-kmp', 'kmp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rails', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-aspnetcore', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,
- count(1) as count
- FROM events PREWHERE timestamp >= '2022-01-10 22:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- WHERE (event LIKE 'helicone%'
- OR event LIKE 'langfuse%'
- OR event LIKE 'keywords_ai%'
- OR event LIKE 'traceloop%'
- OR replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('web',
- 'js',
- 'posthog-node',
- 'posthog-node-mcp',
- 'posthog-python-mcp',
- 'posthog-edge',
- 'posthog-convex',
- 'posthog-android',
- 'posthog-kmp',
- 'posthog-flutter',
- 'posthog-ios',
- 'posthog-go',
- 'posthog-java',
- 'posthog-server',
- 'posthog-react-native',
- 'posthog-ruby',
- 'posthog-rails',
- 'posthog-python',
- 'posthog-php',
- 'posthog-dotnet',
- 'posthog-aspnetcore',
- 'posthog-elixir',
- 'posthog-unity',
- 'posthog-rs'))
- GROUP BY team_id,
- metric
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events
+ WHERE timestamp >= '2022-01-10 22:00:00'
+ AND timestamp < '2022-01-10 23:59:59'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.12
'''
SELECT team_id,
- uniqExact(tuple(toDate(timestamp), cityHash64(distinct_id), cityHash64(uuid))) AS count
- FROM events PREWHERE timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- WHERE event = '$mcp_tool_call'
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events
+ WHERE timestamp >= '2022-01-10 00:00:00'
+ AND timestamp < '2022-01-10 02:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND person_mode IN ('full',
+ 'force_upgrade')
GROUP BY team_id
'''
# ---
@@ -174,367 +70,434 @@
'''
SELECT team_id,
- replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') AS sdk_lib,
- replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') AS ai_lib,
- count(1) as count
- FROM events PREWHERE timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 02:00:00'
- AND startsWith(event, '$ai_')
- WHERE replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('posthog-node',
- 'posthog-python',
- 'posthog-dotnet',
- 'posthog-aspnetcore')
- AND replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') IN ('posthog-openclaw',
- 'posthog-opencode',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- sdk_lib,
- ai_lib
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events
+ WHERE timestamp >= '2022-01-10 02:00:00'
+ AND timestamp < '2022-01-10 04:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND person_mode IN ('full',
+ 'force_upgrade')
+ GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.14
'''
SELECT team_id,
- replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') AS sdk_lib,
- replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') AS ai_lib,
- count(1) as count
- FROM events PREWHERE timestamp >= '2022-01-10 02:00:00'
- AND timestamp < '2022-01-10 04:00:00'
- AND startsWith(event, '$ai_')
- WHERE replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('posthog-node',
- 'posthog-python',
- 'posthog-dotnet',
- 'posthog-aspnetcore')
- AND replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') IN ('posthog-openclaw',
- 'posthog-opencode',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- sdk_lib,
- ai_lib
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events
+ WHERE timestamp >= '2022-01-10 04:00:00'
+ AND timestamp < '2022-01-10 06:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND person_mode IN ('full',
+ 'force_upgrade')
+ GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.15
'''
SELECT team_id,
- replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') AS sdk_lib,
- replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') AS ai_lib,
- count(1) as count
- FROM events PREWHERE timestamp >= '2022-01-10 04:00:00'
- AND timestamp < '2022-01-10 06:00:00'
- AND startsWith(event, '$ai_')
- WHERE replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('posthog-node',
- 'posthog-python',
- 'posthog-dotnet',
- 'posthog-aspnetcore')
- AND replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') IN ('posthog-openclaw',
- 'posthog-opencode',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- sdk_lib,
- ai_lib
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events
+ WHERE timestamp >= '2022-01-10 06:00:00'
+ AND timestamp < '2022-01-10 08:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND person_mode IN ('full',
+ 'force_upgrade')
+ GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.16
'''
SELECT team_id,
- replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') AS sdk_lib,
- replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') AS ai_lib,
- count(1) as count
- FROM events PREWHERE timestamp >= '2022-01-10 06:00:00'
- AND timestamp < '2022-01-10 08:00:00'
- AND startsWith(event, '$ai_')
- WHERE replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('posthog-node',
- 'posthog-python',
- 'posthog-dotnet',
- 'posthog-aspnetcore')
- AND replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') IN ('posthog-openclaw',
- 'posthog-opencode',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- sdk_lib,
- ai_lib
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events
+ WHERE timestamp >= '2022-01-10 08:00:00'
+ AND timestamp < '2022-01-10 10:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND person_mode IN ('full',
+ 'force_upgrade')
+ GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.17
'''
SELECT team_id,
- replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') AS sdk_lib,
- replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') AS ai_lib,
- count(1) as count
- FROM events PREWHERE timestamp >= '2022-01-10 08:00:00'
- AND timestamp < '2022-01-10 10:00:00'
- AND startsWith(event, '$ai_')
- WHERE replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('posthog-node',
- 'posthog-python',
- 'posthog-dotnet',
- 'posthog-aspnetcore')
- AND replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') IN ('posthog-openclaw',
- 'posthog-opencode',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- sdk_lib,
- ai_lib
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events
+ WHERE timestamp >= '2022-01-10 10:00:00'
+ AND timestamp < '2022-01-10 12:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND person_mode IN ('full',
+ 'force_upgrade')
+ GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.18
'''
SELECT team_id,
- replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') AS sdk_lib,
- replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') AS ai_lib,
- count(1) as count
- FROM events PREWHERE timestamp >= '2022-01-10 10:00:00'
- AND timestamp < '2022-01-10 12:00:00'
- AND startsWith(event, '$ai_')
- WHERE replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('posthog-node',
- 'posthog-python',
- 'posthog-dotnet',
- 'posthog-aspnetcore')
- AND replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') IN ('posthog-openclaw',
- 'posthog-opencode',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- sdk_lib,
- ai_lib
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events
+ WHERE timestamp >= '2022-01-10 12:00:00'
+ AND timestamp < '2022-01-10 14:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND person_mode IN ('full',
+ 'force_upgrade')
+ GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.19
'''
SELECT team_id,
- replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') AS sdk_lib,
- replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') AS ai_lib,
- count(1) as count
- FROM events PREWHERE timestamp >= '2022-01-10 12:00:00'
- AND timestamp < '2022-01-10 14:00:00'
- AND startsWith(event, '$ai_')
- WHERE replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('posthog-node',
- 'posthog-python',
- 'posthog-dotnet',
- 'posthog-aspnetcore')
- AND replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') IN ('posthog-openclaw',
- 'posthog-opencode',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- sdk_lib,
- ai_lib
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events
+ WHERE timestamp >= '2022-01-10 14:00:00'
+ AND timestamp < '2022-01-10 16:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND person_mode IN ('full',
+ 'force_upgrade')
+ GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.2
'''
SELECT team_id,
- multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node-mcp', 'node_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python-mcp', 'python_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-edge', 'edge_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-convex', 'convex_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-kmp', 'kmp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rails', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-aspnetcore', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,
- count(1) as count
- FROM events PREWHERE timestamp >= '2022-01-10 04:00:00'
- AND timestamp < '2022-01-10 06:00:00'
- WHERE (event LIKE 'helicone%'
- OR event LIKE 'langfuse%'
- OR event LIKE 'keywords_ai%'
- OR event LIKE 'traceloop%'
- OR replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('web',
- 'js',
- 'posthog-node',
- 'posthog-node-mcp',
- 'posthog-python-mcp',
- 'posthog-edge',
- 'posthog-convex',
- 'posthog-android',
- 'posthog-kmp',
- 'posthog-flutter',
- 'posthog-ios',
- 'posthog-go',
- 'posthog-java',
- 'posthog-server',
- 'posthog-react-native',
- 'posthog-ruby',
- 'posthog-rails',
- 'posthog-python',
- 'posthog-php',
- 'posthog-dotnet',
- 'posthog-aspnetcore',
- 'posthog-elixir',
- 'posthog-unity',
- 'posthog-rs'))
- GROUP BY team_id,
- metric
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events
+ WHERE timestamp >= '2022-01-10 04:00:00'
+ AND timestamp < '2022-01-10 06:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.20
'''
SELECT team_id,
- replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') AS sdk_lib,
- replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') AS ai_lib,
- count(1) as count
- FROM events PREWHERE timestamp >= '2022-01-10 14:00:00'
- AND timestamp < '2022-01-10 16:00:00'
- AND startsWith(event, '$ai_')
- WHERE replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('posthog-node',
- 'posthog-python',
- 'posthog-dotnet',
- 'posthog-aspnetcore')
- AND replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') IN ('posthog-openclaw',
- 'posthog-opencode',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- sdk_lib,
- ai_lib
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events
+ WHERE timestamp >= '2022-01-10 16:00:00'
+ AND timestamp < '2022-01-10 18:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND person_mode IN ('full',
+ 'force_upgrade')
+ GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.21
'''
SELECT team_id,
- replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') AS sdk_lib,
- replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') AS ai_lib,
- count(1) as count
- FROM events PREWHERE timestamp >= '2022-01-10 16:00:00'
- AND timestamp < '2022-01-10 18:00:00'
- AND startsWith(event, '$ai_')
- WHERE replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('posthog-node',
- 'posthog-python',
- 'posthog-dotnet',
- 'posthog-aspnetcore')
- AND replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') IN ('posthog-openclaw',
- 'posthog-opencode',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- sdk_lib,
- ai_lib
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events
+ WHERE timestamp >= '2022-01-10 18:00:00'
+ AND timestamp < '2022-01-10 20:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND person_mode IN ('full',
+ 'force_upgrade')
+ GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.22
'''
SELECT team_id,
- replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') AS sdk_lib,
- replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') AS ai_lib,
- count(1) as count
- FROM events PREWHERE timestamp >= '2022-01-10 18:00:00'
- AND timestamp < '2022-01-10 20:00:00'
- AND startsWith(event, '$ai_')
- WHERE replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('posthog-node',
- 'posthog-python',
- 'posthog-dotnet',
- 'posthog-aspnetcore')
- AND replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') IN ('posthog-openclaw',
- 'posthog-opencode',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- sdk_lib,
- ai_lib
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events
+ WHERE timestamp >= '2022-01-10 20:00:00'
+ AND timestamp < '2022-01-10 22:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND person_mode IN ('full',
+ 'force_upgrade')
+ GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.23
'''
SELECT team_id,
- replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') AS sdk_lib,
- replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') AS ai_lib,
- count(1) as count
- FROM events PREWHERE timestamp >= '2022-01-10 20:00:00'
- AND timestamp < '2022-01-10 22:00:00'
- AND startsWith(event, '$ai_')
- WHERE replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('posthog-node',
- 'posthog-python',
- 'posthog-dotnet',
- 'posthog-aspnetcore')
- AND replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') IN ('posthog-openclaw',
- 'posthog-opencode',
- '@posthog/pi',
- 'posthog-ai')
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events
+ WHERE timestamp >= '2022-01-10 22:00:00'
+ AND timestamp < '2022-01-10 23:59:59'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND person_mode IN ('full',
+ 'force_upgrade')
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.24
+ '''
+
+ SELECT team_id,
+ count(distinct session_id) as count
+ FROM
+ (SELECT any(team_id) as team_id,
+ session_id
+ FROM session_replay_events
+ WHERE min_first_timestamp >= '2022-01-10 00:00:00'
+ AND min_first_timestamp < '2022-01-10 23:59:59'
+ GROUP BY session_id
+ HAVING (ifNull(argMinMerge(snapshot_source), 'web') == 'mobile') == 0
+ AND max(is_deleted) = 0)
+ WHERE session_id NOT IN
+ (SELECT DISTINCT session_id
+ FROM session_replay_events
+ WHERE min_first_timestamp >= '2022-01-09 00:00:00'
+ AND min_first_timestamp < '2022-01-10 00:00:00'
+ GROUP BY session_id)
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.25
+ '''
+
+ SELECT team_id,
+ count(distinct session_id) as count
+ FROM
+ (SELECT any(team_id) as team_id,
+ session_id
+ FROM session_replay_events
+ WHERE min_first_timestamp >= '2022-01-10 00:00:00'
+ AND min_first_timestamp < '2022-01-10 23:59:59'
+ GROUP BY session_id
+ HAVING (ifNull(argMinMerge(snapshot_source), 'web') == 'mobile') == 1
+ AND max(is_deleted) = 0)
+ WHERE session_id NOT IN
+ (SELECT DISTINCT session_id
+ FROM session_replay_events
+ WHERE min_first_timestamp >= '2022-01-09 00:00:00'
+ AND min_first_timestamp < '2022-01-10 00:00:00'
+ GROUP BY session_id)
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.26
+ '''
+
+ SELECT team_id,
+ count(distinct session_id) as count
+ FROM
+ (SELECT any(team_id) as team_id,
+ session_id
+ FROM session_replay_events
+ WHERE min_first_timestamp >= '2022-01-10 00:00:00'
+ AND min_first_timestamp < '2022-01-10 23:59:59'
+ GROUP BY session_id
+ HAVING (ifNull(argMinMerge(snapshot_source), 'web') == 'mobile') == 1
+ AND max(is_deleted) = 0)
+ WHERE session_id NOT IN
+ (SELECT DISTINCT session_id
+ FROM session_replay_events
+ WHERE min_first_timestamp >= '2022-01-09 00:00:00'
+ AND min_first_timestamp < '2022-01-10 00:00:00'
+ GROUP BY session_id)
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.27
+ '''
+
+ SELECT team_id,
+ COUNT() as count
+ FROM events
+ WHERE event = 'survey sent'
+ AND timestamp >= '2022-01-10 00:00:00'
+ AND timestamp < '2022-01-10 23:59:59'
+ AND uuid IN
+ (SELECT argMax(uuid, timestamp)
+ FROM events
+ WHERE timestamp >= '2022-01-10 00:00:00'
+ AND timestamp < '2022-01-10 23:59:59'
+ AND event = 'survey sent'
+ GROUP BY team_id,
+ replaceRegexpAll(JSONExtractRaw(properties, '$survey_id'), '^"|"$', ''),
+ CASE
+ WHEN COALESCE(replaceRegexpAll(JSONExtractRaw(properties, '$survey_submission_id'), '^"|"$', ''), '') = '' THEN toString(uuid)
+ ELSE replaceRegexpAll(JSONExtractRaw(properties, '$survey_submission_id'), '^"|"$', '')
+ END)
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.28
+ '''
+
+ SELECT team_id,
+ COUNT() - uniqExactIf(request_id, verified
+ AND NOT relay
+ AND request_id != '') AS count,
+ max(relay) AS has_verified_relay
+ FROM
+ (SELECT team_id,
+ replaceRegexpAll(JSONExtractRaw(properties, '$ai_gateway_verified'), '^"|"$', '') IN ('true',
+ '1') AS verified,
+ if(verified, replaceRegexpAll(JSONExtractRaw(properties, '$ai_gateway_request_id'), '^"|"$', ''), '') AS request_id,
+ if(verified, replaceRegexpAll(JSONExtractRaw(properties, '$ai_gateway_relay'), '^"|"$', ''), '') IN ('true',
+ '1') AS relay
+ FROM events
+ WHERE startsWith(event, '$ai_')
+ AND timestamp >= '2022-01-10 00:00:00'
+ AND timestamp < '2022-01-10 23:59:59')
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.29
+ '''
+
+ SELECT team_id,
+ multiIf(replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-edge', 'node', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python', 'unknown') AS library,
+ count(1) as total
+ FROM events
+ WHERE event = '$exception'
+ AND timestamp >= '2022-01-10 00:00:00'
+ AND timestamp < '2022-01-10 23:59:59'
GROUP BY team_id,
- sdk_lib,
- ai_lib
+ library
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.3
+ '''
+
+ SELECT team_id,
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events
+ WHERE timestamp >= '2022-01-10 06:00:00'
+ AND timestamp < '2022-01-10 08:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.30
+ '''
+
+ SELECT team_id,
+ SUM(count) as count
+ FROM app_metrics2
+ WHERE app_source='hog_function'
+ AND metric_name IN ('billable_invocation')
+ AND timestamp >= '2022-01-10 00:00:00'
+ AND timestamp < '2022-01-10 23:59:59'
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.31
+ '''
+
+ SELECT distinct_id as team,
+ sum(toInt64OrZero(replaceRegexpAll(JSONExtractRaw(properties, 'count'), '^"|"$', ''))) as sum
+ FROM events
+ WHERE team_id = 99999
+ AND event='decide usage'
+ AND timestamp >= '2022-01-10 00:00:00'
+ AND timestamp < '2022-01-10 23:59:59'
+ AND has(['correct'], replaceRegexpAll(JSONExtractRaw(properties, 'token'), '^"|"$', ''))
+ GROUP BY team
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.32
+ '''
+
+ SELECT distinct_id as team,
+ sum(toInt64OrZero(replaceRegexpAll(JSONExtractRaw(properties, 'count'), '^"|"$', ''))) as sum
+ FROM events
+ WHERE team_id = 99999
+ AND event='local evaluation usage'
+ AND timestamp >= '2022-01-10 00:00:00'
+ AND timestamp < '2022-01-10 23:59:59'
+ AND has(['correct'], replaceRegexpAll(JSONExtractRaw(properties, 'token'), '^"|"$', ''))
+ GROUP BY team
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.24
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.33
'''
SELECT team_id,
- replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') AS sdk_lib,
- replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') AS ai_lib,
- count(1) as count
- FROM events PREWHERE timestamp >= '2022-01-10 22:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- AND startsWith(event, '$ai_')
- WHERE replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('posthog-node',
- 'posthog-python',
- 'posthog-dotnet',
- 'posthog-aspnetcore')
- AND replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') IN ('posthog-openclaw',
- 'posthog-opencode',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- sdk_lib,
- ai_lib
+ SUM(count) as count
+ FROM app_metrics2
+ WHERE app_source='hog_flow'
+ AND metric_name IN ('billable_invocation')
+ AND metric_kind IN ('email')
+ AND timestamp >= '2022-01-10 00:00:00'
+ AND timestamp < '2022-01-10 23:59:59'
+ GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.25
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.34
'''
SELECT team_id,
- event,
- uniqExact(tuple(toDate(timestamp), cityHash64(distinct_id), cityHash64(uuid))) AS count
- FROM events PREWHERE timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- WHERE event IN ('$mcp_missing_capability',
- '$mcp_initialize',
- '$mcp_tools_list',
- '$mcp_resource_read',
- '$mcp_resources_list',
- '$mcp_prompt_get',
- '$mcp_prompts_list')
- GROUP BY team_id,
- event
+ SUM(count) as count
+ FROM app_metrics2
+ WHERE app_source='hog_flow'
+ AND metric_name IN ('billable_invocation')
+ AND metric_kind IN ('push')
+ AND timestamp >= '2022-01-10 00:00:00'
+ AND timestamp < '2022-01-10 23:59:59'
+ GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.26
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.35
'''
- SELECT JSONExtractInt(log_comment, 'team_id') team_id,
- count(1) cnt,
- sum(read_bytes) read_bytes
- FROM clusterAllReplicas(posthog, system.query_log)
- WHERE type = 'QueryFinish'
- AND is_initial_query
- AND event_time >= 'today 00:00:00'
- AND event_time < '2022-01-10 23:59:59'
- AND team_id > 0
- AND JSONExtractBool(log_comment, 'chargeable')
+ SELECT team_id,
+ SUM(count) as count
+ FROM app_metrics2
+ WHERE app_source='hog_flow'
+ AND metric_name IN ('billable_invocation')
+ AND metric_kind IN ('sms')
+ AND timestamp >= '2022-01-10 00:00:00'
+ AND timestamp < '2022-01-10 23:59:59'
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.27
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.36
+ '''
+
+ SELECT team_id,
+ SUM(count) as count
+ FROM app_metrics2
+ WHERE app_source='hog_flow'
+ AND metric_name IN ('billable_invocation')
+ AND metric_kind IN ('fetch',
+ 'push')
+ AND timestamp >= '2022-01-10 00:00:00'
+ AND timestamp < '2022-01-10 23:59:59'
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.37
'''
SELECT team_id,
SUM(count) as count
FROM app_metrics2
WHERE app_source='logs'
- AND metric_name='records_ingested'
+ AND metric_name='bytes_ingested'
AND timestamp >= '2022-01-10 00:00:00'
AND timestamp < '2022-01-10 23:59:59'
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.28
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.38
'''
SELECT team_id,
@@ -551,7 +514,7 @@
metric_name
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.29
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.39
'''
SELECT team_id,
@@ -564,14 +527,187 @@
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.3
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.4
+ '''
+
+ SELECT team_id,
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events
+ WHERE timestamp >= '2022-01-10 08:00:00'
+ AND timestamp < '2022-01-10 10:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.40
+ '''
+
+ SELECT team_id,
+ multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node-mcp', 'node_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python-mcp', 'python_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-edge', 'edge_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-convex', 'convex_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-kmp', 'kmp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rails', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-aspnetcore', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,
+ count(1) as count
+ FROM events PREWHERE timestamp >= '2022-01-10 00:00:00'
+ AND timestamp < '2022-01-10 02:00:00'
+ WHERE (event LIKE 'helicone%'
+ OR event LIKE 'langfuse%'
+ OR event LIKE 'keywords_ai%'
+ OR event LIKE 'traceloop%'
+ OR replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('web',
+ 'js',
+ 'posthog-node',
+ 'posthog-node-mcp',
+ 'posthog-python-mcp',
+ 'posthog-edge',
+ 'posthog-convex',
+ 'posthog-android',
+ 'posthog-kmp',
+ 'posthog-flutter',
+ 'posthog-ios',
+ 'posthog-go',
+ 'posthog-java',
+ 'posthog-server',
+ 'posthog-react-native',
+ 'posthog-ruby',
+ 'posthog-rails',
+ 'posthog-python',
+ 'posthog-php',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore',
+ 'posthog-elixir',
+ 'posthog-unity',
+ 'posthog-rs'))
+ GROUP BY team_id,
+ metric
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.41
+ '''
+
+ SELECT team_id,
+ multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node-mcp', 'node_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python-mcp', 'python_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-edge', 'edge_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-convex', 'convex_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-kmp', 'kmp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rails', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-aspnetcore', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,
+ count(1) as count
+ FROM events PREWHERE timestamp >= '2022-01-10 02:00:00'
+ AND timestamp < '2022-01-10 04:00:00'
+ WHERE (event LIKE 'helicone%'
+ OR event LIKE 'langfuse%'
+ OR event LIKE 'keywords_ai%'
+ OR event LIKE 'traceloop%'
+ OR replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('web',
+ 'js',
+ 'posthog-node',
+ 'posthog-node-mcp',
+ 'posthog-python-mcp',
+ 'posthog-edge',
+ 'posthog-convex',
+ 'posthog-android',
+ 'posthog-kmp',
+ 'posthog-flutter',
+ 'posthog-ios',
+ 'posthog-go',
+ 'posthog-java',
+ 'posthog-server',
+ 'posthog-react-native',
+ 'posthog-ruby',
+ 'posthog-rails',
+ 'posthog-python',
+ 'posthog-php',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore',
+ 'posthog-elixir',
+ 'posthog-unity',
+ 'posthog-rs'))
+ GROUP BY team_id,
+ metric
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.42
+ '''
+
+ SELECT team_id,
+ multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node-mcp', 'node_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python-mcp', 'python_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-edge', 'edge_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-convex', 'convex_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-kmp', 'kmp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rails', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-aspnetcore', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,
+ count(1) as count
+ FROM events PREWHERE timestamp >= '2022-01-10 04:00:00'
+ AND timestamp < '2022-01-10 06:00:00'
+ WHERE (event LIKE 'helicone%'
+ OR event LIKE 'langfuse%'
+ OR event LIKE 'keywords_ai%'
+ OR event LIKE 'traceloop%'
+ OR replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('web',
+ 'js',
+ 'posthog-node',
+ 'posthog-node-mcp',
+ 'posthog-python-mcp',
+ 'posthog-edge',
+ 'posthog-convex',
+ 'posthog-android',
+ 'posthog-kmp',
+ 'posthog-flutter',
+ 'posthog-ios',
+ 'posthog-go',
+ 'posthog-java',
+ 'posthog-server',
+ 'posthog-react-native',
+ 'posthog-ruby',
+ 'posthog-rails',
+ 'posthog-python',
+ 'posthog-php',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore',
+ 'posthog-elixir',
+ 'posthog-unity',
+ 'posthog-rs'))
+ GROUP BY team_id,
+ metric
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.43
+ '''
+
+ SELECT team_id,
+ multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node-mcp', 'node_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python-mcp', 'python_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-edge', 'edge_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-convex', 'convex_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-kmp', 'kmp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rails', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-aspnetcore', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,
+ count(1) as count
+ FROM events PREWHERE timestamp >= '2022-01-10 06:00:00'
+ AND timestamp < '2022-01-10 08:00:00'
+ WHERE (event LIKE 'helicone%'
+ OR event LIKE 'langfuse%'
+ OR event LIKE 'keywords_ai%'
+ OR event LIKE 'traceloop%'
+ OR replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('web',
+ 'js',
+ 'posthog-node',
+ 'posthog-node-mcp',
+ 'posthog-python-mcp',
+ 'posthog-edge',
+ 'posthog-convex',
+ 'posthog-android',
+ 'posthog-kmp',
+ 'posthog-flutter',
+ 'posthog-ios',
+ 'posthog-go',
+ 'posthog-java',
+ 'posthog-server',
+ 'posthog-react-native',
+ 'posthog-ruby',
+ 'posthog-rails',
+ 'posthog-python',
+ 'posthog-php',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore',
+ 'posthog-elixir',
+ 'posthog-unity',
+ 'posthog-rs'))
+ GROUP BY team_id,
+ metric
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.44
'''
SELECT team_id,
multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node-mcp', 'node_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python-mcp', 'python_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-edge', 'edge_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-convex', 'convex_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-kmp', 'kmp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rails', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-aspnetcore', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,
count(1) as count
- FROM events PREWHERE timestamp >= '2022-01-10 06:00:00'
- AND timestamp < '2022-01-10 08:00:00'
+ FROM events PREWHERE timestamp >= '2022-01-10 08:00:00'
+ AND timestamp < '2022-01-10 10:00:00'
WHERE (event LIKE 'helicone%'
OR event LIKE 'langfuse%'
OR event LIKE 'keywords_ai%'
@@ -604,118 +740,207 @@
metric
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.30
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.45
'''
SELECT team_id,
- metric_name,
- SUM(count) as count
- FROM app_metrics2
- WHERE app_source='traces'
- AND metric_name IN ('bytes_ingested',
- 'records_ingested')
- AND timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 23:59:59'
+ multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node-mcp', 'node_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python-mcp', 'python_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-edge', 'edge_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-convex', 'convex_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-kmp', 'kmp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rails', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-aspnetcore', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,
+ count(1) as count
+ FROM events PREWHERE timestamp >= '2022-01-10 10:00:00'
+ AND timestamp < '2022-01-10 12:00:00'
+ WHERE (event LIKE 'helicone%'
+ OR event LIKE 'langfuse%'
+ OR event LIKE 'keywords_ai%'
+ OR event LIKE 'traceloop%'
+ OR replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('web',
+ 'js',
+ 'posthog-node',
+ 'posthog-node-mcp',
+ 'posthog-python-mcp',
+ 'posthog-edge',
+ 'posthog-convex',
+ 'posthog-android',
+ 'posthog-kmp',
+ 'posthog-flutter',
+ 'posthog-ios',
+ 'posthog-go',
+ 'posthog-java',
+ 'posthog-server',
+ 'posthog-react-native',
+ 'posthog-ruby',
+ 'posthog-rails',
+ 'posthog-python',
+ 'posthog-php',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore',
+ 'posthog-elixir',
+ 'posthog-unity',
+ 'posthog-rs'))
GROUP BY team_id,
- metric_name
+ metric
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.31
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.46
'''
SELECT team_id,
- metric_name,
- SUM(count) as count
- FROM app_metrics2
- WHERE app_source='metrics'
- AND metric_name IN ('bytes_ingested',
- 'records_ingested')
- AND timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 23:59:59'
+ multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node-mcp', 'node_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python-mcp', 'python_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-edge', 'edge_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-convex', 'convex_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-kmp', 'kmp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rails', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-aspnetcore', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,
+ count(1) as count
+ FROM events PREWHERE timestamp >= '2022-01-10 12:00:00'
+ AND timestamp < '2022-01-10 14:00:00'
+ WHERE (event LIKE 'helicone%'
+ OR event LIKE 'langfuse%'
+ OR event LIKE 'keywords_ai%'
+ OR event LIKE 'traceloop%'
+ OR replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('web',
+ 'js',
+ 'posthog-node',
+ 'posthog-node-mcp',
+ 'posthog-python-mcp',
+ 'posthog-edge',
+ 'posthog-convex',
+ 'posthog-android',
+ 'posthog-kmp',
+ 'posthog-flutter',
+ 'posthog-ios',
+ 'posthog-go',
+ 'posthog-java',
+ 'posthog-server',
+ 'posthog-react-native',
+ 'posthog-ruby',
+ 'posthog-rails',
+ 'posthog-python',
+ 'posthog-php',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore',
+ 'posthog-elixir',
+ 'posthog-unity',
+ 'posthog-rs'))
GROUP BY team_id,
- metric_name
+ metric
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.32
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.47
'''
SELECT team_id,
- multiIf(replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-edge', 'node', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python', 'unknown') AS library,
- count(1) as total
- FROM events
- WHERE event = '$exception'
- AND timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 23:59:59'
+ multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node-mcp', 'node_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python-mcp', 'python_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-edge', 'edge_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-convex', 'convex_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-kmp', 'kmp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rails', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-aspnetcore', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,
+ count(1) as count
+ FROM events PREWHERE timestamp >= '2022-01-10 14:00:00'
+ AND timestamp < '2022-01-10 16:00:00'
+ WHERE (event LIKE 'helicone%'
+ OR event LIKE 'langfuse%'
+ OR event LIKE 'keywords_ai%'
+ OR event LIKE 'traceloop%'
+ OR replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('web',
+ 'js',
+ 'posthog-node',
+ 'posthog-node-mcp',
+ 'posthog-python-mcp',
+ 'posthog-edge',
+ 'posthog-convex',
+ 'posthog-android',
+ 'posthog-kmp',
+ 'posthog-flutter',
+ 'posthog-ios',
+ 'posthog-go',
+ 'posthog-java',
+ 'posthog-server',
+ 'posthog-react-native',
+ 'posthog-ruby',
+ 'posthog-rails',
+ 'posthog-python',
+ 'posthog-php',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore',
+ 'posthog-elixir',
+ 'posthog-unity',
+ 'posthog-rs'))
GROUP BY team_id,
- library
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.33
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events
- WHERE timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 02:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.34
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events
- WHERE timestamp >= '2022-01-10 02:00:00'
- AND timestamp < '2022-01-10 04:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.35
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events
- WHERE timestamp >= '2022-01-10 04:00:00'
- AND timestamp < '2022-01-10 06:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- GROUP BY team_id
+ metric
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.36
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.48
'''
SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events
- WHERE timestamp >= '2022-01-10 06:00:00'
- AND timestamp < '2022-01-10 08:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- GROUP BY team_id
+ multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node-mcp', 'node_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python-mcp', 'python_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-edge', 'edge_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-convex', 'convex_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-kmp', 'kmp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rails', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-aspnetcore', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,
+ count(1) as count
+ FROM events PREWHERE timestamp >= '2022-01-10 16:00:00'
+ AND timestamp < '2022-01-10 18:00:00'
+ WHERE (event LIKE 'helicone%'
+ OR event LIKE 'langfuse%'
+ OR event LIKE 'keywords_ai%'
+ OR event LIKE 'traceloop%'
+ OR replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('web',
+ 'js',
+ 'posthog-node',
+ 'posthog-node-mcp',
+ 'posthog-python-mcp',
+ 'posthog-edge',
+ 'posthog-convex',
+ 'posthog-android',
+ 'posthog-kmp',
+ 'posthog-flutter',
+ 'posthog-ios',
+ 'posthog-go',
+ 'posthog-java',
+ 'posthog-server',
+ 'posthog-react-native',
+ 'posthog-ruby',
+ 'posthog-rails',
+ 'posthog-python',
+ 'posthog-php',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore',
+ 'posthog-elixir',
+ 'posthog-unity',
+ 'posthog-rs'))
+ GROUP BY team_id,
+ metric
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.37
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.49
'''
SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events
- WHERE timestamp >= '2022-01-10 08:00:00'
- AND timestamp < '2022-01-10 10:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- GROUP BY team_id
+ multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node-mcp', 'node_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python-mcp', 'python_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-edge', 'edge_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-convex', 'convex_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-kmp', 'kmp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rails', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-aspnetcore', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,
+ count(1) as count
+ FROM events PREWHERE timestamp >= '2022-01-10 18:00:00'
+ AND timestamp < '2022-01-10 20:00:00'
+ WHERE (event LIKE 'helicone%'
+ OR event LIKE 'langfuse%'
+ OR event LIKE 'keywords_ai%'
+ OR event LIKE 'traceloop%'
+ OR replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('web',
+ 'js',
+ 'posthog-node',
+ 'posthog-node-mcp',
+ 'posthog-python-mcp',
+ 'posthog-edge',
+ 'posthog-convex',
+ 'posthog-android',
+ 'posthog-kmp',
+ 'posthog-flutter',
+ 'posthog-ios',
+ 'posthog-go',
+ 'posthog-java',
+ 'posthog-server',
+ 'posthog-react-native',
+ 'posthog-ruby',
+ 'posthog-rails',
+ 'posthog-python',
+ 'posthog-php',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore',
+ 'posthog-elixir',
+ 'posthog-unity',
+ 'posthog-rs'))
+ GROUP BY team_id,
+ metric
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.38
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.5
'''
SELECT team_id,
@@ -728,27 +953,54 @@
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.39
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.50
'''
SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events
- WHERE timestamp >= '2022-01-10 12:00:00'
- AND timestamp < '2022-01-10 14:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- GROUP BY team_id
+ multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node-mcp', 'node_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python-mcp', 'python_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-edge', 'edge_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-convex', 'convex_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-kmp', 'kmp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rails', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-aspnetcore', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,
+ count(1) as count
+ FROM events PREWHERE timestamp >= '2022-01-10 20:00:00'
+ AND timestamp < '2022-01-10 22:00:00'
+ WHERE (event LIKE 'helicone%'
+ OR event LIKE 'langfuse%'
+ OR event LIKE 'keywords_ai%'
+ OR event LIKE 'traceloop%'
+ OR replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('web',
+ 'js',
+ 'posthog-node',
+ 'posthog-node-mcp',
+ 'posthog-python-mcp',
+ 'posthog-edge',
+ 'posthog-convex',
+ 'posthog-android',
+ 'posthog-kmp',
+ 'posthog-flutter',
+ 'posthog-ios',
+ 'posthog-go',
+ 'posthog-java',
+ 'posthog-server',
+ 'posthog-react-native',
+ 'posthog-ruby',
+ 'posthog-rails',
+ 'posthog-python',
+ 'posthog-php',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore',
+ 'posthog-elixir',
+ 'posthog-unity',
+ 'posthog-rs'))
+ GROUP BY team_id,
+ metric
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.4
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.51
'''
SELECT team_id,
multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node-mcp', 'node_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python-mcp', 'python_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-edge', 'edge_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-convex', 'convex_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-kmp', 'kmp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rails', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-aspnetcore', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,
count(1) as count
- FROM events PREWHERE timestamp >= '2022-01-10 08:00:00'
- AND timestamp < '2022-01-10 10:00:00'
+ FROM events PREWHERE timestamp >= '2022-01-10 22:00:00'
+ AND timestamp < '2022-01-10 23:59:59'
WHERE (event LIKE 'helicone%'
OR event LIKE 'langfuse%'
OR event LIKE 'keywords_ai%'
@@ -781,292 +1033,400 @@
metric
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.40
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.52
'''
SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events
- WHERE timestamp >= '2022-01-10 14:00:00'
- AND timestamp < '2022-01-10 16:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
+ uniqExact(tuple(toDate(timestamp), cityHash64(distinct_id), cityHash64(uuid))) AS count
+ FROM events PREWHERE timestamp >= '2022-01-10 00:00:00'
+ AND timestamp < '2022-01-10 23:59:59'
+ WHERE event = '$mcp_tool_call'
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.41
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.53
'''
SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events
- WHERE timestamp >= '2022-01-10 16:00:00'
- AND timestamp < '2022-01-10 18:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- GROUP BY team_id
+ replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') AS sdk_lib,
+ replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') AS ai_lib,
+ count(1) as count
+ FROM events PREWHERE timestamp >= '2022-01-10 00:00:00'
+ AND timestamp < '2022-01-10 02:00:00'
+ AND startsWith(event, '$ai_')
+ WHERE replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('posthog-node',
+ 'posthog-python',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore')
+ AND replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') IN ('posthog-openclaw',
+ 'posthog-opencode',
+ '@posthog/pi',
+ 'posthog-ai')
+ GROUP BY team_id,
+ sdk_lib,
+ ai_lib
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.42
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.54
'''
SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events
- WHERE timestamp >= '2022-01-10 18:00:00'
- AND timestamp < '2022-01-10 20:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- GROUP BY team_id
+ replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') AS sdk_lib,
+ replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') AS ai_lib,
+ count(1) as count
+ FROM events PREWHERE timestamp >= '2022-01-10 02:00:00'
+ AND timestamp < '2022-01-10 04:00:00'
+ AND startsWith(event, '$ai_')
+ WHERE replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('posthog-node',
+ 'posthog-python',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore')
+ AND replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') IN ('posthog-openclaw',
+ 'posthog-opencode',
+ '@posthog/pi',
+ 'posthog-ai')
+ GROUP BY team_id,
+ sdk_lib,
+ ai_lib
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.43
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.55
'''
SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events
- WHERE timestamp >= '2022-01-10 20:00:00'
- AND timestamp < '2022-01-10 22:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- GROUP BY team_id
+ replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') AS sdk_lib,
+ replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') AS ai_lib,
+ count(1) as count
+ FROM events PREWHERE timestamp >= '2022-01-10 04:00:00'
+ AND timestamp < '2022-01-10 06:00:00'
+ AND startsWith(event, '$ai_')
+ WHERE replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('posthog-node',
+ 'posthog-python',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore')
+ AND replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') IN ('posthog-openclaw',
+ 'posthog-opencode',
+ '@posthog/pi',
+ 'posthog-ai')
+ GROUP BY team_id,
+ sdk_lib,
+ ai_lib
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.44
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.56
'''
SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events
- WHERE timestamp >= '2022-01-10 22:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- GROUP BY team_id
+ replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') AS sdk_lib,
+ replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') AS ai_lib,
+ count(1) as count
+ FROM events PREWHERE timestamp >= '2022-01-10 06:00:00'
+ AND timestamp < '2022-01-10 08:00:00'
+ AND startsWith(event, '$ai_')
+ WHERE replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('posthog-node',
+ 'posthog-python',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore')
+ AND replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') IN ('posthog-openclaw',
+ 'posthog-opencode',
+ '@posthog/pi',
+ 'posthog-ai')
+ GROUP BY team_id,
+ sdk_lib,
+ ai_lib
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.45
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.57
'''
SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events
- WHERE timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 02:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
+ replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') AS sdk_lib,
+ replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') AS ai_lib,
+ count(1) as count
+ FROM events PREWHERE timestamp >= '2022-01-10 08:00:00'
+ AND timestamp < '2022-01-10 10:00:00'
+ AND startsWith(event, '$ai_')
+ WHERE replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('posthog-node',
+ 'posthog-python',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore')
+ AND replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') IN ('posthog-openclaw',
+ 'posthog-opencode',
+ '@posthog/pi',
+ 'posthog-ai')
+ GROUP BY team_id,
+ sdk_lib,
+ ai_lib
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.58
+ '''
+
+ SELECT team_id,
+ replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') AS sdk_lib,
+ replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') AS ai_lib,
+ count(1) as count
+ FROM events PREWHERE timestamp >= '2022-01-10 10:00:00'
+ AND timestamp < '2022-01-10 12:00:00'
+ AND startsWith(event, '$ai_')
+ WHERE replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('posthog-node',
+ 'posthog-python',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore')
+ AND replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') IN ('posthog-openclaw',
+ 'posthog-opencode',
+ '@posthog/pi',
+ 'posthog-ai')
+ GROUP BY team_id,
+ sdk_lib,
+ ai_lib
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.59
+ '''
+
+ SELECT team_id,
+ replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') AS sdk_lib,
+ replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') AS ai_lib,
+ count(1) as count
+ FROM events PREWHERE timestamp >= '2022-01-10 12:00:00'
+ AND timestamp < '2022-01-10 14:00:00'
+ AND startsWith(event, '$ai_')
+ WHERE replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('posthog-node',
+ 'posthog-python',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore')
+ AND replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') IN ('posthog-openclaw',
+ 'posthog-opencode',
+ '@posthog/pi',
+ 'posthog-ai')
+ GROUP BY team_id,
+ sdk_lib,
+ ai_lib
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.46
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.6
'''
SELECT team_id,
count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
FROM events
- WHERE timestamp >= '2022-01-10 02:00:00'
- AND timestamp < '2022-01-10 04:00:00'
+ WHERE timestamp >= '2022-01-10 12:00:00'
+ AND timestamp < '2022-01-10 14:00:00'
AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
AND NOT startsWith(event, '$ai_')
- AND person_mode IN ('full',
- 'force_upgrade')
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.47
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.60
'''
SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events
- WHERE timestamp >= '2022-01-10 04:00:00'
- AND timestamp < '2022-01-10 06:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
+ replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') AS sdk_lib,
+ replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') AS ai_lib,
+ count(1) as count
+ FROM events PREWHERE timestamp >= '2022-01-10 14:00:00'
+ AND timestamp < '2022-01-10 16:00:00'
+ AND startsWith(event, '$ai_')
+ WHERE replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('posthog-node',
+ 'posthog-python',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore')
+ AND replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') IN ('posthog-openclaw',
+ 'posthog-opencode',
+ '@posthog/pi',
+ 'posthog-ai')
+ GROUP BY team_id,
+ sdk_lib,
+ ai_lib
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.48
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.61
'''
SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events
- WHERE timestamp >= '2022-01-10 06:00:00'
- AND timestamp < '2022-01-10 08:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
+ replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') AS sdk_lib,
+ replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') AS ai_lib,
+ count(1) as count
+ FROM events PREWHERE timestamp >= '2022-01-10 16:00:00'
+ AND timestamp < '2022-01-10 18:00:00'
+ AND startsWith(event, '$ai_')
+ WHERE replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('posthog-node',
+ 'posthog-python',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore')
+ AND replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') IN ('posthog-openclaw',
+ 'posthog-opencode',
+ '@posthog/pi',
+ 'posthog-ai')
+ GROUP BY team_id,
+ sdk_lib,
+ ai_lib
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.49
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.62
'''
SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events
- WHERE timestamp >= '2022-01-10 08:00:00'
- AND timestamp < '2022-01-10 10:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
+ replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') AS sdk_lib,
+ replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') AS ai_lib,
+ count(1) as count
+ FROM events PREWHERE timestamp >= '2022-01-10 18:00:00'
+ AND timestamp < '2022-01-10 20:00:00'
+ AND startsWith(event, '$ai_')
+ WHERE replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('posthog-node',
+ 'posthog-python',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore')
+ AND replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') IN ('posthog-openclaw',
+ 'posthog-opencode',
+ '@posthog/pi',
+ 'posthog-ai')
+ GROUP BY team_id,
+ sdk_lib,
+ ai_lib
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.5
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.63
'''
SELECT team_id,
- multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node-mcp', 'node_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python-mcp', 'python_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-edge', 'edge_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-convex', 'convex_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-kmp', 'kmp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rails', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-aspnetcore', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,
+ replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') AS sdk_lib,
+ replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') AS ai_lib,
count(1) as count
- FROM events PREWHERE timestamp >= '2022-01-10 10:00:00'
- AND timestamp < '2022-01-10 12:00:00'
- WHERE (event LIKE 'helicone%'
- OR event LIKE 'langfuse%'
- OR event LIKE 'keywords_ai%'
- OR event LIKE 'traceloop%'
- OR replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('web',
- 'js',
- 'posthog-node',
- 'posthog-node-mcp',
- 'posthog-python-mcp',
- 'posthog-edge',
- 'posthog-convex',
- 'posthog-android',
- 'posthog-kmp',
- 'posthog-flutter',
- 'posthog-ios',
- 'posthog-go',
- 'posthog-java',
- 'posthog-server',
- 'posthog-react-native',
- 'posthog-ruby',
- 'posthog-rails',
- 'posthog-python',
- 'posthog-php',
- 'posthog-dotnet',
- 'posthog-aspnetcore',
- 'posthog-elixir',
- 'posthog-unity',
- 'posthog-rs'))
+ FROM events PREWHERE timestamp >= '2022-01-10 20:00:00'
+ AND timestamp < '2022-01-10 22:00:00'
+ AND startsWith(event, '$ai_')
+ WHERE replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('posthog-node',
+ 'posthog-python',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore')
+ AND replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') IN ('posthog-openclaw',
+ 'posthog-opencode',
+ '@posthog/pi',
+ 'posthog-ai')
GROUP BY team_id,
- metric
+ sdk_lib,
+ ai_lib
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.50
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.64
'''
SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events
- WHERE timestamp >= '2022-01-10 10:00:00'
- AND timestamp < '2022-01-10 12:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
+ replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') AS sdk_lib,
+ replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') AS ai_lib,
+ count(1) as count
+ FROM events PREWHERE timestamp >= '2022-01-10 22:00:00'
+ AND timestamp < '2022-01-10 23:59:59'
+ AND startsWith(event, '$ai_')
+ WHERE replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('posthog-node',
+ 'posthog-python',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore')
+ AND replaceRegexpAll(JSONExtractRaw(properties, '$ai_lib'), '^"|"$', '') IN ('posthog-openclaw',
+ 'posthog-opencode',
+ '@posthog/pi',
+ 'posthog-ai')
+ GROUP BY team_id,
+ sdk_lib,
+ ai_lib
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.51
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.65
'''
SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events
- WHERE timestamp >= '2022-01-10 12:00:00'
- AND timestamp < '2022-01-10 14:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
+ event,
+ uniqExact(tuple(toDate(timestamp), cityHash64(distinct_id), cityHash64(uuid))) AS count
+ FROM events PREWHERE timestamp >= '2022-01-10 00:00:00'
+ AND timestamp < '2022-01-10 23:59:59'
+ WHERE event IN ('$mcp_missing_capability',
+ '$mcp_initialize',
+ '$mcp_tools_list',
+ '$mcp_resource_read',
+ '$mcp_resources_list',
+ '$mcp_prompt_get',
+ '$mcp_prompts_list')
+ GROUP BY team_id,
+ event
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.52
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.66
'''
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events
- WHERE timestamp >= '2022-01-10 14:00:00'
- AND timestamp < '2022-01-10 16:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND person_mode IN ('full',
- 'force_upgrade')
+ SELECT JSONExtractInt(log_comment, 'team_id') team_id,
+ count(1) cnt,
+ sum(read_bytes) read_bytes
+ FROM clusterAllReplicas(posthog, system.query_log)
+ WHERE type = 'QueryFinish'
+ AND is_initial_query
+ AND event_time >= 'today 00:00:00'
+ AND event_time < '2022-01-10 23:59:59'
+ AND team_id > 0
+ AND JSONExtractBool(log_comment, 'chargeable')
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.53
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.67
'''
SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events
- WHERE timestamp >= '2022-01-10 16:00:00'
- AND timestamp < '2022-01-10 18:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND person_mode IN ('full',
- 'force_upgrade')
+ SUM(count) as count
+ FROM app_metrics2
+ WHERE app_source='logs'
+ AND metric_name='records_ingested'
+ AND timestamp >= '2022-01-10 00:00:00'
+ AND timestamp < '2022-01-10 23:59:59'
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.54
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.68
'''
SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events
- WHERE timestamp >= '2022-01-10 18:00:00'
- AND timestamp < '2022-01-10 20:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
+ metric_name,
+ SUM(count) as count
+ FROM app_metrics2
+ WHERE app_source='traces'
+ AND metric_name IN ('bytes_ingested',
+ 'records_ingested')
+ AND timestamp >= '2022-01-10 00:00:00'
+ AND timestamp < '2022-01-10 23:59:59'
+ GROUP BY team_id,
+ metric_name
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.55
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.69
'''
SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events
- WHERE timestamp >= '2022-01-10 20:00:00'
- AND timestamp < '2022-01-10 22:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
+ metric_name,
+ SUM(count) as count
+ FROM app_metrics2
+ WHERE app_source='metrics'
+ AND metric_name IN ('bytes_ingested',
+ 'records_ingested')
+ AND timestamp >= '2022-01-10 00:00:00'
+ AND timestamp < '2022-01-10 23:59:59'
+ GROUP BY team_id,
+ metric_name
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.56
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.7
'''
SELECT team_id,
count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
FROM events
- WHERE timestamp >= '2022-01-10 22:00:00'
- AND timestamp < '2022-01-10 23:59:59'
+ WHERE timestamp >= '2022-01-10 14:00:00'
+ AND timestamp < '2022-01-10 16:00:00'
AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
AND NOT startsWith(event, '$ai_')
- AND person_mode IN ('full',
- 'force_upgrade')
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.57
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.70
'''
SELECT team_id,
@@ -1084,7 +1444,7 @@
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.58
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.71
'''
SELECT team_id,
@@ -1102,7 +1462,7 @@
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.59
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.72
'''
SELECT team_id,
@@ -1120,47 +1480,7 @@
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.6
- '''
-
- SELECT team_id,
- multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node-mcp', 'node_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python-mcp', 'python_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-edge', 'edge_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-convex', 'convex_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-kmp', 'kmp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rails', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-aspnetcore', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,
- count(1) as count
- FROM events PREWHERE timestamp >= '2022-01-10 12:00:00'
- AND timestamp < '2022-01-10 14:00:00'
- WHERE (event LIKE 'helicone%'
- OR event LIKE 'langfuse%'
- OR event LIKE 'keywords_ai%'
- OR event LIKE 'traceloop%'
- OR replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('web',
- 'js',
- 'posthog-node',
- 'posthog-node-mcp',
- 'posthog-python-mcp',
- 'posthog-edge',
- 'posthog-convex',
- 'posthog-android',
- 'posthog-kmp',
- 'posthog-flutter',
- 'posthog-ios',
- 'posthog-go',
- 'posthog-java',
- 'posthog-server',
- 'posthog-react-native',
- 'posthog-ruby',
- 'posthog-rails',
- 'posthog-python',
- 'posthog-php',
- 'posthog-dotnet',
- 'posthog-aspnetcore',
- 'posthog-elixir',
- 'posthog-unity',
- 'posthog-rs'))
- GROUP BY team_id,
- metric
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.60
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.73
'''
SELECT team_id,
@@ -1178,7 +1498,7 @@
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.61
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.74
'''
SELECT team_id,
@@ -1196,7 +1516,7 @@
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.62
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.75
'''
SELECT team_id,
@@ -1214,7 +1534,7 @@
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.63
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.76
'''
SELECT team_id,
@@ -1232,7 +1552,7 @@
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.64
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.77
'''
SELECT team_id,
@@ -1250,7 +1570,7 @@
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.65
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.78
'''
SELECT team_id,
@@ -1268,7 +1588,7 @@
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.66
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.79
'''
SELECT team_id,
@@ -1286,7 +1606,20 @@
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.67
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.8
+ '''
+
+ SELECT team_id,
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events
+ WHERE timestamp >= '2022-01-10 16:00:00'
+ AND timestamp < '2022-01-10 18:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.80
'''
SELECT team_id,
@@ -1304,7 +1637,7 @@
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.68
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.81
'''
SELECT team_id,
@@ -1322,7 +1655,7 @@
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.69
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.82
'''
SELECT team_id,
@@ -1333,70 +1666,7 @@
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.7
- '''
-
- SELECT team_id,
- multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node-mcp', 'node_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python-mcp', 'python_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-edge', 'edge_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-convex', 'convex_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-kmp', 'kmp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rails', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-aspnetcore', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,
- count(1) as count
- FROM events PREWHERE timestamp >= '2022-01-10 14:00:00'
- AND timestamp < '2022-01-10 16:00:00'
- WHERE (event LIKE 'helicone%'
- OR event LIKE 'langfuse%'
- OR event LIKE 'keywords_ai%'
- OR event LIKE 'traceloop%'
- OR replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('web',
- 'js',
- 'posthog-node',
- 'posthog-node-mcp',
- 'posthog-python-mcp',
- 'posthog-edge',
- 'posthog-convex',
- 'posthog-android',
- 'posthog-kmp',
- 'posthog-flutter',
- 'posthog-ios',
- 'posthog-go',
- 'posthog-java',
- 'posthog-server',
- 'posthog-react-native',
- 'posthog-ruby',
- 'posthog-rails',
- 'posthog-python',
- 'posthog-php',
- 'posthog-dotnet',
- 'posthog-aspnetcore',
- 'posthog-elixir',
- 'posthog-unity',
- 'posthog-rs'))
- GROUP BY team_id,
- metric
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.70
- '''
-
- SELECT team_id,
- count(distinct session_id) as count
- FROM
- (SELECT any(team_id) as team_id,
- session_id
- FROM session_replay_events
- WHERE min_first_timestamp >= '2022-01-10 00:00:00'
- AND min_first_timestamp < '2022-01-10 23:59:59'
- GROUP BY session_id
- HAVING (ifNull(argMinMerge(snapshot_source), 'web') == 'mobile') == 0
- AND max(is_deleted) = 0)
- WHERE session_id NOT IN
- (SELECT DISTINCT session_id
- FROM session_replay_events
- WHERE min_first_timestamp >= '2022-01-09 00:00:00'
- AND min_first_timestamp < '2022-01-10 00:00:00'
- GROUP BY session_id)
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.71
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.83
'''
SELECT team_id,
@@ -1419,7 +1689,7 @@
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.72
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.84
'''
SELECT team_id,
@@ -1443,30 +1713,7 @@
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.73
- '''
-
- SELECT team_id,
- count(distinct session_id) as count
- FROM
- (SELECT any(team_id) as team_id,
- session_id
- FROM session_replay_events
- WHERE min_first_timestamp >= '2022-01-10 00:00:00'
- AND min_first_timestamp < '2022-01-10 23:59:59'
- GROUP BY session_id
- HAVING (ifNull(argMinMerge(snapshot_source), 'web') == 'mobile') == 1
- AND max(is_deleted) = 0)
- WHERE session_id NOT IN
- (SELECT DISTINCT session_id
- FROM session_replay_events
- WHERE min_first_timestamp >= '2022-01-09 00:00:00'
- AND min_first_timestamp < '2022-01-10 00:00:00'
- GROUP BY session_id)
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.74
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.85
'''
SELECT team_id,
@@ -1482,66 +1729,15 @@
HAVING (ifNull(argMinMerge(snapshot_source), 'web') == 'mobile') == 1
AND max(is_deleted) = 0)
WHERE session_id NOT IN
- (SELECT DISTINCT session_id
- FROM session_replay_events
- WHERE min_first_timestamp >= '2022-01-09 00:00:00'
- AND min_first_timestamp < '2022-01-10 00:00:00'
- GROUP BY session_id)
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.75
- '''
-
- SELECT team_id,
- count(distinct session_id) as count
- FROM
- (SELECT any(team_id) as team_id,
- session_id
- FROM session_replay_events
- WHERE min_first_timestamp >= '2022-01-10 00:00:00'
- AND min_first_timestamp < '2022-01-10 23:59:59'
- GROUP BY session_id
- HAVING (ifNull(argMinMerge(snapshot_source), 'web') == 'mobile') == 1
- AND max(is_deleted) = 0)
- WHERE session_id NOT IN
- (SELECT DISTINCT session_id
- FROM session_replay_events
- WHERE min_first_timestamp >= '2022-01-09 00:00:00'
- AND min_first_timestamp < '2022-01-10 00:00:00'
- GROUP BY session_id)
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.76
- '''
-
- SELECT distinct_id as team,
- sum(toInt64OrZero(replaceRegexpAll(JSONExtractRaw(properties, 'count'), '^"|"$', ''))) as sum
- FROM events
- WHERE team_id = 99999
- AND event='decide usage'
- AND timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- AND has(['correct'], replaceRegexpAll(JSONExtractRaw(properties, 'token'), '^"|"$', ''))
- GROUP BY team
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.77
- '''
-
- SELECT distinct_id as team,
- sum(toInt64OrZero(replaceRegexpAll(JSONExtractRaw(properties, 'count'), '^"|"$', ''))) as sum
- FROM events
- WHERE team_id = 99999
- AND event='local evaluation usage'
- AND timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- AND has(['correct'], replaceRegexpAll(JSONExtractRaw(properties, 'token'), '^"|"$', ''))
- GROUP BY team
+ (SELECT DISTINCT session_id
+ FROM session_replay_events
+ WHERE min_first_timestamp >= '2022-01-09 00:00:00'
+ AND min_first_timestamp < '2022-01-10 00:00:00'
+ GROUP BY session_id)
+ GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.78
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.86
'''
WITH JSONExtractInt(log_comment, 'team_id') as team_id,
JSONExtractString(log_comment, 'query_type') as query_type,
@@ -1560,7 +1756,7 @@
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.79
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.87
'''
WITH JSONExtractInt(log_comment, 'team_id') as team_id,
JSONExtractString(log_comment, 'query_type') as query_type,
@@ -1579,47 +1775,7 @@
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.8
- '''
-
- SELECT team_id,
- multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node-mcp', 'node_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python-mcp', 'python_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-edge', 'edge_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-convex', 'convex_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-kmp', 'kmp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rails', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-aspnetcore', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,
- count(1) as count
- FROM events PREWHERE timestamp >= '2022-01-10 16:00:00'
- AND timestamp < '2022-01-10 18:00:00'
- WHERE (event LIKE 'helicone%'
- OR event LIKE 'langfuse%'
- OR event LIKE 'keywords_ai%'
- OR event LIKE 'traceloop%'
- OR replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('web',
- 'js',
- 'posthog-node',
- 'posthog-node-mcp',
- 'posthog-python-mcp',
- 'posthog-edge',
- 'posthog-convex',
- 'posthog-android',
- 'posthog-kmp',
- 'posthog-flutter',
- 'posthog-ios',
- 'posthog-go',
- 'posthog-java',
- 'posthog-server',
- 'posthog-react-native',
- 'posthog-ruby',
- 'posthog-rails',
- 'posthog-python',
- 'posthog-php',
- 'posthog-dotnet',
- 'posthog-aspnetcore',
- 'posthog-elixir',
- 'posthog-unity',
- 'posthog-rs'))
- GROUP BY team_id,
- metric
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.80
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.88
'''
WITH JSONExtractInt(log_comment, 'team_id') as team_id,
JSONExtractString(log_comment, 'query_type') as query_type,
@@ -1638,7 +1794,7 @@
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.81
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.89
'''
WITH JSONExtractInt(log_comment, 'team_id') as team_id,
JSONExtractString(log_comment, 'query_type') as query_type,
@@ -1657,7 +1813,20 @@
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.82
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.9
+ '''
+
+ SELECT team_id,
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events
+ WHERE timestamp >= '2022-01-10 18:00:00'
+ AND timestamp < '2022-01-10 20:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.90
'''
WITH JSONExtractInt(log_comment, 'team_id') as team_id,
JSONExtractString(log_comment, 'query_type') as query_type,
@@ -1676,7 +1845,7 @@
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.83
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.91
'''
WITH JSONExtractInt(log_comment, 'team_id') as team_id,
JSONExtractString(log_comment, 'query_type') as query_type,
@@ -1695,7 +1864,7 @@
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.84
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.92
'''
WITH JSONExtractInt(log_comment, 'team_id') as team_id,
JSONExtractString(log_comment, 'query_type') as query_type,
@@ -1715,7 +1884,7 @@
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.85
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.93
'''
WITH JSONExtractInt(log_comment, 'team_id') as team_id,
JSONExtractString(log_comment, 'query_type') as query_type,
@@ -1735,7 +1904,7 @@
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.86
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.94
'''
WITH JSONExtractInt(log_comment, 'team_id') as team_id,
JSONExtractString(log_comment, 'query_type') as query_type,
@@ -1755,7 +1924,7 @@
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.87
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.95
'''
WITH JSONExtractInt(log_comment, 'team_id') as team_id,
JSONExtractString(log_comment, 'query_type') as query_type,
@@ -1775,7 +1944,7 @@
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.88
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.96
'''
WITH JSONExtractInt(log_comment, 'team_id') as team_id,
JSONExtractString(log_comment, 'query_type') as query_type,
@@ -1795,7 +1964,7 @@
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.89
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.97
'''
WITH JSONExtractInt(log_comment, 'team_id') as team_id,
JSONExtractString(log_comment, 'query_type') as query_type,
@@ -1815,71 +1984,7 @@
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.9
- '''
-
- SELECT team_id,
- multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'web', 'web_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'js', 'web_lite_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node', 'node_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-node-mcp', 'node_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python-mcp', 'python_mcp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-edge', 'edge_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-convex', 'convex_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-android', 'android_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-kmp', 'kmp_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-flutter', 'flutter_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ios', 'ios_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-go', 'go_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-java', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-server', 'java_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-react-native', 'react_native_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-ruby', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rails', 'ruby_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-python', 'python_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-php', 'php_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-dotnet', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-aspnetcore', 'dotnet_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-elixir', 'elixir_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-unity', 'unity_events', replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') = 'posthog-rs', 'rust_events', 'other') AS metric,
- count(1) as count
- FROM events PREWHERE timestamp >= '2022-01-10 18:00:00'
- AND timestamp < '2022-01-10 20:00:00'
- WHERE (event LIKE 'helicone%'
- OR event LIKE 'langfuse%'
- OR event LIKE 'keywords_ai%'
- OR event LIKE 'traceloop%'
- OR replaceRegexpAll(JSONExtractRaw(properties, '$lib'), '^"|"$', '') IN ('web',
- 'js',
- 'posthog-node',
- 'posthog-node-mcp',
- 'posthog-python-mcp',
- 'posthog-edge',
- 'posthog-convex',
- 'posthog-android',
- 'posthog-kmp',
- 'posthog-flutter',
- 'posthog-ios',
- 'posthog-go',
- 'posthog-java',
- 'posthog-server',
- 'posthog-react-native',
- 'posthog-ruby',
- 'posthog-rails',
- 'posthog-python',
- 'posthog-php',
- 'posthog-dotnet',
- 'posthog-aspnetcore',
- 'posthog-elixir',
- 'posthog-unity',
- 'posthog-rs'))
- GROUP BY team_id,
- metric
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.90
- '''
-
- SELECT team_id,
- COUNT() as count
- FROM events
- WHERE event = 'survey sent'
- AND timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- AND uuid IN
- (SELECT argMax(uuid, timestamp)
- FROM events
- WHERE timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- AND event = 'survey sent'
- GROUP BY team_id,
- replaceRegexpAll(JSONExtractRaw(properties, '$survey_id'), '^"|"$', ''),
- CASE
- WHEN COALESCE(replaceRegexpAll(JSONExtractRaw(properties, '$survey_submission_id'), '^"|"$', ''), '') = '' THEN toString(uuid)
- ELSE replaceRegexpAll(JSONExtractRaw(properties, '$survey_submission_id'), '^"|"$', '')
- END)
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.91
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.98
'''
SELECT team_id,
@@ -1894,7 +1999,7 @@
metric_name
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.92
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.99
'''
SELECT team_id,
@@ -1908,108 +2013,3 @@
metric_name
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.93
- '''
-
- SELECT team_id,
- SUM(count) as count
- FROM app_metrics2
- WHERE app_source='hog_function'
- AND metric_name IN ('billable_invocation')
- AND timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.94
- '''
-
- SELECT team_id,
- COUNT() - uniqExactIf(request_id, verified
- AND NOT relay
- AND request_id != '') AS count,
- max(relay) AS has_verified_relay
- FROM
- (SELECT team_id,
- replaceRegexpAll(JSONExtractRaw(properties, '$ai_gateway_verified'), '^"|"$', '') IN ('true',
- '1') AS verified,
- if(verified, replaceRegexpAll(JSONExtractRaw(properties, '$ai_gateway_request_id'), '^"|"$', ''), '') AS request_id,
- if(verified, replaceRegexpAll(JSONExtractRaw(properties, '$ai_gateway_relay'), '^"|"$', ''), '') IN ('true',
- '1') AS relay
- FROM events
- WHERE startsWith(event, '$ai_')
- AND timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 23:59:59')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.95
- '''
-
- SELECT team_id,
- SUM(count) as count
- FROM app_metrics2
- WHERE app_source='hog_flow'
- AND metric_name IN ('billable_invocation')
- AND metric_kind IN ('email')
- AND timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.96
- '''
-
- SELECT team_id,
- SUM(count) as count
- FROM app_metrics2
- WHERE app_source='hog_flow'
- AND metric_name IN ('billable_invocation')
- AND metric_kind IN ('push')
- AND timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.97
- '''
-
- SELECT team_id,
- SUM(count) as count
- FROM app_metrics2
- WHERE app_source='hog_flow'
- AND metric_name IN ('billable_invocation')
- AND metric_kind IN ('sms')
- AND timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.98
- '''
-
- SELECT team_id,
- SUM(count) as count
- FROM app_metrics2
- WHERE app_source='hog_flow'
- AND metric_name IN ('billable_invocation')
- AND metric_kind IN ('fetch',
- 'push')
- AND timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests.99
- '''
-
- SELECT team_id,
- SUM(count) as count
- FROM app_metrics2
- WHERE app_source='logs'
- AND metric_name='bytes_ingested'
- AND timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- GROUP BY team_id
- '''
-# ---
diff --git a/posthog/tasks/test/__snapshots__/test_usage_report.new_events_schema.ambr b/posthog/tasks/test/__snapshots__/test_usage_report.new_events_schema.ambr
index cf79a0e9b32a..fb90d117973a 100644
--- a/posthog/tasks/test/__snapshots__/test_usage_report.new_events_schema.ambr
+++ b/posthog/tasks/test/__snapshots__/test_usage_report.new_events_schema.ambr
@@ -3,524 +3,276 @@
'''
SELECT team_id,
- multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'web', 'web_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'js', 'web_lite_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-node', 'node_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-node-mcp', 'node_mcp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-python-mcp', 'python_mcp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-edge', 'edge_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-convex', 'convex_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-android', 'android_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-kmp', 'kmp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-flutter', 'flutter_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-ios', 'ios_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-go', 'go_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-java', 'java_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-server', 'java_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-react-native', 'react_native_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-ruby', 'ruby_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-rails', 'ruby_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-python', 'python_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-php', 'php_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-dotnet', 'dotnet_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-aspnetcore', 'dotnet_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-elixir', 'elixir_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-unity', 'unity_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-rs', 'rust_events', 'other') AS metric,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 20:00:00'
- AND timestamp < '2022-01-10 22:00:00'
- WHERE (event LIKE 'helicone%'
- OR event LIKE 'langfuse%'
- OR event LIKE 'keywords_ai%'
- OR event LIKE 'traceloop%'
- OR ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('web',
- 'js',
- 'posthog-node',
- 'posthog-node-mcp',
- 'posthog-python-mcp',
- 'posthog-edge',
- 'posthog-convex',
- 'posthog-android',
- 'posthog-kmp',
- 'posthog-flutter',
- 'posthog-ios',
- 'posthog-go',
- 'posthog-java',
- 'posthog-server',
- 'posthog-react-native',
- 'posthog-ruby',
- 'posthog-rails',
- 'posthog-python',
- 'posthog-php',
- 'posthog-dotnet',
- 'posthog-aspnetcore',
- 'posthog-elixir',
- 'posthog-unity',
- 'posthog-rs'))
- GROUP BY team_id,
- metric
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 20:00:00'
+ AND timestamp < '2022-01-10 22:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.11]
'''
SELECT team_id,
- multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'web', 'web_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'js', 'web_lite_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-node', 'node_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-node-mcp', 'node_mcp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-python-mcp', 'python_mcp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-edge', 'edge_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-convex', 'convex_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-android', 'android_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-kmp', 'kmp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-flutter', 'flutter_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-ios', 'ios_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-go', 'go_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-java', 'java_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-server', 'java_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-react-native', 'react_native_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-ruby', 'ruby_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-rails', 'ruby_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-python', 'python_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-php', 'php_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-dotnet', 'dotnet_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-aspnetcore', 'dotnet_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-elixir', 'elixir_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-unity', 'unity_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-rs', 'rust_events', 'other') AS metric,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 22:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- WHERE (event LIKE 'helicone%'
- OR event LIKE 'langfuse%'
- OR event LIKE 'keywords_ai%'
- OR event LIKE 'traceloop%'
- OR ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('web',
- 'js',
- 'posthog-node',
- 'posthog-node-mcp',
- 'posthog-python-mcp',
- 'posthog-edge',
- 'posthog-convex',
- 'posthog-android',
- 'posthog-kmp',
- 'posthog-flutter',
- 'posthog-ios',
- 'posthog-go',
- 'posthog-java',
- 'posthog-server',
- 'posthog-react-native',
- 'posthog-ruby',
- 'posthog-rails',
- 'posthog-python',
- 'posthog-php',
- 'posthog-dotnet',
- 'posthog-aspnetcore',
- 'posthog-elixir',
- 'posthog-unity',
- 'posthog-rs'))
- GROUP BY team_id,
- metric
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 22:00:00'
+ AND timestamp < '2022-01-10 23:59:59'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.12]
'''
SELECT team_id,
- ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') AS sdk_lib,
- ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') AS ai_lib,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 02:00:00'
- AND startsWith(event, '$ai_')
- WHERE ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('posthog-node',
- 'posthog-python',
- 'posthog-dotnet',
- 'posthog-aspnetcore')
- AND ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') IN ('posthog-openclaw',
- 'posthog-opencode',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- sdk_lib,
- ai_lib
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 00:00:00'
+ AND timestamp < '2022-01-10 02:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND person_mode IN ('full',
+ 'force_upgrade')
+ GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.13]
'''
SELECT team_id,
- ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') AS sdk_lib,
- ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') AS ai_lib,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 02:00:00'
- AND timestamp < '2022-01-10 04:00:00'
- AND startsWith(event, '$ai_')
- WHERE ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('posthog-node',
- 'posthog-python',
- 'posthog-dotnet',
- 'posthog-aspnetcore')
- AND ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') IN ('posthog-openclaw',
- 'posthog-opencode',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- sdk_lib,
- ai_lib
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 02:00:00'
+ AND timestamp < '2022-01-10 04:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND person_mode IN ('full',
+ 'force_upgrade')
+ GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.14]
'''
SELECT team_id,
- ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') AS sdk_lib,
- ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') AS ai_lib,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 04:00:00'
- AND timestamp < '2022-01-10 06:00:00'
- AND startsWith(event, '$ai_')
- WHERE ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('posthog-node',
- 'posthog-python',
- 'posthog-dotnet',
- 'posthog-aspnetcore')
- AND ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') IN ('posthog-openclaw',
- 'posthog-opencode',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- sdk_lib,
- ai_lib
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 04:00:00'
+ AND timestamp < '2022-01-10 06:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND person_mode IN ('full',
+ 'force_upgrade')
+ GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.15]
'''
SELECT team_id,
- ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') AS sdk_lib,
- ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') AS ai_lib,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 06:00:00'
- AND timestamp < '2022-01-10 08:00:00'
- AND startsWith(event, '$ai_')
- WHERE ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('posthog-node',
- 'posthog-python',
- 'posthog-dotnet',
- 'posthog-aspnetcore')
- AND ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') IN ('posthog-openclaw',
- 'posthog-opencode',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- sdk_lib,
- ai_lib
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 06:00:00'
+ AND timestamp < '2022-01-10 08:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND person_mode IN ('full',
+ 'force_upgrade')
+ GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.16]
'''
SELECT team_id,
- ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') AS sdk_lib,
- ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') AS ai_lib,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 08:00:00'
- AND timestamp < '2022-01-10 10:00:00'
- AND startsWith(event, '$ai_')
- WHERE ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('posthog-node',
- 'posthog-python',
- 'posthog-dotnet',
- 'posthog-aspnetcore')
- AND ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') IN ('posthog-openclaw',
- 'posthog-opencode',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- sdk_lib,
- ai_lib
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 08:00:00'
+ AND timestamp < '2022-01-10 10:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND person_mode IN ('full',
+ 'force_upgrade')
+ GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.17]
'''
SELECT team_id,
- ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') AS sdk_lib,
- ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') AS ai_lib,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 10:00:00'
- AND timestamp < '2022-01-10 12:00:00'
- AND startsWith(event, '$ai_')
- WHERE ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('posthog-node',
- 'posthog-python',
- 'posthog-dotnet',
- 'posthog-aspnetcore')
- AND ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') IN ('posthog-openclaw',
- 'posthog-opencode',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- sdk_lib,
- ai_lib
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 10:00:00'
+ AND timestamp < '2022-01-10 12:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND person_mode IN ('full',
+ 'force_upgrade')
+ GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.18]
'''
SELECT team_id,
- ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') AS sdk_lib,
- ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') AS ai_lib,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 12:00:00'
- AND timestamp < '2022-01-10 14:00:00'
- AND startsWith(event, '$ai_')
- WHERE ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('posthog-node',
- 'posthog-python',
- 'posthog-dotnet',
- 'posthog-aspnetcore')
- AND ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') IN ('posthog-openclaw',
- 'posthog-opencode',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- sdk_lib,
- ai_lib
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 12:00:00'
+ AND timestamp < '2022-01-10 14:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND person_mode IN ('full',
+ 'force_upgrade')
+ GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.19]
'''
SELECT team_id,
- ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') AS sdk_lib,
- ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') AS ai_lib,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 14:00:00'
- AND timestamp < '2022-01-10 16:00:00'
- AND startsWith(event, '$ai_')
- WHERE ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('posthog-node',
- 'posthog-python',
- 'posthog-dotnet',
- 'posthog-aspnetcore')
- AND ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') IN ('posthog-openclaw',
- 'posthog-opencode',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- sdk_lib,
- ai_lib
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 14:00:00'
+ AND timestamp < '2022-01-10 16:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND person_mode IN ('full',
+ 'force_upgrade')
+ GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.1]
'''
SELECT team_id,
- multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'web', 'web_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'js', 'web_lite_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-node', 'node_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-node-mcp', 'node_mcp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-python-mcp', 'python_mcp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-edge', 'edge_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-convex', 'convex_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-android', 'android_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-kmp', 'kmp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-flutter', 'flutter_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-ios', 'ios_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-go', 'go_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-java', 'java_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-server', 'java_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-react-native', 'react_native_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-ruby', 'ruby_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-rails', 'ruby_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-python', 'python_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-php', 'php_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-dotnet', 'dotnet_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-aspnetcore', 'dotnet_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-elixir', 'elixir_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-unity', 'unity_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-rs', 'rust_events', 'other') AS metric,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 02:00:00'
- AND timestamp < '2022-01-10 04:00:00'
- WHERE (event LIKE 'helicone%'
- OR event LIKE 'langfuse%'
- OR event LIKE 'keywords_ai%'
- OR event LIKE 'traceloop%'
- OR ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('web',
- 'js',
- 'posthog-node',
- 'posthog-node-mcp',
- 'posthog-python-mcp',
- 'posthog-edge',
- 'posthog-convex',
- 'posthog-android',
- 'posthog-kmp',
- 'posthog-flutter',
- 'posthog-ios',
- 'posthog-go',
- 'posthog-java',
- 'posthog-server',
- 'posthog-react-native',
- 'posthog-ruby',
- 'posthog-rails',
- 'posthog-python',
- 'posthog-php',
- 'posthog-dotnet',
- 'posthog-aspnetcore',
- 'posthog-elixir',
- 'posthog-unity',
- 'posthog-rs'))
- GROUP BY team_id,
- metric
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 02:00:00'
+ AND timestamp < '2022-01-10 04:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.20]
'''
SELECT team_id,
- ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') AS sdk_lib,
- ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') AS ai_lib,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 16:00:00'
- AND timestamp < '2022-01-10 18:00:00'
- AND startsWith(event, '$ai_')
- WHERE ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('posthog-node',
- 'posthog-python',
- 'posthog-dotnet',
- 'posthog-aspnetcore')
- AND ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') IN ('posthog-openclaw',
- 'posthog-opencode',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- sdk_lib,
- ai_lib
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 16:00:00'
+ AND timestamp < '2022-01-10 18:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND person_mode IN ('full',
+ 'force_upgrade')
+ GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.21]
'''
SELECT team_id,
- ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') AS sdk_lib,
- ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') AS ai_lib,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 18:00:00'
- AND timestamp < '2022-01-10 20:00:00'
- AND startsWith(event, '$ai_')
- WHERE ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('posthog-node',
- 'posthog-python',
- 'posthog-dotnet',
- 'posthog-aspnetcore')
- AND ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') IN ('posthog-openclaw',
- 'posthog-opencode',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- sdk_lib,
- ai_lib
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 18:00:00'
+ AND timestamp < '2022-01-10 20:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND person_mode IN ('full',
+ 'force_upgrade')
+ GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.22]
'''
SELECT team_id,
- ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') AS sdk_lib,
- ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') AS ai_lib,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 20:00:00'
- AND timestamp < '2022-01-10 22:00:00'
- AND startsWith(event, '$ai_')
- WHERE ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('posthog-node',
- 'posthog-python',
- 'posthog-dotnet',
- 'posthog-aspnetcore')
- AND ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') IN ('posthog-openclaw',
- 'posthog-opencode',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- sdk_lib,
- ai_lib
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 20:00:00'
+ AND timestamp < '2022-01-10 22:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND person_mode IN ('full',
+ 'force_upgrade')
+ GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.23]
'''
SELECT team_id,
- ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') AS sdk_lib,
- ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') AS ai_lib,
- count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 22:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- AND startsWith(event, '$ai_')
- WHERE ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('posthog-node',
- 'posthog-python',
- 'posthog-dotnet',
- 'posthog-aspnetcore')
- AND ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') IN ('posthog-openclaw',
- 'posthog-opencode',
- '@posthog/pi',
- 'posthog-ai')
- GROUP BY team_id,
- sdk_lib,
- ai_lib
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 22:00:00'
+ AND timestamp < '2022-01-10 23:59:59'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND person_mode IN ('full',
+ 'force_upgrade')
+ GROUP BY team_id
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.24]
'''
+ SELECT team_id,
+ COUNT() as count
+ FROM events_json
+ WHERE event = 'survey sent'
+ AND timestamp >= '2022-01-10 00:00:00'
+ AND timestamp < '2022-01-10 23:59:59'
+ AND uuid IN
+ (SELECT argMax(uuid, timestamp)
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 00:00:00'
+ AND timestamp < '2022-01-10 23:59:59'
+ AND event = 'survey sent'
+ GROUP BY team_id,
+ ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$survey_id`), '\\/', '/'), toJSONString(properties.^`$survey_id`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$survey_id`), '\\/', '/'), toJSONString(properties.^`$survey_id`)), if(ascii(toString(properties.`$survey_id`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$survey_id`), '\\/', '/'), toJSONString(properties.`$survey_id`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$survey_id`), '\\/', '/'), toJSONString(properties.`$survey_id`)), '[]'), '{}'), toString(properties.`$survey_id`))), ''),
+ CASE
+ WHEN COALESCE(ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$survey_submission_id`), '\\/', '/'), toJSONString(properties.^`$survey_submission_id`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$survey_submission_id`), '\\/', '/'), toJSONString(properties.^`$survey_submission_id`)), if(ascii(toString(properties.`$survey_submission_id`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$survey_submission_id`), '\\/', '/'), toJSONString(properties.`$survey_submission_id`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$survey_submission_id`), '\\/', '/'), toJSONString(properties.`$survey_submission_id`)), '[]'), '{}'), toString(properties.`$survey_submission_id`))), ''), '') = '' THEN toString(uuid)
+ ELSE ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$survey_submission_id`), '\\/', '/'), toJSONString(properties.^`$survey_submission_id`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$survey_submission_id`), '\\/', '/'), toJSONString(properties.^`$survey_submission_id`)), if(ascii(toString(properties.`$survey_submission_id`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$survey_submission_id`), '\\/', '/'), toJSONString(properties.`$survey_submission_id`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$survey_submission_id`), '\\/', '/'), toJSONString(properties.`$survey_submission_id`)), '[]'), '{}'), toString(properties.`$survey_submission_id`))), '')
+ END)
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.25]
+ '''
+
+ SELECT team_id,
+ COUNT() - uniqExactIf(request_id, verified
+ AND NOT relay
+ AND request_id != '') AS count,
+ max(relay) AS has_verified_relay
+ FROM
+ (SELECT team_id,
+ ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_gateway_verified`), '\\/', '/'), toJSONString(properties.^`$ai_gateway_verified`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_gateway_verified`), '\\/', '/'), toJSONString(properties.^`$ai_gateway_verified`)), if(ascii(toString(properties.`$ai_gateway_verified`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_gateway_verified`), '\\/', '/'), toJSONString(properties.`$ai_gateway_verified`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_gateway_verified`), '\\/', '/'), toJSONString(properties.`$ai_gateway_verified`)), '[]'), '{}'), toString(properties.`$ai_gateway_verified`))), '') IN ('true',
+ '1') AS verified,
+ if(verified, ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_gateway_request_id`), '\\/', '/'), toJSONString(properties.^`$ai_gateway_request_id`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_gateway_request_id`), '\\/', '/'), toJSONString(properties.^`$ai_gateway_request_id`)), if(ascii(toString(properties.`$ai_gateway_request_id`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_gateway_request_id`), '\\/', '/'), toJSONString(properties.`$ai_gateway_request_id`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_gateway_request_id`), '\\/', '/'), toJSONString(properties.`$ai_gateway_request_id`)), '[]'), '{}'), toString(properties.`$ai_gateway_request_id`))), ''), '') AS request_id,
+ if(verified, ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_gateway_relay`), '\\/', '/'), toJSONString(properties.^`$ai_gateway_relay`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_gateway_relay`), '\\/', '/'), toJSONString(properties.^`$ai_gateway_relay`)), if(ascii(toString(properties.`$ai_gateway_relay`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_gateway_relay`), '\\/', '/'), toJSONString(properties.`$ai_gateway_relay`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_gateway_relay`), '\\/', '/'), toJSONString(properties.`$ai_gateway_relay`)), '[]'), '{}'), toString(properties.`$ai_gateway_relay`))), ''), '') IN ('true',
+ '1') AS relay
+ FROM events_json
+ WHERE startsWith(event, '$ai_')
+ AND timestamp >= '2022-01-10 00:00:00'
+ AND timestamp < '2022-01-10 23:59:59')
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.26]
+ '''
+
SELECT team_id,
multiIf(ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'web', 'web', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
@@ -545,74 +297,41 @@
library
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.25]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 02:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.26]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 02:00:00'
- AND timestamp < '2022-01-10 04:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- GROUP BY team_id
- '''
-# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.27]
'''
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ SELECT distinct_id as team,
+ sum(toInt64OrZero(ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^count), '\\/', '/'), toJSONString(properties.^count)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^count), '\\/', '/'), toJSONString(properties.^count)), if(ascii(toString(properties.count)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.count), '\\/', '/'), toJSONString(properties.count))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.count), '\\/', '/'), toJSONString(properties.count)), '[]'), '{}'), toString(properties.count))), ''))) as sum
FROM events_json
- WHERE timestamp >= '2022-01-10 04:00:00'
- AND timestamp < '2022-01-10 06:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- GROUP BY team_id
+ WHERE team_id = 99999
+ AND event='decide usage'
+ AND timestamp >= '2022-01-10 00:00:00'
+ AND timestamp < '2022-01-10 23:59:59'
+ AND has(['correct'], ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^token), '\\/', '/'), toJSONString(properties.^token)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^token), '\\/', '/'), toJSONString(properties.^token)), if(ascii(toString(properties.token)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.token), '\\/', '/'), toJSONString(properties.token))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.token), '\\/', '/'), toJSONString(properties.token)), '[]'), '{}'), toString(properties.token))), ''))
+ GROUP BY team
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.28]
'''
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ SELECT distinct_id as team,
+ sum(toInt64OrZero(ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^count), '\\/', '/'), toJSONString(properties.^count)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^count), '\\/', '/'), toJSONString(properties.^count)), if(ascii(toString(properties.count)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.count), '\\/', '/'), toJSONString(properties.count))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.count), '\\/', '/'), toJSONString(properties.count)), '[]'), '{}'), toString(properties.count))), ''))) as sum
FROM events_json
- WHERE timestamp >= '2022-01-10 06:00:00'
- AND timestamp < '2022-01-10 08:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- GROUP BY team_id
+ WHERE team_id = 99999
+ AND event='local evaluation usage'
+ AND timestamp >= '2022-01-10 00:00:00'
+ AND timestamp < '2022-01-10 23:59:59'
+ AND has(['correct'], ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^token), '\\/', '/'), toJSONString(properties.^token)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^token), '\\/', '/'), toJSONString(properties.^token)), if(ascii(toString(properties.token)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.token), '\\/', '/'), toJSONString(properties.token))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.token), '\\/', '/'), toJSONString(properties.token)), '[]'), '{}'), toString(properties.token))), ''))
+ GROUP BY team
'''
# ---
# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.29]
'''
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 08:00:00'
- AND timestamp < '2022-01-10 10:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.2]
- '''
-
SELECT team_id,
multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'web', 'web_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
@@ -640,8 +359,8 @@
AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-unity', 'unity_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-rs', 'rust_events', 'other') AS metric,
count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 04:00:00'
- AND timestamp < '2022-01-10 06:00:00'
+ FROM events_json PREWHERE timestamp >= '2022-01-10 00:00:00'
+ AND timestamp < '2022-01-10 02:00:00'
WHERE (event LIKE 'helicone%'
OR event LIKE 'langfuse%'
OR event LIKE 'keywords_ai%'
@@ -675,143 +394,150 @@
metric
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.30]
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.2]
'''
SELECT team_id,
count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
FROM events_json
- WHERE timestamp >= '2022-01-10 10:00:00'
- AND timestamp < '2022-01-10 12:00:00'
+ WHERE timestamp >= '2022-01-10 04:00:00'
+ AND timestamp < '2022-01-10 06:00:00'
AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
AND NOT startsWith(event, '$ai_')
GROUP BY team_id
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.31]
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.30]
'''
SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 12:00:00'
- AND timestamp < '2022-01-10 14:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- GROUP BY team_id
+ multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'web', 'web_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'js', 'web_lite_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-node', 'node_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-node-mcp', 'node_mcp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-python-mcp', 'python_mcp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-edge', 'edge_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-convex', 'convex_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-android', 'android_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-kmp', 'kmp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-flutter', 'flutter_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-ios', 'ios_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-go', 'go_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-java', 'java_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-server', 'java_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-react-native', 'react_native_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-ruby', 'ruby_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-rails', 'ruby_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-python', 'python_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-php', 'php_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-dotnet', 'dotnet_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-aspnetcore', 'dotnet_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-elixir', 'elixir_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-unity', 'unity_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-rs', 'rust_events', 'other') AS metric,
+ count(1) as count
+ FROM events_json PREWHERE timestamp >= '2022-01-10 02:00:00'
+ AND timestamp < '2022-01-10 04:00:00'
+ WHERE (event LIKE 'helicone%'
+ OR event LIKE 'langfuse%'
+ OR event LIKE 'keywords_ai%'
+ OR event LIKE 'traceloop%'
+ OR ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('web',
+ 'js',
+ 'posthog-node',
+ 'posthog-node-mcp',
+ 'posthog-python-mcp',
+ 'posthog-edge',
+ 'posthog-convex',
+ 'posthog-android',
+ 'posthog-kmp',
+ 'posthog-flutter',
+ 'posthog-ios',
+ 'posthog-go',
+ 'posthog-java',
+ 'posthog-server',
+ 'posthog-react-native',
+ 'posthog-ruby',
+ 'posthog-rails',
+ 'posthog-python',
+ 'posthog-php',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore',
+ 'posthog-elixir',
+ 'posthog-unity',
+ 'posthog-rs'))
+ GROUP BY team_id,
+ metric
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.32]
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.31]
'''
SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 14:00:00'
- AND timestamp < '2022-01-10 16:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.33]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 16:00:00'
- AND timestamp < '2022-01-10 18:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.34]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 18:00:00'
- AND timestamp < '2022-01-10 20:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.35]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 20:00:00'
- AND timestamp < '2022-01-10 22:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.36]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 22:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.37]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 02:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.38]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 02:00:00'
- AND timestamp < '2022-01-10 04:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.39]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 04:00:00'
- AND timestamp < '2022-01-10 06:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
+ multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'web', 'web_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'js', 'web_lite_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-node', 'node_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-node-mcp', 'node_mcp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-python-mcp', 'python_mcp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-edge', 'edge_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-convex', 'convex_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-android', 'android_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-kmp', 'kmp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-flutter', 'flutter_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-ios', 'ios_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-go', 'go_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-java', 'java_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-server', 'java_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-react-native', 'react_native_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-ruby', 'ruby_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-rails', 'ruby_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-python', 'python_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-php', 'php_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-dotnet', 'dotnet_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-aspnetcore', 'dotnet_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-elixir', 'elixir_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-unity', 'unity_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-rs', 'rust_events', 'other') AS metric,
+ count(1) as count
+ FROM events_json PREWHERE timestamp >= '2022-01-10 04:00:00'
+ AND timestamp < '2022-01-10 06:00:00'
+ WHERE (event LIKE 'helicone%'
+ OR event LIKE 'langfuse%'
+ OR event LIKE 'keywords_ai%'
+ OR event LIKE 'traceloop%'
+ OR ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('web',
+ 'js',
+ 'posthog-node',
+ 'posthog-node-mcp',
+ 'posthog-python-mcp',
+ 'posthog-edge',
+ 'posthog-convex',
+ 'posthog-android',
+ 'posthog-kmp',
+ 'posthog-flutter',
+ 'posthog-ios',
+ 'posthog-go',
+ 'posthog-java',
+ 'posthog-server',
+ 'posthog-react-native',
+ 'posthog-ruby',
+ 'posthog-rails',
+ 'posthog-python',
+ 'posthog-php',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore',
+ 'posthog-elixir',
+ 'posthog-unity',
+ 'posthog-rs'))
+ GROUP BY team_id,
+ metric
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.3]
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.32]
'''
SELECT team_id,
@@ -876,160 +602,137 @@
metric
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.40]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 06:00:00'
- AND timestamp < '2022-01-10 08:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.41]
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.33]
'''
SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 08:00:00'
- AND timestamp < '2022-01-10 10:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
+ multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'web', 'web_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'js', 'web_lite_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-node', 'node_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-node-mcp', 'node_mcp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-python-mcp', 'python_mcp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-edge', 'edge_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-convex', 'convex_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-android', 'android_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-kmp', 'kmp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-flutter', 'flutter_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-ios', 'ios_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-go', 'go_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-java', 'java_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-server', 'java_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-react-native', 'react_native_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-ruby', 'ruby_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-rails', 'ruby_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-python', 'python_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-php', 'php_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-dotnet', 'dotnet_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-aspnetcore', 'dotnet_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-elixir', 'elixir_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-unity', 'unity_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-rs', 'rust_events', 'other') AS metric,
+ count(1) as count
+ FROM events_json PREWHERE timestamp >= '2022-01-10 08:00:00'
+ AND timestamp < '2022-01-10 10:00:00'
+ WHERE (event LIKE 'helicone%'
+ OR event LIKE 'langfuse%'
+ OR event LIKE 'keywords_ai%'
+ OR event LIKE 'traceloop%'
+ OR ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('web',
+ 'js',
+ 'posthog-node',
+ 'posthog-node-mcp',
+ 'posthog-python-mcp',
+ 'posthog-edge',
+ 'posthog-convex',
+ 'posthog-android',
+ 'posthog-kmp',
+ 'posthog-flutter',
+ 'posthog-ios',
+ 'posthog-go',
+ 'posthog-java',
+ 'posthog-server',
+ 'posthog-react-native',
+ 'posthog-ruby',
+ 'posthog-rails',
+ 'posthog-python',
+ 'posthog-php',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore',
+ 'posthog-elixir',
+ 'posthog-unity',
+ 'posthog-rs'))
+ GROUP BY team_id,
+ metric
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.42]
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.34]
'''
SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 10:00:00'
- AND timestamp < '2022-01-10 12:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.43]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 12:00:00'
- AND timestamp < '2022-01-10 14:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.44]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 14:00:00'
- AND timestamp < '2022-01-10 16:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.45]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 16:00:00'
- AND timestamp < '2022-01-10 18:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.46]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 18:00:00'
- AND timestamp < '2022-01-10 20:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.47]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 20:00:00'
- AND timestamp < '2022-01-10 22:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.48]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 22:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND person_mode IN ('full',
- 'force_upgrade')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.49]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 02:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND (properties.`$group_0` != ''
- OR properties.`$group_1` != ''
- OR properties.`$group_2` != ''
- OR properties.`$group_3` != ''
- OR properties.`$group_4` != '')
- GROUP BY team_id
+ multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'web', 'web_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'js', 'web_lite_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-node', 'node_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-node-mcp', 'node_mcp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-python-mcp', 'python_mcp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-edge', 'edge_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-convex', 'convex_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-android', 'android_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-kmp', 'kmp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-flutter', 'flutter_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-ios', 'ios_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-go', 'go_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-java', 'java_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-server', 'java_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-react-native', 'react_native_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-ruby', 'ruby_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-rails', 'ruby_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-python', 'python_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-php', 'php_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-dotnet', 'dotnet_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-aspnetcore', 'dotnet_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-elixir', 'elixir_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-unity', 'unity_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-rs', 'rust_events', 'other') AS metric,
+ count(1) as count
+ FROM events_json PREWHERE timestamp >= '2022-01-10 10:00:00'
+ AND timestamp < '2022-01-10 12:00:00'
+ WHERE (event LIKE 'helicone%'
+ OR event LIKE 'langfuse%'
+ OR event LIKE 'keywords_ai%'
+ OR event LIKE 'traceloop%'
+ OR ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('web',
+ 'js',
+ 'posthog-node',
+ 'posthog-node-mcp',
+ 'posthog-python-mcp',
+ 'posthog-edge',
+ 'posthog-convex',
+ 'posthog-android',
+ 'posthog-kmp',
+ 'posthog-flutter',
+ 'posthog-ios',
+ 'posthog-go',
+ 'posthog-java',
+ 'posthog-server',
+ 'posthog-react-native',
+ 'posthog-ruby',
+ 'posthog-rails',
+ 'posthog-python',
+ 'posthog-php',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore',
+ 'posthog-elixir',
+ 'posthog-unity',
+ 'posthog-rs'))
+ GROUP BY team_id,
+ metric
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.4]
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.35]
'''
SELECT team_id,
@@ -1059,8 +762,8 @@
AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-unity', 'unity_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-rs', 'rust_events', 'other') AS metric,
count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 08:00:00'
- AND timestamp < '2022-01-10 10:00:00'
+ FROM events_json PREWHERE timestamp >= '2022-01-10 12:00:00'
+ AND timestamp < '2022-01-10 14:00:00'
WHERE (event LIKE 'helicone%'
OR event LIKE 'langfuse%'
OR event LIKE 'keywords_ai%'
@@ -1094,187 +797,137 @@
metric
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.50]
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.36]
'''
SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 02:00:00'
- AND timestamp < '2022-01-10 04:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND (properties.`$group_0` != ''
- OR properties.`$group_1` != ''
- OR properties.`$group_2` != ''
- OR properties.`$group_3` != ''
- OR properties.`$group_4` != '')
- GROUP BY team_id
+ multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'web', 'web_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'js', 'web_lite_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-node', 'node_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-node-mcp', 'node_mcp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-python-mcp', 'python_mcp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-edge', 'edge_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-convex', 'convex_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-android', 'android_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-kmp', 'kmp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-flutter', 'flutter_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-ios', 'ios_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-go', 'go_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-java', 'java_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-server', 'java_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-react-native', 'react_native_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-ruby', 'ruby_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-rails', 'ruby_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-python', 'python_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-php', 'php_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-dotnet', 'dotnet_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-aspnetcore', 'dotnet_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-elixir', 'elixir_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-unity', 'unity_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-rs', 'rust_events', 'other') AS metric,
+ count(1) as count
+ FROM events_json PREWHERE timestamp >= '2022-01-10 14:00:00'
+ AND timestamp < '2022-01-10 16:00:00'
+ WHERE (event LIKE 'helicone%'
+ OR event LIKE 'langfuse%'
+ OR event LIKE 'keywords_ai%'
+ OR event LIKE 'traceloop%'
+ OR ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('web',
+ 'js',
+ 'posthog-node',
+ 'posthog-node-mcp',
+ 'posthog-python-mcp',
+ 'posthog-edge',
+ 'posthog-convex',
+ 'posthog-android',
+ 'posthog-kmp',
+ 'posthog-flutter',
+ 'posthog-ios',
+ 'posthog-go',
+ 'posthog-java',
+ 'posthog-server',
+ 'posthog-react-native',
+ 'posthog-ruby',
+ 'posthog-rails',
+ 'posthog-python',
+ 'posthog-php',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore',
+ 'posthog-elixir',
+ 'posthog-unity',
+ 'posthog-rs'))
+ GROUP BY team_id,
+ metric
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.51]
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.37]
'''
SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 04:00:00'
- AND timestamp < '2022-01-10 06:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND (properties.`$group_0` != ''
- OR properties.`$group_1` != ''
- OR properties.`$group_2` != ''
- OR properties.`$group_3` != ''
- OR properties.`$group_4` != '')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.52]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 06:00:00'
- AND timestamp < '2022-01-10 08:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND (properties.`$group_0` != ''
- OR properties.`$group_1` != ''
- OR properties.`$group_2` != ''
- OR properties.`$group_3` != ''
- OR properties.`$group_4` != '')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.53]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 08:00:00'
- AND timestamp < '2022-01-10 10:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND (properties.`$group_0` != ''
- OR properties.`$group_1` != ''
- OR properties.`$group_2` != ''
- OR properties.`$group_3` != ''
- OR properties.`$group_4` != '')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.54]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 10:00:00'
- AND timestamp < '2022-01-10 12:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND (properties.`$group_0` != ''
- OR properties.`$group_1` != ''
- OR properties.`$group_2` != ''
- OR properties.`$group_3` != ''
- OR properties.`$group_4` != '')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.55]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 12:00:00'
- AND timestamp < '2022-01-10 14:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND (properties.`$group_0` != ''
- OR properties.`$group_1` != ''
- OR properties.`$group_2` != ''
- OR properties.`$group_3` != ''
- OR properties.`$group_4` != '')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.56]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 14:00:00'
- AND timestamp < '2022-01-10 16:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND (properties.`$group_0` != ''
- OR properties.`$group_1` != ''
- OR properties.`$group_2` != ''
- OR properties.`$group_3` != ''
- OR properties.`$group_4` != '')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.57]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 16:00:00'
- AND timestamp < '2022-01-10 18:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND (properties.`$group_0` != ''
- OR properties.`$group_1` != ''
- OR properties.`$group_2` != ''
- OR properties.`$group_3` != ''
- OR properties.`$group_4` != '')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.58]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 18:00:00'
- AND timestamp < '2022-01-10 20:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND (properties.`$group_0` != ''
- OR properties.`$group_1` != ''
- OR properties.`$group_2` != ''
- OR properties.`$group_3` != ''
- OR properties.`$group_4` != '')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.59]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 20:00:00'
- AND timestamp < '2022-01-10 22:00:00'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND (properties.`$group_0` != ''
- OR properties.`$group_1` != ''
- OR properties.`$group_2` != ''
- OR properties.`$group_3` != ''
- OR properties.`$group_4` != '')
- GROUP BY team_id
+ multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'web', 'web_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'js', 'web_lite_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-node', 'node_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-node-mcp', 'node_mcp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-python-mcp', 'python_mcp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-edge', 'edge_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-convex', 'convex_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-android', 'android_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-kmp', 'kmp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-flutter', 'flutter_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-ios', 'ios_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-go', 'go_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-java', 'java_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-server', 'java_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-react-native', 'react_native_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-ruby', 'ruby_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-rails', 'ruby_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-python', 'python_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-php', 'php_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-dotnet', 'dotnet_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-aspnetcore', 'dotnet_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-elixir', 'elixir_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-unity', 'unity_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-rs', 'rust_events', 'other') AS metric,
+ count(1) as count
+ FROM events_json PREWHERE timestamp >= '2022-01-10 16:00:00'
+ AND timestamp < '2022-01-10 18:00:00'
+ WHERE (event LIKE 'helicone%'
+ OR event LIKE 'langfuse%'
+ OR event LIKE 'keywords_ai%'
+ OR event LIKE 'traceloop%'
+ OR ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('web',
+ 'js',
+ 'posthog-node',
+ 'posthog-node-mcp',
+ 'posthog-python-mcp',
+ 'posthog-edge',
+ 'posthog-convex',
+ 'posthog-android',
+ 'posthog-kmp',
+ 'posthog-flutter',
+ 'posthog-ios',
+ 'posthog-go',
+ 'posthog-java',
+ 'posthog-server',
+ 'posthog-react-native',
+ 'posthog-ruby',
+ 'posthog-rails',
+ 'posthog-python',
+ 'posthog-php',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore',
+ 'posthog-elixir',
+ 'posthog-unity',
+ 'posthog-rs'))
+ GROUP BY team_id,
+ metric
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.5]
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.38]
'''
SELECT team_id,
@@ -1304,8 +957,8 @@
AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-unity', 'unity_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-rs', 'rust_events', 'other') AS metric,
count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 10:00:00'
- AND timestamp < '2022-01-10 12:00:00'
+ FROM events_json PREWHERE timestamp >= '2022-01-10 18:00:00'
+ AND timestamp < '2022-01-10 20:00:00'
WHERE (event LIKE 'helicone%'
OR event LIKE 'langfuse%'
OR event LIKE 'keywords_ai%'
@@ -1339,109 +992,7 @@
metric
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.60]
- '''
-
- SELECT team_id,
- count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
- FROM events_json
- WHERE timestamp >= '2022-01-10 22:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
- AND NOT startsWith(event, '$ai_')
- AND (properties.`$group_0` != ''
- OR properties.`$group_1` != ''
- OR properties.`$group_2` != ''
- OR properties.`$group_3` != ''
- OR properties.`$group_4` != '')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.61]
- '''
-
- SELECT distinct_id as team,
- sum(toInt64OrZero(ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^count), '\\/', '/'), toJSONString(properties.^count)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^count), '\\/', '/'), toJSONString(properties.^count)), if(ascii(toString(properties.count)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.count), '\\/', '/'), toJSONString(properties.count))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.count), '\\/', '/'), toJSONString(properties.count)), '[]'), '{}'), toString(properties.count))), ''))) as sum
- FROM events_json
- WHERE team_id = 99999
- AND event='decide usage'
- AND timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- AND has(['correct'], ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^token), '\\/', '/'), toJSONString(properties.^token)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^token), '\\/', '/'), toJSONString(properties.^token)), if(ascii(toString(properties.token)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.token), '\\/', '/'), toJSONString(properties.token))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.token), '\\/', '/'), toJSONString(properties.token)), '[]'), '{}'), toString(properties.token))), ''))
- GROUP BY team
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.62]
- '''
-
- SELECT distinct_id as team,
- sum(toInt64OrZero(ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^count), '\\/', '/'), toJSONString(properties.^count)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^count), '\\/', '/'), toJSONString(properties.^count)), if(ascii(toString(properties.count)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.count), '\\/', '/'), toJSONString(properties.count))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.count), '\\/', '/'), toJSONString(properties.count)), '[]'), '{}'), toString(properties.count))), ''))) as sum
- FROM events_json
- WHERE team_id = 99999
- AND event='local evaluation usage'
- AND timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- AND has(['correct'], ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^token), '\\/', '/'), toJSONString(properties.^token)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^token), '\\/', '/'), toJSONString(properties.^token)), if(ascii(toString(properties.token)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.token), '\\/', '/'), toJSONString(properties.token))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.token), '\\/', '/'), toJSONString(properties.token)), '[]'), '{}'), toString(properties.token))), ''))
- GROUP BY team
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.63]
- '''
-
- SELECT team_id,
- COUNT() as count
- FROM events_json
- WHERE event = 'survey sent'
- AND timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- AND uuid IN
- (SELECT argMax(uuid, timestamp)
- FROM events_json
- WHERE timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 23:59:59'
- AND event = 'survey sent'
- GROUP BY team_id,
- ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$survey_id`), '\\/', '/'), toJSONString(properties.^`$survey_id`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$survey_id`), '\\/', '/'), toJSONString(properties.^`$survey_id`)), if(ascii(toString(properties.`$survey_id`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$survey_id`), '\\/', '/'), toJSONString(properties.`$survey_id`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$survey_id`), '\\/', '/'), toJSONString(properties.`$survey_id`)), '[]'), '{}'), toString(properties.`$survey_id`))), ''),
- CASE
- WHEN COALESCE(ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$survey_submission_id`), '\\/', '/'), toJSONString(properties.^`$survey_submission_id`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$survey_submission_id`), '\\/', '/'), toJSONString(properties.^`$survey_submission_id`)), if(ascii(toString(properties.`$survey_submission_id`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$survey_submission_id`), '\\/', '/'), toJSONString(properties.`$survey_submission_id`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$survey_submission_id`), '\\/', '/'), toJSONString(properties.`$survey_submission_id`)), '[]'), '{}'), toString(properties.`$survey_submission_id`))), ''), '') = '' THEN toString(uuid)
- ELSE ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$survey_submission_id`), '\\/', '/'), toJSONString(properties.^`$survey_submission_id`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$survey_submission_id`), '\\/', '/'), toJSONString(properties.^`$survey_submission_id`)), if(ascii(toString(properties.`$survey_submission_id`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$survey_submission_id`), '\\/', '/'), toJSONString(properties.`$survey_submission_id`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$survey_submission_id`), '\\/', '/'), toJSONString(properties.`$survey_submission_id`)), '[]'), '{}'), toString(properties.`$survey_submission_id`))), '')
- END)
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.64]
- '''
-
- SELECT team_id,
- COUNT() - uniqExactIf(request_id, verified
- AND NOT relay
- AND request_id != '') AS count,
- max(relay) AS has_verified_relay
- FROM
- (SELECT team_id,
- ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_gateway_verified`), '\\/', '/'), toJSONString(properties.^`$ai_gateway_verified`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_gateway_verified`), '\\/', '/'), toJSONString(properties.^`$ai_gateway_verified`)), if(ascii(toString(properties.`$ai_gateway_verified`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_gateway_verified`), '\\/', '/'), toJSONString(properties.`$ai_gateway_verified`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_gateway_verified`), '\\/', '/'), toJSONString(properties.`$ai_gateway_verified`)), '[]'), '{}'), toString(properties.`$ai_gateway_verified`))), '') IN ('true',
- '1') AS verified,
- if(verified, ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_gateway_request_id`), '\\/', '/'), toJSONString(properties.^`$ai_gateway_request_id`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_gateway_request_id`), '\\/', '/'), toJSONString(properties.^`$ai_gateway_request_id`)), if(ascii(toString(properties.`$ai_gateway_request_id`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_gateway_request_id`), '\\/', '/'), toJSONString(properties.`$ai_gateway_request_id`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_gateway_request_id`), '\\/', '/'), toJSONString(properties.`$ai_gateway_request_id`)), '[]'), '{}'), toString(properties.`$ai_gateway_request_id`))), ''), '') AS request_id,
- if(verified, ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_gateway_relay`), '\\/', '/'), toJSONString(properties.^`$ai_gateway_relay`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_gateway_relay`), '\\/', '/'), toJSONString(properties.^`$ai_gateway_relay`)), if(ascii(toString(properties.`$ai_gateway_relay`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_gateway_relay`), '\\/', '/'), toJSONString(properties.`$ai_gateway_relay`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_gateway_relay`), '\\/', '/'), toJSONString(properties.`$ai_gateway_relay`)), '[]'), '{}'), toString(properties.`$ai_gateway_relay`))), ''), '') IN ('true',
- '1') AS relay
- FROM events_json
- WHERE startsWith(event, '$ai_')
- AND timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 23:59:59')
- GROUP BY team_id
- '''
-# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.6]
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.39]
'''
SELECT team_id,
@@ -1471,8 +1022,8 @@
AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-unity', 'unity_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-rs', 'rust_events', 'other') AS metric,
count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 12:00:00'
- AND timestamp < '2022-01-10 14:00:00'
+ FROM events_json PREWHERE timestamp >= '2022-01-10 20:00:00'
+ AND timestamp < '2022-01-10 22:00:00'
WHERE (event LIKE 'helicone%'
OR event LIKE 'langfuse%'
OR event LIKE 'keywords_ai%'
@@ -1506,7 +1057,20 @@
metric
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.7]
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.3]
+ '''
+
+ SELECT team_id,
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 06:00:00'
+ AND timestamp < '2022-01-10 08:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.40]
'''
SELECT team_id,
@@ -1536,8 +1100,8 @@
AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-unity', 'unity_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-rs', 'rust_events', 'other') AS metric,
count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 14:00:00'
- AND timestamp < '2022-01-10 16:00:00'
+ FROM events_json PREWHERE timestamp >= '2022-01-10 22:00:00'
+ AND timestamp < '2022-01-10 23:59:59'
WHERE (event LIKE 'helicone%'
OR event LIKE 'langfuse%'
OR event LIKE 'keywords_ai%'
@@ -1571,198 +1135,634 @@
metric
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.8]
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.41]
'''
SELECT team_id,
- multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'web', 'web_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'js', 'web_lite_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-node', 'node_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-node-mcp', 'node_mcp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-python-mcp', 'python_mcp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-edge', 'edge_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-convex', 'convex_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-android', 'android_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-kmp', 'kmp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-flutter', 'flutter_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-ios', 'ios_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-go', 'go_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-java', 'java_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-server', 'java_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-react-native', 'react_native_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-ruby', 'ruby_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-rails', 'ruby_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-python', 'python_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-php', 'php_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-dotnet', 'dotnet_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-aspnetcore', 'dotnet_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-elixir', 'elixir_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-unity', 'unity_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-rs', 'rust_events', 'other') AS metric,
+ ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') AS sdk_lib,
+ ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') AS ai_lib,
count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 16:00:00'
- AND timestamp < '2022-01-10 18:00:00'
- WHERE (event LIKE 'helicone%'
- OR event LIKE 'langfuse%'
- OR event LIKE 'keywords_ai%'
- OR event LIKE 'traceloop%'
- OR ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('web',
- 'js',
- 'posthog-node',
- 'posthog-node-mcp',
- 'posthog-python-mcp',
- 'posthog-edge',
- 'posthog-convex',
- 'posthog-android',
- 'posthog-kmp',
- 'posthog-flutter',
- 'posthog-ios',
- 'posthog-go',
- 'posthog-java',
- 'posthog-server',
- 'posthog-react-native',
- 'posthog-ruby',
- 'posthog-rails',
- 'posthog-python',
- 'posthog-php',
- 'posthog-dotnet',
- 'posthog-aspnetcore',
- 'posthog-elixir',
- 'posthog-unity',
- 'posthog-rs'))
+ FROM events_json PREWHERE timestamp >= '2022-01-10 00:00:00'
+ AND timestamp < '2022-01-10 02:00:00'
+ AND startsWith(event, '$ai_')
+ WHERE ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('posthog-node',
+ 'posthog-python',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore')
+ AND ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') IN ('posthog-openclaw',
+ 'posthog-opencode',
+ '@posthog/pi',
+ 'posthog-ai')
GROUP BY team_id,
- metric
+ sdk_lib,
+ ai_lib
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.9]
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.42]
'''
SELECT team_id,
- multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'web', 'web_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'js', 'web_lite_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-node', 'node_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-node-mcp', 'node_mcp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-python-mcp', 'python_mcp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-edge', 'edge_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-convex', 'convex_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-android', 'android_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-kmp', 'kmp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-flutter', 'flutter_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-ios', 'ios_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-go', 'go_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-java', 'java_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-server', 'java_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-react-native', 'react_native_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-ruby', 'ruby_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-rails', 'ruby_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-python', 'python_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-php', 'php_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-dotnet', 'dotnet_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-aspnetcore', 'dotnet_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-elixir', 'elixir_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-unity', 'unity_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-rs', 'rust_events', 'other') AS metric,
+ ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') AS sdk_lib,
+ ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') AS ai_lib,
count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 18:00:00'
- AND timestamp < '2022-01-10 20:00:00'
- WHERE (event LIKE 'helicone%'
- OR event LIKE 'langfuse%'
- OR event LIKE 'keywords_ai%'
- OR event LIKE 'traceloop%'
- OR ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('web',
- 'js',
- 'posthog-node',
- 'posthog-node-mcp',
- 'posthog-python-mcp',
- 'posthog-edge',
- 'posthog-convex',
- 'posthog-android',
- 'posthog-kmp',
- 'posthog-flutter',
- 'posthog-ios',
- 'posthog-go',
- 'posthog-java',
- 'posthog-server',
- 'posthog-react-native',
- 'posthog-ruby',
- 'posthog-rails',
- 'posthog-python',
- 'posthog-php',
- 'posthog-dotnet',
- 'posthog-aspnetcore',
- 'posthog-elixir',
- 'posthog-unity',
- 'posthog-rs'))
+ FROM events_json PREWHERE timestamp >= '2022-01-10 02:00:00'
+ AND timestamp < '2022-01-10 04:00:00'
+ AND startsWith(event, '$ai_')
+ WHERE ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('posthog-node',
+ 'posthog-python',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore')
+ AND ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') IN ('posthog-openclaw',
+ 'posthog-opencode',
+ '@posthog/pi',
+ 'posthog-ai')
GROUP BY team_id,
- metric
+ sdk_lib,
+ ai_lib
'''
# ---
-# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema]
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.43]
'''
SELECT team_id,
- multiIf(event LIKE 'helicone%', 'helicone_events', event LIKE 'langfuse%', 'langfuse_events', event LIKE 'keywords_ai%', 'keywords_ai_events', event LIKE 'traceloop%', 'traceloop_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'web', 'web_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'js', 'web_lite_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-node', 'node_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-node-mcp', 'node_mcp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-python-mcp', 'python_mcp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-edge', 'edge_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-convex', 'convex_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-android', 'android_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-kmp', 'kmp_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-flutter', 'flutter_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-ios', 'ios_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-go', 'go_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-java', 'java_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-server', 'java_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-react-native', 'react_native_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-ruby', 'ruby_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-rails', 'ruby_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-python', 'python_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-php', 'php_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-dotnet', 'dotnet_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-aspnetcore', 'dotnet_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-elixir', 'elixir_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-unity', 'unity_events', ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') = 'posthog-rs', 'rust_events', 'other') AS metric,
+ ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') AS sdk_lib,
+ ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') AS ai_lib,
count(1) as count
- FROM events_json PREWHERE timestamp >= '2022-01-10 00:00:00'
- AND timestamp < '2022-01-10 02:00:00'
- WHERE (event LIKE 'helicone%'
- OR event LIKE 'langfuse%'
- OR event LIKE 'keywords_ai%'
- OR event LIKE 'traceloop%'
- OR ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
- AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('web',
- 'js',
- 'posthog-node',
- 'posthog-node-mcp',
- 'posthog-python-mcp',
- 'posthog-edge',
- 'posthog-convex',
- 'posthog-android',
- 'posthog-kmp',
- 'posthog-flutter',
- 'posthog-ios',
- 'posthog-go',
- 'posthog-java',
- 'posthog-server',
- 'posthog-react-native',
- 'posthog-ruby',
- 'posthog-rails',
- 'posthog-python',
- 'posthog-php',
- 'posthog-dotnet',
- 'posthog-aspnetcore',
- 'posthog-elixir',
- 'posthog-unity',
- 'posthog-rs'))
+ FROM events_json PREWHERE timestamp >= '2022-01-10 04:00:00'
+ AND timestamp < '2022-01-10 06:00:00'
+ AND startsWith(event, '$ai_')
+ WHERE ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('posthog-node',
+ 'posthog-python',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore')
+ AND ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') IN ('posthog-openclaw',
+ 'posthog-opencode',
+ '@posthog/pi',
+ 'posthog-ai')
GROUP BY team_id,
- metric
+ sdk_lib,
+ ai_lib
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.44]
+ '''
+
+ SELECT team_id,
+ ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') AS sdk_lib,
+ ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') AS ai_lib,
+ count(1) as count
+ FROM events_json PREWHERE timestamp >= '2022-01-10 06:00:00'
+ AND timestamp < '2022-01-10 08:00:00'
+ AND startsWith(event, '$ai_')
+ WHERE ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('posthog-node',
+ 'posthog-python',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore')
+ AND ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') IN ('posthog-openclaw',
+ 'posthog-opencode',
+ '@posthog/pi',
+ 'posthog-ai')
+ GROUP BY team_id,
+ sdk_lib,
+ ai_lib
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.45]
+ '''
+
+ SELECT team_id,
+ ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') AS sdk_lib,
+ ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') AS ai_lib,
+ count(1) as count
+ FROM events_json PREWHERE timestamp >= '2022-01-10 08:00:00'
+ AND timestamp < '2022-01-10 10:00:00'
+ AND startsWith(event, '$ai_')
+ WHERE ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('posthog-node',
+ 'posthog-python',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore')
+ AND ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') IN ('posthog-openclaw',
+ 'posthog-opencode',
+ '@posthog/pi',
+ 'posthog-ai')
+ GROUP BY team_id,
+ sdk_lib,
+ ai_lib
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.46]
+ '''
+
+ SELECT team_id,
+ ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') AS sdk_lib,
+ ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') AS ai_lib,
+ count(1) as count
+ FROM events_json PREWHERE timestamp >= '2022-01-10 10:00:00'
+ AND timestamp < '2022-01-10 12:00:00'
+ AND startsWith(event, '$ai_')
+ WHERE ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('posthog-node',
+ 'posthog-python',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore')
+ AND ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') IN ('posthog-openclaw',
+ 'posthog-opencode',
+ '@posthog/pi',
+ 'posthog-ai')
+ GROUP BY team_id,
+ sdk_lib,
+ ai_lib
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.47]
+ '''
+
+ SELECT team_id,
+ ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') AS sdk_lib,
+ ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') AS ai_lib,
+ count(1) as count
+ FROM events_json PREWHERE timestamp >= '2022-01-10 12:00:00'
+ AND timestamp < '2022-01-10 14:00:00'
+ AND startsWith(event, '$ai_')
+ WHERE ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('posthog-node',
+ 'posthog-python',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore')
+ AND ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') IN ('posthog-openclaw',
+ 'posthog-opencode',
+ '@posthog/pi',
+ 'posthog-ai')
+ GROUP BY team_id,
+ sdk_lib,
+ ai_lib
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.48]
+ '''
+
+ SELECT team_id,
+ ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') AS sdk_lib,
+ ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') AS ai_lib,
+ count(1) as count
+ FROM events_json PREWHERE timestamp >= '2022-01-10 14:00:00'
+ AND timestamp < '2022-01-10 16:00:00'
+ AND startsWith(event, '$ai_')
+ WHERE ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('posthog-node',
+ 'posthog-python',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore')
+ AND ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') IN ('posthog-openclaw',
+ 'posthog-opencode',
+ '@posthog/pi',
+ 'posthog-ai')
+ GROUP BY team_id,
+ sdk_lib,
+ ai_lib
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.49]
+ '''
+
+ SELECT team_id,
+ ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') AS sdk_lib,
+ ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') AS ai_lib,
+ count(1) as count
+ FROM events_json PREWHERE timestamp >= '2022-01-10 16:00:00'
+ AND timestamp < '2022-01-10 18:00:00'
+ AND startsWith(event, '$ai_')
+ WHERE ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('posthog-node',
+ 'posthog-python',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore')
+ AND ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') IN ('posthog-openclaw',
+ 'posthog-opencode',
+ '@posthog/pi',
+ 'posthog-ai')
+ GROUP BY team_id,
+ sdk_lib,
+ ai_lib
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.4]
+ '''
+
+ SELECT team_id,
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 08:00:00'
+ AND timestamp < '2022-01-10 10:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.50]
+ '''
+
+ SELECT team_id,
+ ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') AS sdk_lib,
+ ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') AS ai_lib,
+ count(1) as count
+ FROM events_json PREWHERE timestamp >= '2022-01-10 18:00:00'
+ AND timestamp < '2022-01-10 20:00:00'
+ AND startsWith(event, '$ai_')
+ WHERE ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('posthog-node',
+ 'posthog-python',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore')
+ AND ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') IN ('posthog-openclaw',
+ 'posthog-opencode',
+ '@posthog/pi',
+ 'posthog-ai')
+ GROUP BY team_id,
+ sdk_lib,
+ ai_lib
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.51]
+ '''
+
+ SELECT team_id,
+ ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') AS sdk_lib,
+ ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') AS ai_lib,
+ count(1) as count
+ FROM events_json PREWHERE timestamp >= '2022-01-10 20:00:00'
+ AND timestamp < '2022-01-10 22:00:00'
+ AND startsWith(event, '$ai_')
+ WHERE ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('posthog-node',
+ 'posthog-python',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore')
+ AND ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') IN ('posthog-openclaw',
+ 'posthog-opencode',
+ '@posthog/pi',
+ 'posthog-ai')
+ GROUP BY team_id,
+ sdk_lib,
+ ai_lib
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.52]
+ '''
+
+ SELECT team_id,
+ ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') AS sdk_lib,
+ ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') AS ai_lib,
+ count(1) as count
+ FROM events_json PREWHERE timestamp >= '2022-01-10 22:00:00'
+ AND timestamp < '2022-01-10 23:59:59'
+ AND startsWith(event, '$ai_')
+ WHERE ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$lib`), '\\/', '/'), toJSONString(properties.^`$lib`)), if(ascii(toString(properties.`$lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$lib`), '\\/', '/'), toJSONString(properties.`$lib`)), '[]'), '{}'), toString(properties.`$lib`))), '') IN ('posthog-node',
+ 'posthog-python',
+ 'posthog-dotnet',
+ 'posthog-aspnetcore')
+ AND ifNull(if(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)) != '{}', if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.^`$ai_lib`), '\\/', '/'), toJSONString(properties.^`$ai_lib`)), if(ascii(toString(properties.`$ai_lib`)) IN (91, 123)
+ AND ascii(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`))) IN (91, 123), nullIf(nullIf(if(getSetting('output_format_json_escape_forward_slashes'), replaceAll(toJSONString(properties.`$ai_lib`), '\\/', '/'), toJSONString(properties.`$ai_lib`)), '[]'), '{}'), toString(properties.`$ai_lib`))), '') IN ('posthog-openclaw',
+ 'posthog-opencode',
+ '@posthog/pi',
+ 'posthog-ai')
+ GROUP BY team_id,
+ sdk_lib,
+ ai_lib
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.53]
+ '''
+
+ SELECT team_id,
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 00:00:00'
+ AND timestamp < '2022-01-10 02:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND (properties.`$group_0` != ''
+ OR properties.`$group_1` != ''
+ OR properties.`$group_2` != ''
+ OR properties.`$group_3` != ''
+ OR properties.`$group_4` != '')
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.54]
+ '''
+
+ SELECT team_id,
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 02:00:00'
+ AND timestamp < '2022-01-10 04:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND (properties.`$group_0` != ''
+ OR properties.`$group_1` != ''
+ OR properties.`$group_2` != ''
+ OR properties.`$group_3` != ''
+ OR properties.`$group_4` != '')
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.55]
+ '''
+
+ SELECT team_id,
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 04:00:00'
+ AND timestamp < '2022-01-10 06:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND (properties.`$group_0` != ''
+ OR properties.`$group_1` != ''
+ OR properties.`$group_2` != ''
+ OR properties.`$group_3` != ''
+ OR properties.`$group_4` != '')
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.56]
+ '''
+
+ SELECT team_id,
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 06:00:00'
+ AND timestamp < '2022-01-10 08:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND (properties.`$group_0` != ''
+ OR properties.`$group_1` != ''
+ OR properties.`$group_2` != ''
+ OR properties.`$group_3` != ''
+ OR properties.`$group_4` != '')
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.57]
+ '''
+
+ SELECT team_id,
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 08:00:00'
+ AND timestamp < '2022-01-10 10:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND (properties.`$group_0` != ''
+ OR properties.`$group_1` != ''
+ OR properties.`$group_2` != ''
+ OR properties.`$group_3` != ''
+ OR properties.`$group_4` != '')
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.58]
+ '''
+
+ SELECT team_id,
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 10:00:00'
+ AND timestamp < '2022-01-10 12:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND (properties.`$group_0` != ''
+ OR properties.`$group_1` != ''
+ OR properties.`$group_2` != ''
+ OR properties.`$group_3` != ''
+ OR properties.`$group_4` != '')
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.59]
+ '''
+
+ SELECT team_id,
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 12:00:00'
+ AND timestamp < '2022-01-10 14:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND (properties.`$group_0` != ''
+ OR properties.`$group_1` != ''
+ OR properties.`$group_2` != ''
+ OR properties.`$group_3` != ''
+ OR properties.`$group_4` != '')
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.5]
+ '''
+
+ SELECT team_id,
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 10:00:00'
+ AND timestamp < '2022-01-10 12:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.60]
+ '''
+
+ SELECT team_id,
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 14:00:00'
+ AND timestamp < '2022-01-10 16:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND (properties.`$group_0` != ''
+ OR properties.`$group_1` != ''
+ OR properties.`$group_2` != ''
+ OR properties.`$group_3` != ''
+ OR properties.`$group_4` != '')
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.61]
+ '''
+
+ SELECT team_id,
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 16:00:00'
+ AND timestamp < '2022-01-10 18:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND (properties.`$group_0` != ''
+ OR properties.`$group_1` != ''
+ OR properties.`$group_2` != ''
+ OR properties.`$group_3` != ''
+ OR properties.`$group_4` != '')
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.62]
+ '''
+
+ SELECT team_id,
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 18:00:00'
+ AND timestamp < '2022-01-10 20:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND (properties.`$group_0` != ''
+ OR properties.`$group_1` != ''
+ OR properties.`$group_2` != ''
+ OR properties.`$group_3` != ''
+ OR properties.`$group_4` != '')
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.63]
+ '''
+
+ SELECT team_id,
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 20:00:00'
+ AND timestamp < '2022-01-10 22:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND (properties.`$group_0` != ''
+ OR properties.`$group_1` != ''
+ OR properties.`$group_2` != ''
+ OR properties.`$group_3` != ''
+ OR properties.`$group_4` != '')
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.64]
+ '''
+
+ SELECT team_id,
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 22:00:00'
+ AND timestamp < '2022-01-10 23:59:59'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ AND (properties.`$group_0` != ''
+ OR properties.`$group_1` != ''
+ OR properties.`$group_2` != ''
+ OR properties.`$group_3` != ''
+ OR properties.`$group_4` != '')
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.6]
+ '''
+
+ SELECT team_id,
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 12:00:00'
+ AND timestamp < '2022-01-10 14:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.7]
+ '''
+
+ SELECT team_id,
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 14:00:00'
+ AND timestamp < '2022-01-10 16:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.8]
+ '''
+
+ SELECT team_id,
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 16:00:00'
+ AND timestamp < '2022-01-10 18:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema.9]
+ '''
+
+ SELECT team_id,
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 18:00:00'
+ AND timestamp < '2022-01-10 20:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ GROUP BY team_id
+ '''
+# ---
+# name: TestFeatureFlagsUsageReport.test_usage_report_decide_requests[new_events_schema]
+ '''
+
+ SELECT team_id,
+ count(distinct toDate(timestamp), event, cityHash64(distinct_id), cityHash64(uuid)) as count
+ FROM events_json
+ WHERE timestamp >= '2022-01-10 00:00:00'
+ AND timestamp < '2022-01-10 02:00:00'
+ AND event NOT IN ['$feature_flag_called', '$experiment_exposure', 'survey sent', 'survey shown', 'survey dismissed', '$exception', '$llm_prompt_fetched', '$conversations_loaded', '$conversations_widget_loaded', '$conversations_message_sent', '$conversations_user_identified', '$conversations_restore_link_requested', '$conversations_widget_state_changed', '$conversations_back_to_tickets']
+ AND NOT startsWith(event, '$ai_')
+ GROUP BY team_id
'''
# ---
diff --git a/posthog/tasks/test/test_usage_counters.py b/posthog/tasks/test/test_usage_counters.py
new file mode 100644
index 000000000000..41affe2d96f8
--- /dev/null
+++ b/posthog/tasks/test/test_usage_counters.py
@@ -0,0 +1,725 @@
+from datetime import UTC, datetime, timedelta, timezone
+from itertools import product
+
+import time_machine
+from unittest.mock import Mock, patch
+
+from django.test import SimpleTestCase, override_settings
+
+from parameterized import parameterized
+
+from posthog.tasks import usage_report
+from posthog.usage_counters import (
+ COUNTER_FLAG_NAMES,
+ SHADOW_FAILURES,
+ UsageCounter,
+ UsageCounterCaller,
+ UsageCounterComparisonRows,
+ UsageCounterMode,
+ UsageCounterPlan,
+ UsageCounterReport,
+ UsageCounterService,
+ UsageRecordTotal,
+ UsageRecordTotals,
+ _mode_cache,
+ log_usage_counter_comparisons,
+ resolve_modes,
+ validate_usage_record_window,
+)
+from posthog.utils import DayRange
+
+from products.tasks.backend.facade.billing import SandboxComputeUsageByTeam
+
+SANDBOX_COMPUTE_RESOURCE_KEYS = (
+ "teams_with_sandbox_compute_cpu_millicore_seconds_in_period",
+ "teams_with_sandbox_compute_memory_mib_seconds_in_period",
+)
+# Removing a counter from RECORD_REALTIME_BLOCKERS must fail these tests, so this set lists the counters by name.
+REALTIME_GUARDED_COUNTERS = {
+ UsageCounter.EVENTS,
+ UsageCounter.ENHANCED_PERSON_EVENTS,
+ UsageCounter.EXCEPTIONS,
+ UsageCounter.CDP_INVOCATIONS,
+ UsageCounter.RECORDINGS,
+ UsageCounter.MOBILE_RECORDINGS,
+ UsageCounter.MOBILE_BILLABLE_RECORDINGS,
+ UsageCounter.WORKFLOW_INVOCATIONS,
+ UsageCounter.WORKFLOW_EMAILS,
+ UsageCounter.WORKFLOW_PUSH,
+ UsageCounter.WORKFLOW_SMS,
+ UsageCounter.FEATURE_FLAG_REQUESTS,
+ UsageCounter.FEATURE_FLAG_LOCAL_EVALUATION_REQUESTS,
+ UsageCounter.SURVEY_RESPONSES,
+ UsageCounter.AI_EVENTS,
+}
+
+
+class TestUsageRecordQuery(SimpleTestCase):
+ @parameterized.expand(
+ [
+ ("shadow", UsageCounterMode.REALTIME, "cdp_billable_invocations", 3),
+ ("authoritative", UsageCounterMode.REALTIME, "workflow_emails_sent", 3),
+ ("shadow_with_zero_total", UsageCounterMode.REALTIME, "cdp_billable_invocations", 0),
+ ("all_shadow", UsageCounterMode.BOTH, "cdp_billable_invocations", 3),
+ ]
+ )
+ def test_invalid_units_only_fail_authoritative_counters(
+ self, _name: str, email_mode: UsageCounterMode, invalid_key: str, emails: int
+ ) -> None:
+ period = DayRange(start=datetime(2026, 5, 4, tzinfo=UTC), end=datetime(2026, 5, 5, tzinfo=UTC))
+ plan = UsageCounterPlan(
+ period=period,
+ caller="daily_report",
+ modes={UsageCounter.CDP_INVOCATIONS: UsageCounterMode.BOTH, UsageCounter.WORKFLOW_EMAILS: email_mode},
+ complete=True,
+ )
+ rows = [(1, "org-a", "cdp_billable_invocations", "invocations", 9)]
+ if emails:
+ rows.append((1, "org-a", "workflow_emails_sent", "invocations", emails))
+ rows.append((1, "org-a", invalid_key, "bytes", 25))
+ failures_before = SHADOW_FAILURES.labels(caller="daily_report", stage="validation")._value.get()
+ with (
+ patch("posthog.tasks.usage_report.sync_execute", return_value=rows) as scan,
+ patch(
+ "posthog.tasks.usage_report.get_teams_with_cdp_billable_invocations_in_period", return_value=[(1, 12)]
+ ),
+ patch("posthog.tasks.usage_report.get_teams_with_workflow_emails_sent_in_period", return_value=[(1, 5)]),
+ ):
+ service = UsageCounterService()
+ if invalid_key == "workflow_emails_sent":
+ with self.assertRaisesRegex(ValueError, "Unexpected unit 'bytes'.*workflow_emails_sent"):
+ service.fetch_report(period, plan=plan)
+ else:
+ report = service.fetch_report(period, plan=plan)
+ assert report.counts[UsageCounter.CDP_INVOCATIONS] == [(1, 12)]
+ assert report.counts[UsageCounter.WORKFLOW_EMAILS] == (
+ [(1, 5)] if email_mode == UsageCounterMode.BOTH else [(1, emails)] if emails else []
+ )
+ assert report.counter_comparisons == {
+ "workflow_emails_sent_in_period": UsageCounterComparisonRows(
+ legacy_by_team={1: 5}, realtime_by_team={1: {"org-a": emails}} if emails else {}
+ )
+ }
+ assert (
+ SHADOW_FAILURES.labels(caller="daily_report", stage="validation")._value.get()
+ == failures_before + 1
+ )
+ scan.assert_called_once()
+
+ @parameterized.expand(
+ [
+ ("events", "events"),
+ ("session_replay_recordings", "recordings"),
+ ("cdp_billable_invocations", "invocations"),
+ ("feature_flag_requests", "requests"),
+ ]
+ )
+ def test_reads_quantities_in_the_producer_unit(self, usage_key: str, unit: str) -> None:
+ period = DayRange(start=datetime(2026, 5, 4, tzinfo=UTC), end=datetime(2026, 5, 5, tzinfo=UTC))
+ with patch("posthog.tasks.usage_report.sync_execute", return_value=[(1, "org-a", usage_key, unit, 25)]):
+ assert usage_report.get_usage_records_in_period(period, (usage_key,), "daily_report") == UsageRecordTotals(
+ totals=[UsageRecordTotal(team_id=1, organization_id="org-a", usage_key=usage_key, quantity=25)]
+ )
+
+ @parameterized.expand([("incorrect_unit", False), ("mixed_units", True)])
+ def test_omits_all_totals_for_a_key_with_incompatible_units(self, _name: str, mixed: bool) -> None:
+ period = DayRange(start=datetime(2026, 5, 4, tzinfo=UTC), end=datetime(2026, 5, 5, tzinfo=UTC))
+ rows = [(1, "org-a", "cdp_billable_invocations", "bytes", 25)]
+ if mixed:
+ rows.insert(0, (1, "org-a", "cdp_billable_invocations", "invocations", 10))
+ with patch("posthog.tasks.usage_report.sync_execute", return_value=rows) as scan:
+ result = usage_report.get_usage_records_in_period(period, ("cdp_billable_invocations",), "daily_report")
+ assert result.totals == []
+ assert result.errors == {
+ "cdp_billable_invocations": "Unexpected unit 'bytes' for usage key 'cdp_billable_invocations'; expected 'invocations'"
+ }
+ scan.assert_called_once()
+
+
+class TestUsageCounterReport(SimpleTestCase):
+ def setUp(self) -> None:
+ super().setUp()
+ _mode_cache.clear()
+ self.addCleanup(_mode_cache.clear)
+ self.legacy = {counter: Mock(return_value=[]) for counter in UsageCounter}
+ self.records = Mock(return_value=UsageRecordTotals(totals=[]))
+ self.exceptions = Mock(side_effect=lambda begin, end: ({}, self.legacy[UsageCounter.EXCEPTIONS](begin, end)))
+ self.events = Mock(side_effect=lambda begin, end, **kwargs: self.legacy[UsageCounter.EVENTS](begin, end))
+ self.logs_retention = Mock(
+ side_effect=lambda begin, end: {"30d": self.legacy[UsageCounter.LOGS_RETENTION_30D_BYTES](begin, end)}
+ )
+ self.sandbox_compute = Mock(
+ side_effect=lambda begin, end: SandboxComputeUsageByTeam(
+ credits=self.legacy[UsageCounter.SANDBOX_COMPUTE_CREDITS](begin, end),
+ cpu_millicore_seconds=[],
+ memory_mib_seconds=[],
+ )
+ )
+ patches = {
+ "get_teams_with_logs_retention_bytes_in_period": self.logs_retention,
+ "get_teams_with_logs_retention_byte_days_in_period": self.legacy[UsageCounter.LOGS_RETENTION_BYTE_DAYS],
+ "get_teams_with_billable_sandbox_compute_usage_in_period": self.sandbox_compute,
+ "get_teams_with_rows_synced_in_period": self.legacy[UsageCounter.ROWS_SYNCED],
+ "get_teams_with_free_historical_rows_synced_in_period": self.legacy[
+ UsageCounter.FREE_HISTORICAL_ROWS_SYNCED
+ ],
+ "get_teams_with_rows_exported_in_period": self.legacy[UsageCounter.ROWS_EXPORTED],
+ "get_teams_with_logs_bytes_in_period": self.legacy[UsageCounter.LOGS_BYTES],
+ "get_teams_with_ai_credits_used_in_period": self.legacy[UsageCounter.AI_CREDITS],
+ "get_teams_with_signals_credits_used_in_period": self.legacy[UsageCounter.SIGNALS_CREDITS],
+ "get_teams_with_posthog_code_credits_used_in_period": self.legacy[UsageCounter.POSTHOG_CODE_CREDITS],
+ "get_teams_with_replay_vision_credits_used_in_period": self.legacy[UsageCounter.REPLAY_VISION_CREDITS],
+ "get_teams_with_billable_event_count_in_period": self.events,
+ "get_teams_with_billable_enhanced_persons_event_count_in_period": Mock(
+ side_effect=lambda begin, end, **kwargs: self.legacy[UsageCounter.ENHANCED_PERSON_EVENTS](begin, end)
+ ),
+ "get_teams_with_recording_count_in_period": Mock(
+ side_effect=lambda begin, end, snapshot_source: self.legacy[
+ UsageCounter.RECORDINGS if snapshot_source == "web" else UsageCounter.MOBILE_RECORDINGS
+ ](begin, end)
+ ),
+ "get_teams_with_mobile_billable_recording_count_in_period": self.legacy[
+ UsageCounter.MOBILE_BILLABLE_RECORDINGS
+ ],
+ "get_teams_with_survey_responses_count_in_period": self.legacy[UsageCounter.SURVEY_RESPONSES],
+ "get_teams_with_ai_event_count_in_period": self.legacy[UsageCounter.AI_EVENTS],
+ "get_teams_with_exceptions_captured_in_period": self.exceptions,
+ "get_teams_with_cdp_billable_invocations_in_period": self.legacy[UsageCounter.CDP_INVOCATIONS],
+ "get_teams_with_feature_flag_requests_count_in_period": Mock(
+ side_effect=lambda begin, end, kind: self.legacy[
+ UsageCounter.FEATURE_FLAG_REQUESTS
+ if kind == usage_report.FlagRequestType.DECIDE
+ else UsageCounter.FEATURE_FLAG_LOCAL_EVALUATION_REQUESTS
+ ](begin, end)
+ ),
+ "get_teams_with_workflow_emails_sent_in_period": self.legacy[UsageCounter.WORKFLOW_EMAILS],
+ "get_teams_with_workflow_push_sent_in_period": self.legacy[UsageCounter.WORKFLOW_PUSH],
+ "get_teams_with_workflow_sms_sent_in_period": self.legacy[UsageCounter.WORKFLOW_SMS],
+ "get_teams_with_workflow_billable_invocations_in_period": self.legacy[UsageCounter.WORKFLOW_INVOCATIONS],
+ "get_usage_records_in_period": self.records,
+ }
+ patcher = patch.multiple(usage_report, **patches)
+ patcher.start()
+ self.addCleanup(patcher.stop)
+
+ @parameterized.expand([("counts", False, False), ("zero", True, False), ("comparison_failure", False, True)])
+ @override_settings(USAGE_COUNTER_REALTIME_MODES="")
+ def test_fetch_report_uses_resolved_plan_and_preserves_legacy_counts(
+ self, _name: str, empty: bool, fails: bool
+ ) -> None:
+ period = DayRange(start=datetime(2026, 5, 4, tzinfo=UTC), end=datetime(2026, 5, 5, tzinfo=UTC))
+ rows = (
+ []
+ if empty
+ else [
+ UsageRecordTotal(team_id=1, organization_id="org-a", usage_key="cdp_billable_invocations", quantity=4),
+ UsageRecordTotal(team_id=2, organization_id="org-a", usage_key="cdp_billable_invocations", quantity=5),
+ ]
+ )
+ records_query = self.records
+ records_query.return_value = UsageRecordTotals(totals=rows)
+ records_query.side_effect = RuntimeError("unavailable") if fails else None
+ legacy_query = self.legacy[UsageCounter.CDP_INVOCATIONS]
+ legacy_query.return_value = [(1, 12)]
+ email_query = self.legacy[UsageCounter.WORKFLOW_EMAILS]
+ email_query.return_value = [(1, 3)]
+ service = UsageCounterService()
+ failures_before = SHADOW_FAILURES.labels(caller="daily_report", stage="scan")._value.get()
+ with patch(
+ "posthoganalytics.get_feature_flag",
+ side_effect=lambda name, distinct_id: "both" if name.endswith("cdp-invocations") else "legacy",
+ ) as flag:
+ plan = service.resolve_plan(period, caller="daily_report", complete=True)
+ flag.side_effect = None
+ flag.return_value = "legacy"
+ report = service.fetch_report(period, plan=plan)
+ assert flag.call_count == len(COUNTER_FLAG_NAMES)
+
+ assert report.counts == {
+ **{key: [] for key in (*UsageCounter, *SANDBOX_COMPUTE_RESOURCE_KEYS)},
+ UsageCounter.CDP_INVOCATIONS.value: [(1, 12)],
+ UsageCounter.WORKFLOW_EMAILS.value: [(1, 3)],
+ }
+ assert report.usage_sources == {
+ **{counter.value.removeprefix("teams_with_"): "legacy" for counter in UsageCounter},
+ "cdp_billable_invocations_in_period": "both",
+ }
+ assert report.counter_comparisons == (
+ None
+ if fails
+ else {
+ "cdp_billable_invocations_in_period": UsageCounterComparisonRows(
+ legacy_by_team={1: 12}, realtime_by_team={} if empty else {1: {"org-a": 4}, 2: {"org-a": 5}}
+ )
+ }
+ )
+ records_query.assert_called_once_with(period, ("cdp_billable_invocations",), "daily_report")
+ legacy_query.assert_called_once_with(period.start, period.end)
+ email_query.assert_called_once_with(period.start, period.end)
+ assert SHADOW_FAILURES.labels(caller="daily_report", stage="scan")._value.get() == failures_before + int(fails)
+ with self.assertRaisesRegex(ValueError, "across periods"):
+ service.fetch_report(
+ DayRange(start=period.start + timedelta(days=1), end=period.end + timedelta(days=1)), plan=plan
+ )
+
+ @override_settings(USAGE_COUNTER_REALTIME_MODES="")
+ def test_legacy_report_without_plan_does_not_query_records(self) -> None:
+ period = DayRange(start=datetime(2026, 5, 4, tzinfo=UTC), end=datetime(2026, 5, 5, tzinfo=UTC))
+ self.records.side_effect = AssertionError("unexpected scan")
+ self.legacy[UsageCounter.CDP_INVOCATIONS].return_value = [(1, 12)]
+ with patch("posthoganalytics.get_feature_flag") as flag:
+ report = UsageCounterService().fetch_report(period)
+ assert report.counts[UsageCounter.CDP_INVOCATIONS.value] == [(1, 12)]
+ assert report.usage_sources is None
+ assert report.counter_comparisons is None
+ self.records.assert_not_called()
+ flag.assert_not_called()
+
+ def test_comparison_logs_expose_differences_when_totals_match(self) -> None:
+ report = UsageCounterReport(
+ counts={},
+ usage_sources={"event_count_in_period": UsageCounterMode.BOTH},
+ counter_comparisons={
+ "event_count_in_period": UsageCounterComparisonRows(
+ legacy_by_team={1: 7, 2: 3},
+ realtime_by_team={1: {"org-a": 3}, 2: {"org-b": 7}},
+ )
+ },
+ )
+ with patch("posthog.usage_counters.logger.info") as log:
+ log_usage_counter_comparisons(report, caller="quota_limiting", date="2026-05-04")
+ log.assert_any_call(
+ "usage_counter_sources",
+ caller="quota_limiting",
+ date="2026-05-04",
+ usage_sources=report.usage_sources,
+ )
+ log.assert_any_call(
+ "usage_counter_comparison",
+ caller="quota_limiting",
+ date="2026-05-04",
+ counter="event_count_in_period",
+ source="both",
+ legacy=10,
+ realtime=10,
+ differing_teams=2,
+ absolute_difference=8,
+ )
+
+ @parameterized.expand([("legacy",), ("both",)])
+ def test_authoritative_query_failure_fails_report(self, mode: str) -> None:
+ period = DayRange(start=datetime(2026, 5, 4, tzinfo=UTC), end=datetime(2026, 5, 5, tzinfo=UTC))
+ self.legacy[UsageCounter.CDP_INVOCATIONS].side_effect = RuntimeError("legacy unavailable")
+ service = UsageCounterService()
+ with (
+ self.settings(USAGE_COUNTER_REALTIME_MODES=f"cdp-invocations:{mode}"),
+ patch("posthoganalytics.get_feature_flag", return_value="legacy"),
+ ):
+ plan = service.resolve_plan(period, caller="daily_report", complete=True)
+ with self.assertRaisesRegex(RuntimeError, "legacy unavailable"):
+ service.fetch_report(period, plan=plan)
+
+ @parameterized.expand(
+ [
+ ("cross_midnight", 25, UTC),
+ ("offset_crosses_utc_midnight", 24, timezone(timedelta(hours=-5))),
+ ("naive", 24, None),
+ ("empty", 0, UTC),
+ ]
+ )
+ def test_rejects_invalid_scan_windows(self, _name: str, hours: int, tz: timezone | None) -> None:
+ start = datetime(2026, 5, 4, tzinfo=tz)
+ with self.assertRaises(ValueError):
+ validate_usage_record_window(DayRange(start=start, end=start + timedelta(hours=hours)))
+
+ @parameterized.expand(
+ [(None,), (False,), (True,), ("legacy",), ("both",), ("realtime",), ("invalid",), (RuntimeError("offline"),)]
+ )
+ @override_settings(USAGE_COUNTER_REALTIME_MODES="")
+ def test_flag_selects_query_mode_or_defaults_to_legacy(self, flag_value: str | bool | None | Exception) -> None:
+ period = DayRange(start=datetime(2026, 5, 4, tzinfo=UTC), end=datetime(2026, 5, 5, tzinfo=UTC))
+ records_query = self.records
+ records_query.return_value = UsageRecordTotals(
+ totals=[UsageRecordTotal(team_id=1, organization_id="org-a", usage_key="workflow_emails_sent", quantity=9)]
+ )
+ self.legacy[UsageCounter.WORKFLOW_EMAILS].return_value = [(1, 12)]
+ service = UsageCounterService()
+ with patch(
+ "posthoganalytics.get_feature_flag",
+ side_effect=lambda name, distinct_id: flag_value if name.endswith("workflow-emails") else "legacy",
+ ) as flag:
+ if isinstance(flag_value, Exception):
+ flag.side_effect = flag_value
+ plan = service.resolve_plan(period, caller="daily_report", complete=True)
+ report = service.fetch_report(period, plan=plan)
+ assert report.counts[UsageCounter.WORKFLOW_EMAILS.value] == [(1, 12)]
+ assert plan.modes[UsageCounter.WORKFLOW_EMAILS] == (
+ UsageCounterMode.BOTH if flag_value in ("both", "realtime") else UsageCounterMode.LEGACY
+ )
+ assert (report.counter_comparisons is not None) == (flag_value in ("both", "realtime"))
+ assert records_query.call_count == int(flag_value in ("both", "realtime"))
+ assert flag.call_count == len(COUNTER_FLAG_NAMES)
+
+ @parameterized.expand([("both", True), ("realtime", True), ("legacy", False), ("unknown", False)])
+ def test_local_override_does_not_consult_flag_service(self, mode: str, enabled: bool) -> None:
+ period = DayRange(start=datetime(2026, 5, 4, tzinfo=UTC), end=datetime(2026, 5, 5, tzinfo=UTC))
+ service = UsageCounterService()
+ with (
+ self.settings(USAGE_COUNTER_REALTIME_MODES=f"cdp-invocations:{mode}"),
+ patch("posthoganalytics.get_feature_flag") as flag,
+ ):
+ plan = service.resolve_plan(period, caller="daily_report", complete=True)
+ assert (service.fetch_report(period, plan=plan).counter_comparisons is not None) == enabled
+ assert all(call.args[0] != "usage-counter-realtime-cdp-invocations" for call in flag.call_args_list)
+
+ @parameterized.expand(
+ list(product(UsageCounterMode, ("daily_report", "usage_reports_v2", "quota_limiting"), (0, 1)))
+ )
+ @time_machine.travel("2026-05-04T12:00:00Z", tick=False)
+ def test_resolved_mode_selects_queries_for_every_caller_and_day(
+ self, mode: UsageCounterMode, caller: UsageCounterCaller, days_ago: int
+ ) -> None:
+ start = datetime(2026, 5, 4, tzinfo=UTC) - timedelta(days=days_ago)
+ period = DayRange(start=start, end=start + timedelta(days=1))
+ legacy = self.legacy[UsageCounter.WORKFLOW_EMAILS]
+ legacy.return_value = [(1, 12)]
+ records = self.records
+ records.return_value = UsageRecordTotals(
+ totals=[UsageRecordTotal(team_id=1, organization_id="org-a", usage_key="workflow_emails_sent", quantity=9)]
+ )
+ service = UsageCounterService()
+ plan = UsageCounterPlan(
+ period=period,
+ caller=caller,
+ modes={**dict.fromkeys(UsageCounter, UsageCounterMode.LEGACY), UsageCounter.WORKFLOW_EMAILS: mode},
+ complete=days_ago > 0,
+ )
+ report = service.fetch_report(period, plan=plan)
+ assert set(report.counts) == {*UsageCounter, *SANDBOX_COMPUTE_RESOURCE_KEYS}
+ assert report.counts[UsageCounter.WORKFLOW_EMAILS.value] == [
+ (1, 9 if mode == UsageCounterMode.REALTIME else 12)
+ ]
+ compares = mode == UsageCounterMode.BOTH or (mode == UsageCounterMode.REALTIME and days_ago > 0)
+ assert legacy.call_count == int(mode != UsageCounterMode.REALTIME or compares)
+ assert records.call_count == int(mode != UsageCounterMode.LEGACY)
+ assert report.counter_comparisons == (
+ {
+ "workflow_emails_sent_in_period": UsageCounterComparisonRows(
+ legacy_by_team={1: 12}, realtime_by_team={1: {"org-a": 9}}
+ )
+ }
+ if compares
+ else None
+ )
+ if mode == UsageCounterMode.REALTIME:
+ records.side_effect = RuntimeError("records unavailable")
+ with self.assertRaisesRegex(RuntimeError, "records unavailable"):
+ service.fetch_report(period, plan=plan)
+
+ @override_settings(USAGE_COUNTER_REALTIME_MODES="")
+ def test_mode_cache_expires_without_changing_existing_plan(self) -> None:
+ period = DayRange(start=datetime(2026, 5, 4, tzinfo=UTC), end=datetime(2026, 5, 5, tzinfo=UTC))
+ service = UsageCounterService()
+ with (
+ patch("posthog.usage_counters.time.monotonic", return_value=100) as clock,
+ patch("posthoganalytics.get_feature_flag", return_value="both") as flag,
+ ):
+ modes = resolve_modes("daily_report")
+ assert modes == {
+ counter: UsageCounterMode.BOTH if counter in COUNTER_FLAG_NAMES else UsageCounterMode.LEGACY
+ for counter in UsageCounter
+ }
+ plan = service.resolve_plan(period, caller="daily_report", complete=True)
+ flag.return_value = "realtime"
+ assert resolve_modes("usage_reports_v2") == modes
+ assert resolve_modes("quota_limiting") == modes
+ assert flag.call_count == len(COUNTER_FLAG_NAMES)
+ clock.return_value = 161
+ assert resolve_modes("daily_report") == {
+ counter: (
+ UsageCounterMode.LEGACY
+ if counter not in COUNTER_FLAG_NAMES
+ else UsageCounterMode.BOTH
+ if counter in REALTIME_GUARDED_COUNTERS
+ else UsageCounterMode.REALTIME
+ )
+ for counter in UsageCounter
+ }
+ assert flag.call_count == 2 * len(COUNTER_FLAG_NAMES)
+ with self.settings(USAGE_COUNTER_REALTIME_MODES="cdp-invocations:legacy"):
+ assert resolve_modes("daily_report")[UsageCounter.CDP_INVOCATIONS] == UsageCounterMode.LEGACY
+ report = service.fetch_report(period, plan=plan)
+ assert report.counts[UsageCounter.CDP_INVOCATIONS.value] == []
+ assert report.counter_comparisons == {
+ counter.value.removeprefix("teams_with_"): UsageCounterComparisonRows(
+ legacy_by_team={}, realtime_by_team={}
+ )
+ for counter in COUNTER_FLAG_NAMES
+ }
+
+ @parameterized.expand([("success",), ("records",), ("legacy_comparison",)])
+ def test_mixed_sources_share_one_scan_and_preserve_authoritative_failure(self, failure: str) -> None:
+ period = DayRange(start=datetime(2026, 5, 4, tzinfo=UTC), end=datetime(2026, 5, 5, tzinfo=UTC))
+ cdp_legacy = self.legacy[UsageCounter.CDP_INVOCATIONS]
+ cdp_legacy.return_value = [(1, 12)]
+ email_legacy = self.legacy[UsageCounter.WORKFLOW_EMAILS]
+ email_legacy.return_value = [(1, 5)]
+ email_legacy.side_effect = RuntimeError("legacy unavailable") if failure == "legacy_comparison" else None
+ records = self.records
+ records.return_value = UsageRecordTotals(
+ totals=[
+ UsageRecordTotal(team_id=1, organization_id="org-a", usage_key="cdp_billable_invocations", quantity=9),
+ UsageRecordTotal(team_id=1, organization_id="org-a", usage_key="workflow_emails_sent", quantity=3),
+ ]
+ )
+ records.side_effect = RuntimeError("records unavailable") if failure == "records" else None
+ service = UsageCounterService()
+ plan = UsageCounterPlan(
+ period=period,
+ caller="daily_report",
+ modes={
+ UsageCounter.CDP_INVOCATIONS: UsageCounterMode.BOTH,
+ UsageCounter.WORKFLOW_EMAILS: UsageCounterMode.REALTIME,
+ },
+ complete=True,
+ )
+ if failure == "records":
+ with self.assertRaisesRegex(RuntimeError, "records unavailable"):
+ service.fetch_report(period, plan=plan)
+ else:
+ report = service.fetch_report(period, plan=plan)
+ assert report.counts[UsageCounter.CDP_INVOCATIONS.value] == [(1, 12)]
+ assert report.counts[UsageCounter.WORKFLOW_EMAILS.value] == [(1, 3)]
+ expected = {
+ "cdp_billable_invocations_in_period": UsageCounterComparisonRows(
+ legacy_by_team={1: 12}, realtime_by_team={1: {"org-a": 9}}
+ )
+ }
+ if failure != "legacy_comparison":
+ expected["workflow_emails_sent_in_period"] = UsageCounterComparisonRows(
+ legacy_by_team={1: 5}, realtime_by_team={1: {"org-a": 3}}
+ )
+ assert report.counter_comparisons == expected
+ assert report.usage_sources is not None
+ assert report.usage_sources["workflow_emails_sent_in_period"] == UsageCounterMode.REALTIME
+ records.assert_called_once_with(period, ("cdp_billable_invocations", "workflow_emails_sent"), "daily_report")
+ email_legacy.assert_called_once_with(period.start, period.end)
+
+ @parameterized.expand(
+ list(product(UsageCounterMode, ("flag", "override"), ("daily_report", "usage_reports_v2", "quota_limiting")))
+ )
+ def test_remaining_readers_preserve_counts_and_exception_breakdowns(
+ self, mode: UsageCounterMode, source: str, caller: UsageCounterCaller
+ ) -> None:
+ period = DayRange(start=datetime(2026, 5, 4, tzinfo=UTC), end=datetime(2026, 5, 5, tzinfo=UTC))
+ counter_keys = {
+ UsageCounter.EVENTS: ("events", 101),
+ UsageCounter.ENHANCED_PERSON_EVENTS: ("enhanced_person_events", 102),
+ UsageCounter.RECORDINGS: ("session_replay_recordings", 103),
+ UsageCounter.MOBILE_RECORDINGS: ("mobile_replay_recordings", 104),
+ UsageCounter.MOBILE_BILLABLE_RECORDINGS: ("mobile_replay_recordings", 104),
+ UsageCounter.SURVEY_RESPONSES: ("survey_responses", 105),
+ UsageCounter.AI_EVENTS: ("ai_events", 106),
+ UsageCounter.EXCEPTIONS: ("exceptions", 107),
+ UsageCounter.CDP_INVOCATIONS: ("cdp_billable_invocations", 111),
+ UsageCounter.FEATURE_FLAG_REQUESTS: ("feature_flag_requests", 108),
+ UsageCounter.FEATURE_FLAG_LOCAL_EVALUATION_REQUESTS: ("feature_flag_local_evaluation_requests", 109),
+ UsageCounter.WORKFLOW_EMAILS: ("workflow_emails_sent", 112),
+ UsageCounter.WORKFLOW_PUSH: ("workflow_push_sent", 113),
+ UsageCounter.WORKFLOW_SMS: ("workflow_sms_sent", 114),
+ UsageCounter.WORKFLOW_INVOCATIONS: ("workflow_billable_invocations", 110),
+ }
+ flag_counters = {UsageCounter.FEATURE_FLAG_REQUESTS, UsageCounter.FEATURE_FLAG_LOCAL_EVALUATION_REQUESTS}
+ for index, counter in enumerate(counter_keys):
+ self.legacy[counter].return_value = [("1" if counter in flag_counters else 1, index + 1)]
+ self.exceptions.side_effect = None
+ self.exceptions.return_value = ({"web": [[1, 3]], "web_lite": [[1, 5]]}, [[1, 8]])
+ self.records.return_value = UsageRecordTotals(
+ totals=[
+ UsageRecordTotal(team_id=1, organization_id="org-a", usage_key=key, quantity=quantity)
+ for key, quantity in dict(counter_keys.values()).items()
+ ]
+ )
+ with (
+ self.settings(
+ USAGE_COUNTER_REALTIME_MODES=(
+ ",".join(f"{COUNTER_FLAG_NAMES[counter]}:{mode}" for counter in counter_keys)
+ if source == "override"
+ else ""
+ )
+ ),
+ patch("posthoganalytics.get_feature_flag", return_value=mode if source == "flag" else "legacy"),
+ ):
+ service = UsageCounterService()
+ plan = service.resolve_plan(
+ period, caller=caller, complete=caller != "quota_limiting", counters=tuple(counter_keys)
+ )
+ report = service.fetch_report(period, plan=plan)
+
+ for index, (counter, (_, quantity)) in enumerate(counter_keys.items()):
+ reads_records = plan.modes[counter] == UsageCounterMode.REALTIME
+ assert reads_records == (mode == UsageCounterMode.REALTIME and counter not in REALTIME_GUARDED_COUNTERS)
+ assert report.counts[counter] == [(1, quantity if reads_records else index + 1)]
+ if caller == "quota_limiting":
+ assert "teams_with_web_exceptions_captured_in_period" not in report.counts
+ assert "teams_with_js_lite_exceptions_captured_in_period" not in report.counts
+ else:
+ assert report.counts["teams_with_web_exceptions_captured_in_period"] == [(1, 3)]
+ assert report.counts["teams_with_js_lite_exceptions_captured_in_period"] == [(1, 5)]
+ self.exceptions.assert_called_once_with(period.start, period.end)
+ self.legacy[UsageCounter.CDP_INVOCATIONS].assert_called_once_with(period.start, period.end)
+ if mode == UsageCounterMode.LEGACY:
+ self.records.assert_not_called()
+ assert report.counter_comparisons is None
+ else:
+ self.records.assert_called_once_with(period, tuple(dict(counter_keys.values())), caller)
+ assert report.counter_comparisons == {
+ counter.value.removeprefix("teams_with_"): UsageCounterComparisonRows(
+ legacy_by_team={1: index + 1}, realtime_by_team={1: {"org-a": quantity}}
+ )
+ for index, (counter, (_, quantity)) in enumerate(counter_keys.items())
+ }
+
+ @override_settings(USAGE_COUNTER_REALTIME_MODES="mobile-recordings:legacy,mobile-billable-recordings:both")
+ def test_mobile_replay_counters_select_modes_independently_with_one_record_key(self) -> None:
+ period = DayRange(start=datetime(2026, 5, 4, tzinfo=UTC), end=datetime(2026, 5, 5, tzinfo=UTC))
+ self.legacy[UsageCounter.MOBILE_RECORDINGS].return_value = [(1, 5)]
+ self.legacy[UsageCounter.MOBILE_BILLABLE_RECORDINGS].return_value = [(1, 3)]
+ self.records.return_value = UsageRecordTotals(
+ totals=[
+ UsageRecordTotal(team_id=1, organization_id="org-a", usage_key="mobile_replay_recordings", quantity=7)
+ ]
+ )
+ with patch("posthoganalytics.get_feature_flag", return_value="legacy"):
+ service = UsageCounterService()
+ plan = service.resolve_plan(
+ period,
+ caller="daily_report",
+ complete=True,
+ counters=(UsageCounter.MOBILE_RECORDINGS, UsageCounter.MOBILE_BILLABLE_RECORDINGS),
+ )
+ report = service.fetch_report(period, plan=plan)
+
+ assert report.counts == {
+ UsageCounter.MOBILE_RECORDINGS: [(1, 5)],
+ UsageCounter.MOBILE_BILLABLE_RECORDINGS: [(1, 3)],
+ }
+ assert report.counter_comparisons == {
+ "mobile_billable_recording_count_in_period": UsageCounterComparisonRows(
+ legacy_by_team={1: 3}, realtime_by_team={1: {"org-a": 7}}
+ ),
+ }
+ assert report.usage_sources == {
+ "mobile_recording_count_in_period": UsageCounterMode.LEGACY,
+ "mobile_billable_recording_count_in_period": UsageCounterMode.BOTH,
+ }
+ self.records.assert_called_once_with(period, ("mobile_replay_recordings",), "daily_report")
+ self.legacy[UsageCounter.MOBILE_BILLABLE_RECORDINGS].assert_called_once_with(period.start, period.end)
+
+ @parameterized.expand([("daily_report", True), ("usage_reports_v2", True), ("quota_limiting", False)])
+ def test_legacy_event_reader_preserves_caller_deduplication(
+ self, caller: UsageCounterCaller, count_distinct: bool
+ ) -> None:
+ period = DayRange(start=datetime(2026, 5, 4, tzinfo=UTC), end=datetime(2026, 5, 5, tzinfo=UTC))
+ self.legacy[UsageCounter.EVENTS].return_value = [(1, 7)]
+ with patch("posthoganalytics.get_feature_flag", return_value="legacy"):
+ service = UsageCounterService()
+ plan = service.resolve_plan(period, caller=caller, complete=True, counters=(UsageCounter.EVENTS,))
+ assert service.fetch_report(period, plan=plan).counts == {UsageCounter.EVENTS: [(1, 7)]}
+ self.events.assert_called_once_with(period.start, period.end, count_distinct=count_distinct)
+ self.exceptions.assert_not_called()
+
+ @parameterized.expand(list(product(("daily_report", "usage_reports_v2", "quota_limiting"), (False, True))))
+ def test_guarded_exception_reader_preserves_legacy_totals_and_breakdowns(
+ self, caller: UsageCounterCaller, fails: bool
+ ) -> None:
+ period = DayRange(start=datetime(2026, 5, 4, tzinfo=UTC), end=datetime(2026, 5, 5, tzinfo=UTC))
+ self.records.return_value = UsageRecordTotals(
+ totals=[UsageRecordTotal(team_id=1, organization_id="org-a", usage_key="exceptions", quantity=7)]
+ )
+ with patch("posthoganalytics.get_feature_flag", return_value="realtime"):
+ service = UsageCounterService()
+ plan = service.resolve_plan(
+ period, caller=caller, complete=caller == "daily_report", counters=(UsageCounter.EXCEPTIONS,)
+ )
+ assert plan.modes == {UsageCounter.EXCEPTIONS: UsageCounterMode.BOTH}
+ self.exceptions.side_effect = RuntimeError("legacy unavailable") if fails else None
+ self.exceptions.return_value = ({"web": [(1, 3)]}, [(1, 3)])
+ if fails:
+ with self.assertRaisesRegex(RuntimeError, "legacy unavailable"):
+ service.fetch_report(period, plan=plan)
+ else:
+ report = service.fetch_report(period, plan=plan)
+ expected = {UsageCounter.EXCEPTIONS.value: [(1, 3)]}
+ if caller != "quota_limiting":
+ expected["teams_with_web_exceptions_captured_in_period"] = [(1, 3)]
+ assert report.counts == expected
+ assert report.counter_comparisons == {
+ "exceptions_captured_in_period": UsageCounterComparisonRows(
+ legacy_by_team={1: 3}, realtime_by_team={1: {"org-a": 7}}
+ )
+ }
+ assert report.usage_sources == {"exceptions_captured_in_period": UsageCounterMode.BOTH}
+ self.exceptions.assert_called_once_with(period.start, period.end)
+
+ @parameterized.expand([(mode,) for mode in UsageCounterMode])
+ def test_legacy_only_counters_preserve_values_and_bundled_series(self, flag_mode: UsageCounterMode) -> None:
+ period = DayRange(start=datetime(2026, 5, 4, tzinfo=UTC), end=datetime(2026, 5, 5, tzinfo=UTC))
+ counters = (
+ UsageCounter.ROWS_SYNCED,
+ UsageCounter.FREE_HISTORICAL_ROWS_SYNCED,
+ UsageCounter.ROWS_EXPORTED,
+ UsageCounter.LOGS_BYTES,
+ UsageCounter.LOGS_RETENTION_30D_BYTES,
+ UsageCounter.LOGS_RETENTION_BYTE_DAYS,
+ UsageCounter.AI_CREDITS,
+ UsageCounter.SIGNALS_CREDITS,
+ UsageCounter.POSTHOG_CODE_CREDITS,
+ UsageCounter.SANDBOX_COMPUTE_CREDITS,
+ UsageCounter.REPLAY_VISION_CREDITS,
+ )
+ expected = {counter.value: [(1, index + 1)] for index, counter in enumerate(counters)}
+ dictionary_readers = {
+ UsageCounter.ROWS_SYNCED,
+ UsageCounter.FREE_HISTORICAL_ROWS_SYNCED,
+ UsageCounter.ROWS_EXPORTED,
+ }
+ for index, counter in enumerate(counters):
+ self.legacy[counter].return_value = (
+ [{"team_id": 1, "total": index + 1}] if counter in dictionary_readers else expected[counter]
+ )
+ self.logs_retention.side_effect = None
+ self.logs_retention.return_value = {
+ "14d": [(1, 17)],
+ "30d": expected[UsageCounter.LOGS_RETENTION_30D_BYTES],
+ "90d": [(2, 23)],
+ }
+ self.sandbox_compute.side_effect = None
+ self.sandbox_compute.return_value = SandboxComputeUsageByTeam(
+ credits=expected[UsageCounter.SANDBOX_COMPUTE_CREDITS],
+ cpu_millicore_seconds=[(1, 29)],
+ memory_mib_seconds=[(2, 31)],
+ )
+ expected.update(
+ {
+ "teams_with_logs_retention_14d_bytes_in_period": [(1, 17)],
+ "teams_with_logs_retention_90d_bytes_in_period": [(2, 23)],
+ "teams_with_sandbox_compute_cpu_millicore_seconds_in_period": [(1, 29)],
+ "teams_with_sandbox_compute_memory_mib_seconds_in_period": [(2, 31)],
+ }
+ )
+ with patch("posthoganalytics.get_feature_flag", return_value=flag_mode) as flag:
+ service = UsageCounterService()
+ plan = service.resolve_plan(period, caller="daily_report", complete=True, counters=counters)
+ report = service.fetch_report(period, plan=plan)
+
+ assert plan.modes == dict.fromkeys(counters, UsageCounterMode.LEGACY)
+ assert report.counts == expected
+ assert report.usage_sources is None
+ assert report.counter_comparisons is None
+ assert {call.args[0] for call in flag.call_args_list} == {
+ f"usage-counter-realtime-{suffix}" for suffix in COUNTER_FLAG_NAMES.values()
+ }
+ self.records.assert_not_called()
+ self.logs_retention.assert_called_once_with(period.start, period.end)
+ self.sandbox_compute.assert_called_once_with(period.start, period.end)
diff --git a/posthog/tasks/test/test_usage_report.py b/posthog/tasks/test/test_usage_report.py
index 2004710fb1ff..4335aeff4d09 100644
--- a/posthog/tasks/test/test_usage_report.py
+++ b/posthog/tasks/test/test_usage_report.py
@@ -3,7 +3,7 @@ import json
import base64
import dataclasses
from datetime import UTC, datetime, timedelta
-from typing import Any
+from typing import Any, cast
from uuid import uuid4
import pytest
@@ -64,6 +64,7 @@ from posthog.tasks.usage_report import (
_get_team_report,
_get_teams_for_usage_reports,
_get_teams_with_ai_credits_for_products,
+ apply_usage_counter_metadata,
capture_event,
capture_report,
get_all_event_metrics_in_period,
@@ -77,8 +78,10 @@ from posthog.tasks.usage_report import (
has_non_zero_usage,
send_all_org_usage_reports,
)
+from posthog.temporal.usage_report.queries import QUERY_INDEX
from posthog.test.fixtures import create_app_metric2
from posthog.test.test_utils import create_group_type_mapping_without_created_at
+from posthog.usage_counters import UsageCounter, UsageCounterQuery, UsageCounterService
from posthog.utils import get_previous_day
from products.batch_exports.backend.facade import testing as batch_exports_testing
@@ -2071,6 +2074,14 @@ class TestFeatureFlagsUsageReport(ClickhouseDestroyTablesMixin, TestCase, Clickh
assert org_2_report["teams"]["5"]["local_evaluation_requests_count_in_period"] == 0
assert org_2_report["teams"]["5"]["billable_feature_flag_requests_count_in_period"] == 0
+ with self.settings(DECIDE_BILLING_ANALYTICS_TOKEN="correct"):
+ for counter, expected in (
+ (UsageCounter.FEATURE_FLAG_REQUESTS, {}),
+ (UsageCounter.FEATURE_FLAG_LOCAL_EVALUATION_REQUESTS, {3: 10, 4: 1}),
+ ):
+ query = cast(UsageCounterQuery, QUERY_INDEX[counter].fn)
+ assert {int(team_id): count for team_id, count in query(period.start, period.end)} == expected
+
@patch("posthog.tasks.usage_report.get_ph_client")
@patch("posthog.tasks.usage_report.send_report_to_billing_service")
def test_active_hog_destinations_and_transformations_per_team(
@@ -3370,6 +3381,59 @@ class TestHogFunctionUsageReports(ClickhouseDestroyTablesMixin, TestCase, Clickh
assert org_1_report["teams"]["4"]["hog_function_fetch_calls_in_period"] == 2
assert org_1_report["teams"]["4"]["cdp_billable_invocations_in_period"] == 3
+ query = cast(UsageCounterQuery, QUERY_INDEX[UsageCounter.CDP_INVOCATIONS].fn)
+ assert dict(query(period.start, period.end)) == {3: 5, 4: 3}
+
+ base_record = {
+ "schema_version": 1,
+ "record_id": "invocation-a",
+ "producer_id": "producer-a",
+ "team_id": 3,
+ "organization_id": self.org_1.id,
+ "usage_key": "cdp_billable_invocations",
+ "unit": "invocations",
+ "quantity": 2,
+ "timestamp": period.start + timedelta(hours=1),
+ "inserted_at": period.start + timedelta(hours=1),
+ }
+ corrected = {**base_record, "quantity": 5, "inserted_at": period.start + timedelta(hours=2)}
+ records = [
+ base_record,
+ corrected,
+ corrected,
+ {**base_record, "producer_id": "producer-b"},
+ {**base_record, "team_id": 4, "record_id": "invocation-b", "quantity": 3},
+ {**base_record, "usage_key": "workflow_emails_sent", "quantity": 90},
+ {**base_record, "timestamp": period.start - timedelta(days=1), "quantity": 100},
+ {**base_record, "record_id": "at-end", "timestamp": period.end, "quantity": 500},
+ ]
+ sync_execute(
+ """
+ INSERT INTO sharded_billing_usage_records
+ (schema_version, record_id, producer_id, team_id, organization_id, usage_key, unit, quantity, timestamp, inserted_at)
+ VALUES
+ """,
+ records,
+ )
+ with self.settings(USAGE_COUNTER_REALTIME_MODES="cdp-invocations:both"):
+ plan = UsageCounterService().resolve_plan(period, caller="daily_report", complete=True)
+ counter_report = UsageCounterService().fetch_report(period, plan=plan)
+ assert counter_report.counter_comparisons is not None
+ assert counter_report.counter_comparisons["cdp_billable_invocations_in_period"].realtime_by_team == {
+ 3: {str(self.org_1.id): 7},
+ 4: {str(self.org_1.id): 3},
+ }
+ apply_usage_counter_metadata(
+ all_reports, counter_report, caller="daily_report", date=period.start.date().isoformat()
+ )
+ with_shadow = _get_full_org_usage_report_as_dict(
+ _get_full_org_usage_report(all_reports[str(self.org_1.id)], get_instance_metadata(period))
+ )
+ assert with_shadow["cdp_billable_invocations_in_period"] == 8
+ assert with_shadow["counter_comparisons"] == {
+ "cdp_billable_invocations_in_period": {"legacy": 8, "realtime": 10}
+ }
+
@patch("posthog.tasks.usage_report.get_ph_client")
@patch("posthog.tasks.usage_report.send_report_to_billing_service")
def test_workflow_usage_metrics(self, billing_task_mock: MagicMock, posthog_capture_mock: MagicMock) -> None:
@@ -3464,6 +3528,15 @@ class TestHogFunctionUsageReports(ClickhouseDestroyTablesMixin, TestCase, Clickh
assert org_1_report["teams"]["4"]["workflow_sms_sent_in_period"] == 2
assert org_1_report["teams"]["4"]["workflow_billable_invocations_in_period"] == 19 # fetch 12, push 7
+ for counter, expected in (
+ (UsageCounter.WORKFLOW_EMAILS, {3: 10, 4: 15}),
+ (UsageCounter.WORKFLOW_PUSH, {3: 5, 4: 7}),
+ (UsageCounter.WORKFLOW_SMS, {3: 3, 4: 2}),
+ (UsageCounter.WORKFLOW_INVOCATIONS, {3: 13, 4: 19}),
+ ):
+ query = cast(UsageCounterQuery, QUERY_INDEX[counter].fn)
+ assert dict(query(period.start, period.end)) == expected
+
@parameterized.expand(
[
# 1.5 GB at a non-tier 45 days = 67.5 GB-days, so logs_retention_mb_days_in_period = 67_500
diff --git a/posthog/tasks/usage_report.py b/posthog/tasks/usage_report.py
index e14855309bd4..41ff64373eee 100644
--- a/posthog/tasks/usage_report.py
+++ b/posthog/tasks/usage_report.py
@@ -6,7 +6,7 @@ import base64
import logging
import dataclasses
from collections import Counter, defaultdict
-from collections.abc import Callable, Sequence
+from collections.abc import Callable, Iterable, Iterator, Sequence
from datetime import datetime, timedelta
from typing import Any, Literal, Optional, TypedDict, Union
@@ -17,6 +17,7 @@ from django.db.models import Count, Q, Sum
import requests
import structlog
+import posthoganalytics
from cachetools import cached
from celery import shared_task
from dateutil import parser
@@ -42,11 +43,24 @@ from posthog.models.organization import Organization
from posthog.models.property.util import get_property_string_expr
from posthog.models.team.team import Team
from posthog.models.utils import namedtuplefetchall
+from posthog.ph_client import ph_scoped_capture
from posthog.scoping_audit import skip_team_scope_audit
from posthog.settings import CLICKHOUSE_CLUSTER, INSTANCE_TAG
from posthog.tasks.ai_observability_usage_report import LLM_PROMPT_FETCHED_EVENT
from posthog.tasks.report_utils import capture_event
from posthog.tasks.utils import CeleryQueue
+from posthog.usage_counters import (
+ RECORD_USAGE_UNITS,
+ SHADOW_MISSING_ORGS,
+ UsageCounterCaller,
+ UsageCounterComparison,
+ UsageCounterMode,
+ UsageCounterReport,
+ UsageCounterService,
+ UsageRecordTotal,
+ UsageRecordTotals,
+ validate_usage_record_window,
+)
from posthog.utils import DayRange, get_helm_info_env, get_instance_realm, get_instance_region, get_previous_day
from products.batch_exports.backend.facade import api as batch_exports_api
@@ -411,7 +425,7 @@ class InstanceMetadata:
instance_tag: str
[email protected](frozen=False)
class OrgReport(UsageReportCounters):
date: str
organization_id: str
@@ -420,6 +434,8 @@ class OrgReport(UsageReportCounters):
organization_user_count: int
team_count: int
teams: dict[str, UsageReportCounters]
+ usage_sources: dict[str, UsageCounterMode] | None = dataclasses.field(default=None, kw_only=True)
+ counter_comparisons: dict[str, UsageCounterComparison] | None = dataclasses.field(default=None, kw_only=True)
@dataclasses.dataclass
@@ -2921,12 +2937,72 @@ def convert_team_usage_rows_to_dict(
return team_id_map
-def _get_all_usage_data(period_start: datetime, period_end: datetime) -> dict[str, Any]:
+@frozen
+class _UsageRecordRow:
+ team_id: int
+ organization_id: str
+ usage_key: str
+ unit: str
+ quantity: int
+
+
+@retry(tries=QUERY_RETRIES, delay=QUERY_RETRY_DELAY, backoff=QUERY_RETRY_BACKOFF)
+def _query_usage_records(
+ period: DayRange, usage_keys: tuple[str, ...], caller: UsageCounterCaller
+) -> list[_UsageRecordRow]:
+ with tags_context(product=Product.BILLING, feature=Feature.USAGE_REPORT, usage_report=f"{caller}_usage_counters"):
+ rows = sync_execute(
+ """
+ SELECT team_id, organization_id, usage_key, unit, sum(quantity)
+ FROM billing_usage_records FINAL
+ WHERE timestamp >= %(begin)s AND timestamp < %(end)s
+ AND usage_key IN %(usage_keys)s
+ GROUP BY team_id, organization_id, usage_key, unit
+ """,
+ {"begin": period.start, "end": period.end, "usage_keys": usage_keys},
+ workload=Workload.OFFLINE,
+ ch_user=ClickHouseUser.BILLING,
+ settings={**CH_BILLING_SETTINGS, "do_not_merge_across_partitions_select_final": 1},
+ )
+ return [
+ _UsageRecordRow(team_id=team_id, organization_id=str(org_id), usage_key=key, unit=unit, quantity=quantity)
+ for team_id, org_id, key, unit, quantity in rows
+ ]
+
+
+@timed_log()
+def get_usage_records_in_period(
+ period: DayRange, usage_keys: tuple[str, ...], caller: UsageCounterCaller
+) -> UsageRecordTotals:
+ # Validation runs outside the retried query, because a bad window or unit fails the same way on every attempt.
+ validate_usage_record_window(period)
+ rows = _query_usage_records(period, usage_keys, caller)
+ errors = {
+ row.usage_key: f"Unexpected unit {row.unit!r} for usage key {row.usage_key!r}; expected {RECORD_USAGE_UNITS[row.usage_key]!r}"
+ for row in rows
+ if row.unit != RECORD_USAGE_UNITS[row.usage_key]
+ }
+ return UsageRecordTotals(
+ totals=[
+ UsageRecordTotal(
+ team_id=row.team_id, organization_id=row.organization_id, usage_key=row.usage_key, quantity=row.quantity
+ )
+ for row in rows
+ if row.usage_key not in errors
+ ],
+ errors=errors,
+ )
+
+
+def _get_all_usage_data(
+ period_start: datetime, period_end: datetime, counter_report: UsageCounterReport | None = None
+) -> dict[str, Any]:
"""
Gets all usage data for the specified period. Clickhouse is good at counting things so
we count across all teams rather than doing it one by one
"""
+ counter_report = counter_report or UsageCounterService().fetch_report(DayRange(start=period_start, end=period_end))
all_metrics = get_all_event_metrics_in_period(period_start, period_end)
api_queries_usage = get_teams_with_api_queries_metrics(period_start, period_end)
logs_records_rows = get_teams_with_logs_records_in_period(period_start, period_end)
@@ -2934,24 +3010,12 @@ def _get_all_usage_data(period_start: datetime, period_end: datetime) -> dict[st
sdk_logs_by_suffix = get_teams_with_sdk_logs_records_in_period(
period_start, period_end, team_ids_with_logs=team_ids_with_logs
)
- logs_retention_by_tier = get_teams_with_logs_retention_bytes_in_period(period_start, period_end)
- logs_retention_byte_days_rows = get_teams_with_logs_retention_byte_days_in_period(period_start, period_end)
apm_tracing_usage = get_teams_with_apm_tracing_usage_in_period(period_start, period_end)
metrics_usage = get_teams_with_metrics_usage_in_period(period_start, period_end)
- exception_metrics_by_library, exception_metrics = get_teams_with_exceptions_captured_in_period(
- period_start, period_end
- )
task_sandbox_usage = get_teams_with_task_sandbox_usage_in_period(period_start, period_end)
- sandbox_compute_usage = get_teams_with_billable_sandbox_compute_usage_in_period(period_start, period_end)
- token_credits = get_teams_with_posthog_code_credits_used_in_period(period_start, period_end)
return {
- "teams_with_event_count_in_period": get_teams_with_billable_event_count_in_period(
- period_start, period_end, count_distinct=True
- ),
- "teams_with_enhanced_persons_event_count_in_period": get_teams_with_billable_enhanced_persons_event_count_in_period(
- period_start, period_end, count_distinct=True
- ),
+ **counter_report.counts,
"teams_with_event_count_with_groups_in_period": get_teams_with_event_count_with_groups_in_period(
period_start, period_end, count_distinct=True
),
@@ -2995,36 +3059,18 @@ def _get_all_usage_data(period_start: datetime, period_end: datetime) -> dict[st
"teams_with_unity_events_count_in_period": all_metrics["unity_events"],
"teams_with_rust_events_count_in_period": all_metrics["rust_events"],
"teams_with_heatmap_count_in_period": get_teams_with_heatmap_count_in_period(period_start, period_end),
- "teams_with_recording_count_in_period": get_teams_with_recording_count_in_period(
- period_start, period_end, snapshot_source="web"
- ),
"teams_with_zero_duration_recording_count_in_period": get_teams_with_zero_duration_recording_count_in_period(
period_start, period_end
),
"teams_with_recording_bytes_in_period": get_teams_with_recording_bytes_in_period(
period_start, period_end, snapshot_source="web"
),
- "teams_with_mobile_recording_count_in_period": get_teams_with_recording_count_in_period(
- period_start, period_end, snapshot_source="mobile"
- ),
"teams_with_mobile_recording_bytes_in_period": get_teams_with_recording_bytes_in_period(
period_start, period_end, snapshot_source="mobile"
),
- "teams_with_mobile_billable_recording_count_in_period": get_teams_with_mobile_billable_recording_count_in_period(
- period_start, period_end
- ),
- "teams_with_replay_vision_credits_used_in_period": get_teams_with_replay_vision_credits_used_in_period(
- period_start, period_end
- ),
"teams_with_replay_vision_observation_count_in_period": get_teams_with_replay_vision_observation_count_in_period(
period_start, period_end
),
- "teams_with_decide_requests_count_in_period": get_teams_with_feature_flag_requests_count_in_period(
- period_start, period_end, FlagRequestType.DECIDE
- ),
- "teams_with_local_evaluation_requests_count_in_period": get_teams_with_feature_flag_requests_count_in_period(
- period_start, period_end, FlagRequestType.LOCAL_EVALUATION
- ),
"teams_with_group_types_total": count_group_type_mappings_per_team(),
"teams_with_dashboard_count": list(
Dashboard.objects.values("team_id").annotate(total=Count("id")).order_by("team_id")
@@ -3153,70 +3199,22 @@ def _get_all_usage_data(period_start: datetime, period_end: datetime) -> dict[st
query_types=["EventsQuery"],
access_method="personal_api_key",
),
- "teams_with_survey_responses_count_in_period": get_teams_with_survey_responses_count_in_period(
- period_start, period_end
- ),
- "teams_with_rows_synced_in_period": get_teams_with_rows_synced_in_period(period_start, period_end),
- "teams_with_free_historical_rows_synced_in_period": get_teams_with_free_historical_rows_synced_in_period(
- period_start, period_end
- ),
- "teams_with_rows_exported_in_period": get_teams_with_rows_exported_in_period(period_start, period_end),
"teams_with_active_external_data_schemas_in_period": get_teams_with_active_external_data_schemas_in_period(),
"teams_with_active_batch_exports_in_period": get_teams_with_active_batch_exports_in_period(),
"teams_with_dwh_tables_storage_in_s3_in_mib": get_teams_with_dwh_tables_storage_in_s3(),
"teams_with_dwh_mat_views_storage_in_s3_in_mib": get_teams_with_dwh_mat_views_storage_in_s3(),
"teams_with_dwh_total_storage_in_s3_in_mib": get_teams_with_dwh_total_storage_in_s3(),
- "teams_with_exceptions_captured_in_period": exception_metrics,
- "teams_with_web_exceptions_captured_in_period": exception_metrics_by_library["web"],
- "teams_with_js_lite_exceptions_captured_in_period": exception_metrics_by_library["web_lite"],
- "teams_with_node_exceptions_captured_in_period": exception_metrics_by_library["node"],
- "teams_with_go_exceptions_captured_in_period": exception_metrics_by_library["go"],
- "teams_with_java_exceptions_captured_in_period": exception_metrics_by_library["java"],
- "teams_with_ruby_exceptions_captured_in_period": exception_metrics_by_library["ruby"],
- "teams_with_python_exceptions_captured_in_period": exception_metrics_by_library["python"],
- "teams_with_android_exceptions_captured_in_period": exception_metrics_by_library["android"],
- "teams_with_react_native_exceptions_captured_in_period": exception_metrics_by_library["react_native"],
- "teams_with_ios_exceptions_captured_in_period": exception_metrics_by_library["ios"],
- "teams_with_flutter_exceptions_captured_in_period": exception_metrics_by_library["flutter"],
- "teams_with_unknown_exceptions_captured_in_period": exception_metrics_by_library["unknown"],
"teams_with_hog_function_calls_in_period": get_teams_with_hog_function_calls_in_period(
period_start, period_end
),
"teams_with_hog_function_fetch_calls_in_period": get_teams_with_hog_function_fetch_calls_in_period(
period_start, period_end
),
- "teams_with_cdp_billable_invocations_in_period": get_teams_with_cdp_billable_invocations_in_period(
- period_start, period_end
- ),
- "teams_with_ai_event_count_in_period": get_teams_with_ai_event_count_in_period(period_start, period_end),
- "teams_with_ai_credits_used_in_period": get_teams_with_ai_credits_used_in_period(period_start, period_end),
- "teams_with_signals_credits_used_in_period": get_teams_with_signals_credits_used_in_period(
- period_start, period_end
- ),
- "teams_with_posthog_code_credits_used_in_period": token_credits,
- "teams_with_sandbox_compute_credits_used_in_period": sandbox_compute_usage.credits,
- "teams_with_sandbox_compute_cpu_millicore_seconds_in_period": sandbox_compute_usage.cpu_millicore_seconds,
- "teams_with_sandbox_compute_memory_mib_seconds_in_period": sandbox_compute_usage.memory_mib_seconds,
"teams_with_task_sandbox_seconds_in_period": task_sandbox_usage.seconds,
"teams_with_task_sandbox_cpu_core_seconds_in_period": task_sandbox_usage.cpu_core_seconds,
"teams_with_task_sandbox_memory_gib_seconds_in_period": task_sandbox_usage.memory_gib_seconds,
"teams_with_active_hog_destinations_in_period": get_teams_with_active_hog_destinations_in_period(),
"teams_with_active_hog_transformations_in_period": get_teams_with_active_hog_transformations_in_period(),
- "teams_with_workflow_emails_sent_in_period": get_teams_with_workflow_emails_sent_in_period(
- period_start, period_end
- ),
- "teams_with_workflow_push_sent_in_period": get_teams_with_workflow_push_sent_in_period(
- period_start, period_end
- ),
- "teams_with_workflow_sms_sent_in_period": get_teams_with_workflow_sms_sent_in_period(period_start, period_end),
- "teams_with_workflow_billable_invocations_in_period": get_teams_with_workflow_billable_invocations_in_period(
- period_start, period_end
- ),
- "teams_with_logs_bytes_in_period": get_teams_with_logs_bytes_in_period(period_start, period_end),
- "teams_with_logs_retention_14d_bytes_in_period": logs_retention_by_tier["14d"],
- "teams_with_logs_retention_30d_bytes_in_period": logs_retention_by_tier["30d"],
- "teams_with_logs_retention_90d_bytes_in_period": logs_retention_by_tier["90d"],
- "teams_with_logs_retention_byte_days_in_period": logs_retention_byte_days_rows,
"teams_with_logs_records_in_period": logs_records_rows,
"teams_with_web_logs_records_in_period": sdk_logs_by_suffix["web"],
"teams_with_ios_logs_records_in_period": sdk_logs_by_suffix["ios"],
@@ -3231,12 +3229,14 @@ def _get_all_usage_data(period_start: datetime, period_end: datetime) -> dict[st
}
-def _get_all_usage_data_as_team_rows(period_start: datetime, period_end: datetime) -> dict[str, Any]:
+def _get_all_usage_data_as_team_rows(
+ period_start: datetime, period_end: datetime, counter_report: UsageCounterReport | None = None
+) -> dict[str, Any]:
"""
Gets all usage data for the specified period as a map of team_id -> value. This makes it faster
to access the data than looping over all_data to find what we want.
"""
- all_data = _get_all_usage_data(period_start, period_end)
+ all_data = _get_all_usage_data(period_start, period_end, counter_report)
# convert it to a map of team_id -> value
for key, rows in all_data.items():
all_data[key] = convert_team_usage_rows_to_dict(rows)
@@ -3522,10 +3522,10 @@ def _add_team_report_to_org_reports(
)
-def _get_all_org_reports(*, period: DayRange) -> dict[str, OrgReport]:
+def _get_all_org_reports(*, period: DayRange, counter_report: UsageCounterReport | None = None) -> dict[str, OrgReport]:
logger.info("Querying all org reports", period_start=period.start, period_end=period.end)
- all_data = _get_all_usage_data_as_team_rows(period.start, period.end)
+ all_data = _get_all_usage_data_as_team_rows(period.start, period.end, counter_report)
logger.info("Querying all teams")
@@ -3554,10 +3554,118 @@ def _get_full_org_usage_report(org_report: OrgReport, instance_metadata: Instanc
def _get_full_org_usage_report_as_dict(full_report: FullUsageReport) -> dict[str, Any]:
- return {
+ report = {
**dataclasses.asdict(full_report),
"has_non_zero_usage": has_non_zero_usage(full_report),
}
+ for field in ("usage_sources", "counter_comparisons"):
+ if report[field] is None:
+ del report[field]
+ return report
+
+
+def _usage_counter_diagnostic_batches(
+ missing: dict[str, dict[str, UsageCounterComparison]],
+) -> Iterator[dict[str, dict[str, UsageCounterComparison]]]:
+ # Leave room for the SDK envelope and properties below its 900 KiB event limit.
+ max_bytes = 500_000
+ batch: dict[str, dict[str, UsageCounterComparison]] = {}
+ size = 2
+ for org_id, comparisons in missing.items():
+ entry_size = len(json.dumps({org_id: comparisons}).encode("utf-8"))
+ if entry_size > max_bytes:
+ raise ValueError("A usage counter diagnostic entry exceeds the event size limit")
+ if batch and size + entry_size > max_bytes:
+ yield batch
+ batch = {}
+ size = 2
+ batch[org_id] = comparisons
+ size += entry_size
+ if batch:
+ yield batch
+
+
+def apply_usage_counter_metadata(
+ org_reports: dict[str, OrgReport],
+ counter_report: UsageCounterReport,
+ *,
+ caller: UsageCounterCaller,
+ date: str,
+ organization_ids: list[str] | None = None,
+) -> None:
+ if not counter_report.usage_sources:
+ return
+ for _ in iter_reports_with_usage_counter_metadata(
+ org_reports.values(), counter_report, caller=caller, date=date, organization_ids=organization_ids
+ ):
+ pass
+
+
+def iter_reports_with_usage_counter_metadata(
+ org_reports: Iterable[OrgReport],
+ counter_report: UsageCounterReport,
+ *,
+ caller: UsageCounterCaller,
+ date: str,
+ organization_ids: list[str] | None = None,
+) -> Iterator[OrgReport]:
+ if not counter_report.usage_sources:
+ yield from org_reports
+ return
+ report_orgs: set[str] = set()
+ report_teams: set[int] = set()
+ missing: dict[str, dict[str, UsageCounterComparison]] = {}
+ wanted = set(organization_ids) if organization_ids else None
+ for report in org_reports:
+ report.usage_sources = counter_report.usage_sources
+ report.counter_comparisons = {} if counter_report.counter_comparisons is not None else None
+ if counter_report.counter_comparisons is not None:
+ org_id = report.organization_id
+ teams = [int(team_id) for team_id in report.teams]
+ report_orgs.add(org_id)
+ report_teams.update(teams)
+ reported = has_non_zero_usage(report)
+ for field, rows in counter_report.counter_comparisons.items():
+ comparison: UsageCounterComparison = {
+ "legacy": sum(rows.legacy_by_team.get(team_id, 0) for team_id in teams),
+ "realtime": sum(sum(rows.realtime_by_team.get(team_id, {}).values()) for team_id in teams),
+ }
+ assert report.counter_comparisons is not None
+ report.counter_comparisons[field] = comparison
+ if (
+ (comparison["legacy"] or comparison["realtime"])
+ and not reported
+ and (wanted is None or org_id in wanted)
+ ):
+ missing.setdefault(org_id, {})[field] = comparison
+ yield report
+ if counter_report.counter_comparisons is None:
+ return
+ for field, rows in counter_report.counter_comparisons.items():
+ # A team in no report keeps the organization on its records, so deleted organizations still show as missing.
+ unreported: dict[str, int] = {}
+ for team_id, orgs in rows.realtime_by_team.items():
+ if team_id in report_teams:
+ continue
+ for org_id, quantity in orgs.items():
+ if org_id not in report_orgs and (wanted is None or org_id in wanted):
+ unreported[org_id] = unreported.get(org_id, 0) + quantity
+ for org_id, quantity in unreported.items():
+ if quantity:
+ missing.setdefault(org_id, {})[field] = {"legacy": 0, "realtime": quantity}
+ try:
+ SHADOW_MISSING_ORGS.labels(caller=caller).set(len(missing))
+ if missing:
+ logger.warning("usage_counter_shadow_missing_organizations", caller=caller, date=date, count=len(missing))
+ with ph_scoped_capture(region=get_instance_region() or "US") as capture:
+ for batch in _usage_counter_diagnostic_batches(missing):
+ capture(
+ distinct_id="internal_billing_events",
+ event="usage counter shadow missing organizations",
+ properties={"caller": caller, "date": date, "organizations": batch},
+ )
+ except Exception:
+ logger.exception("usage_counter_shadow_diagnostics_failed", caller=caller, date=date)
def build_org_reports(all_data: dict[str, Any], period_start: datetime) -> dict[str, OrgReport]:
@@ -3613,7 +3721,6 @@ def send_all_org_usage_reports(
skip_capture_event: bool = False,
organization_ids: Optional[list[str]] = None,
) -> None:
- import posthoganalytics
are_usage_reports_disabled = posthoganalytics.feature_enabled("disable-usage-reports", "internal_billing_events")
if are_usage_reports_disabled:
@@ -3646,7 +3753,10 @@ def send_all_org_usage_reports(
logger.info("Querying usage report data")
query_time_start = datetime.now()
- org_reports = _get_all_org_reports(period=period)
+ service = UsageCounterService()
+ plan = service.resolve_plan(period, caller="daily_report", complete=True)
+ counter_report = service.fetch_report(period, plan=plan)
+ org_reports = _get_all_org_reports(period=period, counter_report=counter_report)
if organization_ids:
original_count = len(org_reports)
@@ -3665,6 +3775,14 @@ def send_all_org_usage_reports(
filtering_properties["requested_org_count"] = len(organization_ids)
filtering_properties["requested_missing_org_count"] = len(missing_orgs) if missing_orgs else None
+ apply_usage_counter_metadata(
+ org_reports,
+ counter_report,
+ caller="daily_report",
+ date=period.start.strftime("%Y-%m-%d"),
+ organization_ids=organization_ids,
+ )
+
query_time_duration = (datetime.now() - query_time_start).total_seconds()
logger.info(f"Found {len(org_reports)} org reports. It took {query_time_duration} seconds.")
diff --git a/posthog/temporal/tests/usage_report/conftest.py b/posthog/temporal/tests/usage_report/conftest.py
index 2ad0e786fb72..226430ea06aa 100644
--- a/posthog/temporal/tests/usage_report/conftest.py
+++ b/posthog/temporal/tests/usage_report/conftest.py
@@ -21,6 +21,7 @@ from botocore.client import Config
from posthog.temporal.usage_report.storage import bucket, run_prefix
from posthog.temporal.usage_report.types import WorkflowContext
+from posthog.usage_counters import _mode_cache
def _s3_resource():
@@ -54,3 +55,10 @@ def minio_workflow_ctx() -> Iterator[WorkflowContext]:
yield ctx
finally:
_delete_prefix(run_prefix(ctx))
+
+
[email protected](autouse=True)
+def clear_usage_counter_mode_cache() -> Iterator[None]:
+ _mode_cache.clear()
+ yield
+ _mode_cache.clear()
diff --git a/posthog/temporal/tests/usage_report/test_aggregator.py b/posthog/temporal/tests/usage_report/test_aggregator.py
index 8ce5174e8e3a..b016d4be0937 100644
--- a/posthog/temporal/tests/usage_report/test_aggregator.py
+++ b/posthog/temporal/tests/usage_report/test_aggregator.py
@@ -7,13 +7,22 @@ No Django / Temporal / S3 required.
"""
import json
+import weakref
import dataclasses
+from collections.abc import Iterator
from datetime import UTC, datetime
from typing import Any, cast
+import pytest
from unittest.mock import patch
-from posthog.tasks.usage_report import InstanceMetadata, OrgReport, UsageReportCounters
+from posthog.tasks.usage_report import (
+ InstanceMetadata,
+ OrgReport,
+ UsageReportCounters,
+ apply_usage_counter_metadata,
+ iter_reports_with_usage_counter_metadata,
+)
from posthog.temporal.usage_report.aggregator import (
add_pre_sandbox_compute_patch_defaults,
build_manifest,
@@ -21,9 +30,24 @@ from posthog.temporal.usage_report.aggregator import (
filter_orgs_with_usage,
iter_chunk_lines,
load_all_data,
+ load_usage_counter_report,
sort_org_reports,
)
-from posthog.temporal.usage_report.types import Manifest, ReportCompleteness, RunQueryToS3Result, WorkflowContext
+from posthog.temporal.usage_report.types import (
+ AggregateInputs,
+ Manifest,
+ ReportCompleteness,
+ RunQueryToS3Result,
+ WorkflowContext,
+)
+from posthog.usage_counters import (
+ UsageCounterComparison,
+ UsageCounterComparisonRows,
+ UsageCounterMode,
+ UsageCounterReport,
+ UsageCounterService,
+)
+from posthog.utils import DayRange
def _ctx(run_id: str = "abc", report_completeness: ReportCompleteness = "partial") -> WorkflowContext:
@@ -150,6 +174,152 @@ def test_load_all_data_does_not_default_compute_for_patched_workflow_history() -
assert all_data == {}
+ "state", ["zero", "failed_scan", "missing_result", "missing_object", "invalid_json", "legacy", "partial"]
+)
+def test_shadow_coverage_distinguishes_zero_from_failure(state: str) -> None:
+ ctx = _ctx(report_completeness="partial" if state == "partial" else "complete")
+ if state != "legacy":
+ with patch("posthoganalytics.get_feature_flag", return_value="both"):
+ ctx.usage_counter_plan = UsageCounterService().resolve_plan(
+ DayRange(start=ctx.period_start, end=ctx.period_end),
+ caller="usage_reports_v2",
+ complete=ctx.report_completeness == "complete",
+ )
+ result = RunQueryToS3Result(query_name="usage_counters", s3_key="shadow.json", duration_ms=1)
+ payload = json.dumps(
+ {
+ "counts": {"teams_with_cdp_billable_invocations_in_period": [[1, 12]]},
+ "usage_sources": {"cdp_billable_invocations_in_period": "both"},
+ "counter_comparisons": None
+ if state == "failed_scan"
+ else {"cdp_billable_invocations_in_period": {"legacy_by_team": {1: 12}, "realtime_by_team": {}}},
+ }
+ ).encode()
+ with patch(
+ "posthog.storage.object_storage.read_bytes", return_value=b"invalid" if state == "invalid_json" else payload
+ ) as read:
+ if state == "missing_object":
+ read.side_effect = FileNotFoundError("missing")
+ inputs = AggregateInputs(
+ ctx=ctx, query_results=[], counter_result=None if state in {"missing_result", "legacy"} else result
+ )
+ if state in {"missing_result", "missing_object", "invalid_json"}:
+ with pytest.raises((ValueError, FileNotFoundError)):
+ load_usage_counter_report(inputs)
+ return
+ counter_report = load_usage_counter_report(inputs)
+ if state != "legacy":
+ assert counter_report.counts == {"teams_with_cdp_billable_invocations_in_period": [(1, 12)]}
+ org = _empty_org_report("org-a", cdp_billable_invocations_in_period=12)
+ org.teams["1"] = _empty_org_report("org-a", cdp_billable_invocations_in_period=12)
+ apply_usage_counter_metadata({"org-a": org}, counter_report, caller="usage_reports_v2", date=ctx.date_str)
+ assert org.cdp_billable_invocations_in_period == 12
+ if state == "legacy":
+ assert org.usage_sources is None
+ read.assert_not_called()
+ else:
+ assert org.usage_sources is not None
+ assert org.usage_sources["cdp_billable_invocations_in_period"] == "both"
+ assert org.counter_comparisons == (
+ {"cdp_billable_invocations_in_period": {"legacy": 12, "realtime": 0}} if state in {"zero", "partial"} else None
+ )
+
+
[email protected]("streamed", [False, True])
+def test_counter_comparisons_follow_current_team_ownership(streamed: bool) -> None:
+ previous_owner = _empty_org_report("org-a")
+ previous_owner.teams["1"] = _empty_org_report("org-a")
+ current_owner = _empty_org_report("org-b", cdp_billable_invocations_in_period=100)
+ current_owner.teams["2"] = _empty_org_report("org-b", cdp_billable_invocations_in_period=100)
+ counter_report = UsageCounterReport(
+ counts={},
+ usage_sources={"cdp_billable_invocations_in_period": UsageCounterMode.BOTH},
+ counter_comparisons={
+ "cdp_billable_invocations_in_period": UsageCounterComparisonRows(
+ legacy_by_team={2: 100}, realtime_by_team={2: {"org-a": 60, "org-b": 40}}
+ )
+ },
+ )
+
+ with patch("posthog.tasks.usage_report.ph_scoped_capture") as capture:
+ if streamed:
+ assert list(
+ iter_reports_with_usage_counter_metadata(
+ iter((previous_owner, current_owner)), counter_report, caller="usage_reports_v2", date="2026-05-04"
+ )
+ ) == [previous_owner, current_owner]
+ else:
+ apply_usage_counter_metadata(
+ {"org-a": previous_owner, "org-b": current_owner},
+ counter_report,
+ caller="daily_report",
+ date="2026-05-04",
+ )
+
+ assert previous_owner.counter_comparisons == {"cdp_billable_invocations_in_period": {"legacy": 0, "realtime": 0}}
+ assert current_owner.counter_comparisons == {"cdp_billable_invocations_in_period": {"legacy": 100, "realtime": 100}}
+ capture.assert_not_called()
+
+
+def test_counter_metadata_does_not_retain_streamed_reports() -> None:
+ references: list[weakref.ReferenceType[OrgReport]] = []
+
+ def reports() -> Iterator[OrgReport]:
+ for team_id in range(4):
+ report = _empty_org_report(str(team_id), event_count_in_period=1)
+ report.teams[str(team_id)] = _empty_org_report(str(team_id), event_count_in_period=1)
+ references.append(weakref.ref(report))
+ yield report
+
+ counter_report = UsageCounterReport(
+ counts={},
+ usage_sources={"event_count_in_period": UsageCounterMode.BOTH},
+ counter_comparisons={
+ "event_count_in_period": UsageCounterComparisonRows(
+ legacy_by_team=dict.fromkeys(range(4), 1),
+ realtime_by_team={team_id: {str(team_id): 2} for team_id in range(4)},
+ )
+ },
+ )
+ output = iter_reports_with_usage_counter_metadata(
+ reports(), counter_report, caller="usage_reports_v2", date="2026-05-04"
+ )
+ for team_id in range(4):
+ report = next(output)
+ assert report.organization_id == str(team_id)
+ assert report.counter_comparisons == {"event_count_in_period": {"legacy": 1, "realtime": 2}}
+ assert sum(ref() is not None for ref in references) == 1
+ del report
+ assert next(output, None) is None
+
+
+def test_missing_organization_diagnostics_split_without_losing_comparisons() -> None:
+ rows = {team: {f"00000000-0000-0000-0000-{team:012d}": 7} for team in range(10_000)}
+ report = UsageCounterReport(
+ counts={},
+ usage_sources={"event_count_in_period": UsageCounterMode.BOTH},
+ counter_comparisons={
+ "event_count_in_period": UsageCounterComparisonRows(legacy_by_team={}, realtime_by_team=rows)
+ },
+ )
+ with patch("posthog.tasks.usage_report.ph_scoped_capture") as scoped:
+ apply_usage_counter_metadata({}, report, caller="daily_report", date="2026-05-04")
+ calls = scoped.return_value.__enter__.return_value.call_args_list
+ assert len(calls) > 1
+ recovered: dict[str, dict[str, UsageCounterComparison]] = {}
+ for call in calls:
+ assert len(json.dumps(call.kwargs).encode("utf-8")) < 900 * 1024
+ batch = call.kwargs["properties"]["organizations"]
+ assert not recovered.keys() & batch.keys()
+ recovered.update(batch)
+ assert recovered == {
+ org: {"event_count_in_period": {"legacy": 0, "realtime": quantity}}
+ for orgs in rows.values()
+ for org, quantity in orgs.items()
+ }
+
+
# ---- iter_chunk_lines ----------------------------------------------------
@@ -277,6 +447,11 @@ def test_filter_orgs_with_usage_keeps_only_orgs_with_billable_counters() -> None
"with-events": _empty_org_report("with-events", event_count_in_period=1),
"with-recordings": _empty_org_report("with-recordings", recording_count_in_period=1),
"idle": _empty_org_report("idle"),
+ "shadow-only": _empty_org_report(
+ "shadow-only",
+ usage_sources={"cdp_billable_invocations_in_period": "both"},
+ counter_comparisons={"cdp_billable_invocations_in_period": {"legacy": 0, "realtime": 50}},
+ ),
# Counters not in `has_non_zero_usage` (dashboard counts, query
# bytes read, etc.) must not keep an org in.
"non-billable-only": _empty_org_report("non-billable-only", dashboard_count=10, query_app_bytes_read=5_000_000),
diff --git a/posthog/temporal/tests/usage_report/test_parity.py b/posthog/temporal/tests/usage_report/test_parity.py
index 42d848ffb619..2ab8111e0c91 100644
--- a/posthog/temporal/tests/usage_report/test_parity.py
+++ b/posthog/temporal/tests/usage_report/test_parity.py
@@ -17,8 +17,10 @@ import gzip
import json
import base64
import asyncio
+from contextlib import nullcontext
from datetime import UTC, datetime
from typing import Any
+from uuid import uuid4
import pytest
from unittest import mock
@@ -27,13 +29,28 @@ from django.db import connection
from django.test.utils import CaptureQueriesContext
from posthog.models import Organization, Team
+from posthog.tasks import usage_report
from posthog.tasks.usage_report import send_all_org_usage_reports
-from posthog.temporal.usage_report.activities import aggregate_and_chunk_org_reports
+from posthog.temporal.usage_report.activities import (
+ aggregate_and_chunk_org_reports,
+ fetch_usage_counter_report,
+ plan_usage_counters,
+ run_legacy_usage_counter,
+)
from posthog.temporal.usage_report.queries import QUERIES
from posthog.temporal.usage_report.storage import queries_key, write_json
-from posthog.temporal.usage_report.types import AggregateInputs, AggregateResult, RunQueryToS3Result, WorkflowContext
+from posthog.temporal.usage_report.types import (
+ AggregateInputs,
+ AggregateResult,
+ RunLegacyCounterInputs,
+ RunQueryToS3Result,
+ WorkflowContext,
+)
+from posthog.usage_counters import RECORD_REALTIME_BLOCKERS, UsageCounter
from posthog.utils import get_previous_day
+from products.tasks.backend.facade.billing import SandboxComputeUsageByTeam
+
def _all_destination_keys() -> list[str]:
"""Every key `_get_team_report` reads, derived from the registry so we
@@ -68,6 +85,14 @@ def _seed_all_data(team_a_id: int, team_b_id: int, team_c_id: int) -> dict[str,
"teams_with_ff_count": {team_a_id: 7, team_b_id: 3},
"teams_with_survey_count": {team_a_id: 1, team_c_id: 2},
"teams_with_web_events_count_in_period": {team_a_id: 60, team_b_id: 30},
+ "teams_with_rows_synced_in_period": {team_a_id: 101, team_b_id: 27},
+ "teams_with_logs_bytes_in_period": {team_a_id: 3_500_000, team_b_id: 600_000},
+ "teams_with_logs_retention_30d_bytes_in_period": {team_a_id: 2_500_000},
+ "teams_with_posthog_code_credits_used_in_period": {team_a_id: 321},
+ "teams_with_sandbox_compute_credits_used_in_period": {team_a_id: 9},
+ "teams_with_sandbox_compute_cpu_millicore_seconds_in_period": {team_b_id: 1_000},
+ "teams_with_sandbox_compute_memory_mib_seconds_in_period": {team_b_id: 2_000},
+ "teams_with_logs_retention_byte_days_in_period": {team_a_id: 4_000_000},
"teams_with_exceptions_captured_in_period": {team_a_id: 5, team_b_id: 1},
"teams_with_web_exceptions_captured_in_period": {team_a_id: 5},
"teams_with_node_exceptions_captured_in_period": {team_b_id: 1},
@@ -173,9 +198,14 @@ def _decode_temporal_chunks(s3: dict[str, bytes], chunk_keys: list[str]) -> dict
@pytest.mark.django_db(transaction=True)
+ ("mode", "guarded"), [("legacy", True), ("both", True), ("realtime", True), ("realtime", False)]
+)
def test_end_to_end_parity_celery_task_vs_temporal_activity(
activity_environment: Any,
monkeypatch: pytest.MonkeyPatch,
+ mode: str,
+ guarded: bool,
) -> None:
"""Both production paths must produce the same per-org bytes for the
same `all_data` snapshot. Drift here is what billing's parity check
@@ -192,10 +222,18 @@ def test_end_to_end_parity_celery_task_vs_temporal_activity(
team_a1 = Team.objects.create(organization=org_a, name="A1")
team_a2 = Team.objects.create(organization=org_a, name="A2")
team_b = Team.objects.create(organization=org_b, name="B")
+ idle_org = Organization.objects.create(name="Idle")
+ idle_team = Team.objects.create(organization=idle_org, name="Idle")
+ legacy_only_org = Organization.objects.create(name="Legacy only")
+ legacy_only_team = Team.objects.create(organization=legacy_only_org, name="Legacy only")
+ deleted_org_id = str(uuid4())
+ excluded_org_id = str(uuid4())
+ organization_ids = [str(org_a.id), str(org_b.id), str(idle_org.id), str(legacy_only_org.id), deleted_org_id]
celery_at = datetime(2026, 5, 5, 0, 0, 0, tzinfo=UTC)
period = get_previous_day(celery_at)
seeded = _seed_all_data(team_a1.id, team_a2.id, team_b.id)
+ seeded["teams_with_workflow_emails_sent_in_period"] = {team_a1.id: 11, team_a2.id: 13, legacy_only_team.id: 5}
s3 = _install_in_memory_object_storage(monkeypatch)
sqs_messages = _install_fake_sqs_producer(monkeypatch)
@@ -203,34 +241,176 @@ def test_end_to_end_parity_celery_task_vs_temporal_activity(
# Don't let the Celery task short-circuit on the kill-switch flag,
# and silence the start/end PostHog `capture` calls.
monkeypatch.setattr("posthoganalytics.feature_enabled", lambda *a, **kw: False)
+ monkeypatch.setattr("django.conf.settings.CLOUD_DEPLOYMENT", "US")
+ monkeypatch.setattr("django.conf.settings.USAGE_COUNTER_REALTIME_MODES", f"workflow-emails:{mode}")
+ if not guarded:
+ monkeypatch.delitem(RECORD_REALTIME_BLOCKERS, UsageCounter.WORKFLOW_EMAILS, raising=False)
+ resolved_mode = "both" if mode == "realtime" and guarded else mode
+ captures_on_event_loop: list[str] = []
+
+ def check_capture_thread(*args: Any, **kwargs: Any) -> None:
+ if kwargs.get("event") != "usage counter shadow missing organizations":
+ return
+ try:
+ asyncio.get_running_loop()
+ except RuntimeError:
+ return
+ captures_on_event_loop.append(kwargs["properties"]["caller"])
+
+ capture = mock.Mock(side_effect=check_capture_thread)
+ monkeypatch.setattr("posthoganalytics.capture", capture)
+ monkeypatch.setattr("posthog.tasks.usage_report.ph_scoped_capture", lambda **kw: nullcontext(capture))
+ scan = mock.Mock(
+ return_value=[
+ (team_a1.id, org_a.id, "workflow_emails_sent", "invocations", 7),
+ (team_a2.id, org_a.id, "workflow_emails_sent", "invocations", 9),
+ (idle_team.id, idle_org.id, "workflow_emails_sent", "invocations", 4),
+ (987654, deleted_org_id, "workflow_emails_sent", "invocations", 6),
+ (987655, excluded_org_id, "workflow_emails_sent", "invocations", 23),
+ ]
+ )
+ monkeypatch.setattr("posthog.tasks.usage_report.sync_execute", scan)
monkeypatch.setattr("posthog.tasks.usage_report.get_ph_client", lambda *a, **kw: mock.MagicMock())
# Skip the heavy gather queries — both paths use this same `seeded`
# dict, just shaped differently for each entry point.
monkeypatch.setattr(
"posthog.tasks.usage_report._get_all_usage_data_as_team_rows",
- lambda *a, **kw: seeded,
+ lambda begin, end, counter_report: {
+ **seeded,
+ **{field: dict(rows) for field, rows in counter_report.counts.items()},
+ },
)
+ for counter, query_name in (
+ (UsageCounter.ROWS_SYNCED, "get_teams_with_rows_synced_in_period"),
+ (UsageCounter.FREE_HISTORICAL_ROWS_SYNCED, "get_teams_with_free_historical_rows_synced_in_period"),
+ (UsageCounter.ROWS_EXPORTED, "get_teams_with_rows_exported_in_period"),
+ ):
+ monkeypatch.setattr(
+ usage_report,
+ query_name,
+ mock.Mock(
+ return_value=[{"team_id": team_id, "total": total} for team_id, total in seeded[counter].items()]
+ ),
+ )
+ for counter, query_name in (
+ (UsageCounter.LOGS_BYTES, "get_teams_with_logs_bytes_in_period"),
+ (UsageCounter.LOGS_RETENTION_BYTE_DAYS, "get_teams_with_logs_retention_byte_days_in_period"),
+ (UsageCounter.AI_CREDITS, "get_teams_with_ai_credits_used_in_period"),
+ (UsageCounter.SIGNALS_CREDITS, "get_teams_with_signals_credits_used_in_period"),
+ (UsageCounter.POSTHOG_CODE_CREDITS, "get_teams_with_posthog_code_credits_used_in_period"),
+ (UsageCounter.REPLAY_VISION_CREDITS, "get_teams_with_replay_vision_credits_used_in_period"),
+ (UsageCounter.EVENTS, "get_teams_with_billable_event_count_in_period"),
+ (UsageCounter.ENHANCED_PERSON_EVENTS, "get_teams_with_billable_enhanced_persons_event_count_in_period"),
+ (UsageCounter.MOBILE_BILLABLE_RECORDINGS, "get_teams_with_mobile_billable_recording_count_in_period"),
+ (UsageCounter.SURVEY_RESPONSES, "get_teams_with_survey_responses_count_in_period"),
+ (UsageCounter.AI_EVENTS, "get_teams_with_ai_event_count_in_period"),
+ (UsageCounter.CDP_INVOCATIONS, "get_teams_with_cdp_billable_invocations_in_period"),
+ (UsageCounter.WORKFLOW_EMAILS, "get_teams_with_workflow_emails_sent_in_period"),
+ (UsageCounter.WORKFLOW_PUSH, "get_teams_with_workflow_push_sent_in_period"),
+ (UsageCounter.WORKFLOW_SMS, "get_teams_with_workflow_sms_sent_in_period"),
+ (UsageCounter.WORKFLOW_INVOCATIONS, "get_teams_with_workflow_billable_invocations_in_period"),
+ ):
+ monkeypatch.setattr(usage_report, query_name, mock.Mock(return_value=list(seeded[counter].items())))
+ monkeypatch.setattr(
+ usage_report,
+ "get_teams_with_recording_count_in_period",
+ lambda begin, end, snapshot_source: list(
+ seeded[UsageCounter.RECORDINGS if snapshot_source == "web" else UsageCounter.MOBILE_RECORDINGS].items()
+ ),
+ )
+ monkeypatch.setattr(
+ usage_report,
+ "get_teams_with_billable_sandbox_compute_usage_in_period",
+ mock.Mock(
+ return_value=SandboxComputeUsageByTeam(
+ credits=list(seeded[UsageCounter.SANDBOX_COMPUTE_CREDITS].items()),
+ cpu_millicore_seconds=list(
+ seeded["teams_with_sandbox_compute_cpu_millicore_seconds_in_period"].items()
+ ),
+ memory_mib_seconds=list(seeded["teams_with_sandbox_compute_memory_mib_seconds_in_period"].items()),
+ )
+ ),
+ )
+ monkeypatch.setattr(
+ usage_report,
+ "get_teams_with_logs_retention_bytes_in_period",
+ mock.Mock(
+ return_value={
+ tier: list(seeded[f"teams_with_logs_retention_{tier}_bytes_in_period"].items())
+ for tier in ("14d", "30d", "90d")
+ }
+ ),
+ )
+ exception_spec = next(spec for spec in QUERIES if spec.name == "exceptions_captured")
+ monkeypatch.setattr(
+ usage_report,
+ "get_teams_with_exceptions_captured_in_period",
+ mock.Mock(
+ return_value=(
+ {
+ library: list(seeded[field].items())
+ for library, field in exception_spec.multi_keys_mapping.items()
+ if library != "total"
+ },
+ list(seeded[UsageCounter.EXCEPTIONS].items()),
+ )
+ ),
+ )
+ monkeypatch.setattr(
+ usage_report,
+ "get_teams_with_feature_flag_requests_count_in_period",
+ lambda begin, end, kind: [
+ (str(team_id), total)
+ for team_id, total in seeded[
+ UsageCounter.FEATURE_FLAG_REQUESTS
+ if kind == usage_report.FlagRequestType.DECIDE
+ else UsageCounter.FEATURE_FLAG_LOCAL_EVALUATION_REQUESTS
+ ].items()
+ ],
+ )
+ monkeypatch.setattr("posthoganalytics.get_feature_flag", mock.Mock(return_value="legacy"))
+
# ---- Celery path ----
- send_all_org_usage_reports(at=celery_at.isoformat(), skip_capture_event=True)
+ send_all_org_usage_reports(at=celery_at.isoformat(), skip_capture_event=True, organization_ids=organization_ids)
celery_per_org = _decode_celery_sqs_messages(sqs_messages)
# ---- Temporal path ----
ctx = WorkflowContext(
run_id="e2e-parity-test",
- workflow_started_at=period.start,
+ workflow_started_at=celery_at,
period_start=period.start,
period_end=period.end,
date_str=period.start.strftime("%Y-%m-%d"),
- organization_ids=None,
+ organization_ids=organization_ids,
+ report_completeness="complete",
)
- query_results = _seed_temporal_query_files(s3, ctx, seeded)
+ ctx.usage_counter_plan = asyncio.run(activity_environment.run(plan_usage_counters, ctx))
+ query_results = [
+ result
+ for result in _seed_temporal_query_files(s3, ctx, seeded)
+ if result.query_name not in ctx.usage_counter_plan.query_names
+ ]
+
+ async def fetch_counters() -> RunQueryToS3Result:
+ assert ctx.usage_counter_plan is not None
+ prepared = []
+ for counter in ctx.usage_counter_plan.legacy_counters:
+ if await activity_environment.run(
+ run_legacy_usage_counter, RunLegacyCounterInputs(ctx=ctx, counter=counter)
+ ):
+ prepared.append(counter)
+ return await activity_environment.run(
+ fetch_usage_counter_report, ctx.model_copy(update={"prepared_legacy_counters": prepared})
+ )
+
+ counter_result = asyncio.run(fetch_counters())
# The activity is async; the test is sync so DB setup can use the
# ORM directly. `asyncio.run` drives the activity in a fresh loop.
result: AggregateResult = asyncio.run(
activity_environment.run(
aggregate_and_chunk_org_reports,
- AggregateInputs(ctx=ctx, query_results=query_results),
+ AggregateInputs(ctx=ctx, query_results=query_results, counter_result=counter_result),
)
)
temporal_per_org = _decode_temporal_chunks(s3, result.chunk_keys)
@@ -243,6 +423,7 @@ def test_end_to_end_parity_celery_task_vs_temporal_activity(
# Both paths skip zero-usage orgs; comparing on the Celery key set
# keeps the assertion focused on the orgs billing actually receives.
+ assert celery_per_org.keys() == temporal_per_org.keys()
for org_id, celery_dict in celery_per_org.items():
assert org_id in temporal_per_org, f"Celery emitted {org_id} but Temporal didn't"
celery_json = json.dumps(celery_dict, sort_keys=True, default=str)
@@ -271,6 +452,42 @@ def test_end_to_end_parity_celery_task_vs_temporal_activity(
assert temporal_per_org[str(org_b.id)]["apm_tracing_bytes_in_period"] == 999_999
assert temporal_per_org[str(org_b.id)]["apm_tracing_spans_in_period"] == 5
assert temporal_per_org[str(org_b.id)]["apm_tracing_mb_in_period"] == 0
+ assert temporal_per_org[str(org_a.id)]["workflow_emails_sent_in_period"] == (
+ 16 if resolved_mode == "realtime" else 24
+ )
+ assert temporal_per_org[str(org_a.id)]["posthog_code_credits_used_in_period"] == 321 + 9
+ assert temporal_per_org[str(org_a.id)]["sandbox_compute_memory_mib_seconds_in_period"] == 2_000
+ assert temporal_per_org[str(org_a.id)]["logs_retention_mb_days_in_period"] == 4
+ assert (str(idle_org.id) in temporal_per_org) == (resolved_mode == "realtime")
+ assert (str(idle_org.id) in celery_per_org) == (resolved_mode == "realtime")
+ assert scan.call_count == (0 if mode == "legacy" else 2)
+ assert captures_on_event_loop == []
+ assert (str(legacy_only_org.id) in temporal_per_org) == (resolved_mode != "realtime")
+ if mode != "legacy":
+ assert temporal_per_org[str(org_a.id)]["counter_comparisons"] == {
+ "workflow_emails_sent_in_period": {"legacy": 24, "realtime": 16}
+ }
+ assert temporal_per_org[str(org_b.id)]["counter_comparisons"] == {
+ "workflow_emails_sent_in_period": {"legacy": 0, "realtime": 0}
+ }
+ assert temporal_per_org[str(org_a.id)]["usage_sources"]["workflow_emails_sent_in_period"] == resolved_mode
+ missing_events = [
+ call.kwargs
+ for call in capture.call_args_list
+ if call.kwargs.get("event") == "usage counter shadow missing organizations"
+ ]
+ assert len(missing_events) == 2
+ assert {event["properties"]["caller"] for event in missing_events} == {"daily_report", "usage_reports_v2"}
+ expected_missing = {deleted_org_id: {"workflow_emails_sent_in_period": {"legacy": 0, "realtime": 6}}}
+ if resolved_mode == "both":
+ expected_missing[str(idle_org.id)] = {"workflow_emails_sent_in_period": {"legacy": 0, "realtime": 4}}
+ else:
+ expected_missing[str(legacy_only_org.id)] = {"workflow_emails_sent_in_period": {"legacy": 5, "realtime": 0}}
+ for event in missing_events:
+ assert event["properties"]["organizations"] == expected_missing
+ else:
+ assert "usage_sources" not in temporal_per_org[str(org_a.id)]
+ assert "counter_comparisons" not in temporal_per_org[str(org_a.id)]
@pytest.mark.django_db(transaction=True)
diff --git a/posthog/temporal/tests/usage_report/test_query_activity.py b/posthog/temporal/tests/usage_report/test_query_activity.py
index 330acceb2123..9649a9a984e9 100644
--- a/posthog/temporal/tests/usage_report/test_query_activity.py
+++ b/posthog/temporal/tests/usage_report/test_query_activity.py
@@ -7,17 +7,395 @@ so we can assert it was *never* called.
"""
import json
-from datetime import datetime
+import asyncio
+import dataclasses
+from concurrent.futures import ThreadPoolExecutor
+from datetime import UTC, datetime
+from functools import partial
+from threading import Event
import pytest
from unittest.mock import patch
+from asgiref.sync import sync_to_async
+from temporalio.testing import ActivityEnvironment
+
from posthog.storage import object_storage
+from posthog.sync import database_sync_to_async_pool
+from posthog.temporal.tests.usage_report.test_parity import _install_in_memory_object_storage
from posthog.temporal.usage_report import storage
-from posthog.temporal.usage_report.activities import run_query_to_s3
+from posthog.temporal.usage_report.activities import (
+ fetch_usage_counter_report,
+ plan_usage_counters,
+ run_legacy_usage_counter,
+ run_query_to_s3,
+)
+from posthog.temporal.usage_report.metrics import USAGE_REPORTS_QUERY_LATENCY
from posthog.temporal.usage_report.queries import QuerySpec
from posthog.temporal.usage_report.storage import queries_key
-from posthog.temporal.usage_report.types import RunQueryToS3Inputs, WorkflowContext
+from posthog.temporal.usage_report.types import (
+ RunLegacyCounterInputs,
+ RunQueryToS3Inputs,
+ RunQueryToS3Result,
+ WorkflowContext,
+)
+from posthog.usage_counters import (
+ UsageCounter,
+ UsageCounterMode,
+ UsageCounterPlan,
+ UsageCounterReport,
+ UsageRecordTotal,
+ UsageRecordTotals,
+)
+from posthog.utils import DayRange
+
+from products.tasks.backend.facade.billing import SandboxComputeUsageByTeam
+
+
+async def _fetch_counter_report(environment: ActivityEnvironment, ctx: WorkflowContext) -> RunQueryToS3Result:
+ if ctx.prepared_legacy_counters is not None:
+ assert ctx.usage_counter_plan is not None
+ prepared = []
+ for counter in ctx.usage_counter_plan.legacy_counters:
+ if await environment.run(run_legacy_usage_counter, RunLegacyCounterInputs(ctx=ctx, counter=counter)):
+ prepared.append(counter)
+ ctx = ctx.model_copy(update={"prepared_legacy_counters": prepared})
+ return await environment.run(fetch_usage_counter_report, ctx)
+
+
[email protected]("activity_name", ["plan", "fetch"])
+async def test_counter_activities_complete_while_shared_executor_is_busy(
+ activity_environment, activity_name: str
+) -> None:
+ period = DayRange(start=datetime(2026, 5, 4, tzinfo=UTC), end=datetime(2026, 5, 5, tzinfo=UTC))
+ plan = UsageCounterPlan(
+ period=period,
+ caller="usage_reports_v2",
+ modes={UsageCounter.EVENTS: UsageCounterMode.LEGACY},
+ complete=True,
+ )
+ ctx = WorkflowContext(
+ run_id="counter-executor-test",
+ workflow_started_at=period.end,
+ period_start=period.start,
+ period_end=period.end,
+ date_str="2026-05-04",
+ usage_counter_plan=plan,
+ )
+ started = asyncio.Event()
+ release = Event()
+ loop = asyncio.get_running_loop()
+
+ def occupy_shared_thread() -> None:
+ loop.call_soon_threadsafe(started.set)
+ release.wait()
+
+ blocker = asyncio.create_task(sync_to_async(occupy_shared_thread)())
+ try:
+ await asyncio.wait_for(started.wait(), timeout=10)
+ with (
+ patch("posthog.temporal.usage_report.activities.UsageCounterService.resolve_plan", return_value=plan),
+ patch(
+ "posthog.temporal.usage_report.activities.UsageCounterService.fetch_report",
+ return_value=UsageCounterReport(counts={UsageCounter.EVENTS: [(1, 17)]}),
+ ),
+ patch("posthog.storage.object_storage.write") as write,
+ ):
+ if activity_name == "plan":
+ assert await asyncio.wait_for(activity_environment.run(plan_usage_counters, ctx), timeout=10) == plan
+ write.assert_not_called()
+ else:
+ result = await asyncio.wait_for(activity_environment.run(fetch_usage_counter_report, ctx), timeout=10)
+ assert write.call_args.args[0] == result.s3_key
+ assert json.loads(write.call_args.args[1])["counts"] == {UsageCounter.EVENTS.value: [[1, 17]]}
+ finally:
+ release.set()
+ await blocker
+
+
+async def test_fetch_usage_counter_report_converts_off_the_event_loop(activity_environment) -> None:
+ period = DayRange(start=datetime(2026, 5, 4, tzinfo=UTC), end=datetime(2026, 5, 5, tzinfo=UTC))
+ ctx = WorkflowContext(
+ run_id="counter-report-test",
+ workflow_started_at=period.end,
+ period_start=period.start,
+ period_end=period.end,
+ date_str="2026-05-04",
+ usage_counter_plan=UsageCounterPlan(
+ period=period,
+ caller="usage_reports_v2",
+ modes={UsageCounter.EVENTS: UsageCounterMode.LEGACY},
+ complete=True,
+ ),
+ )
+ report = UsageCounterReport(counts={UsageCounter.EVENTS: [(1, 7)]})
+ asdict = dataclasses.asdict
+
+ def convert_report(value: UsageCounterReport) -> dict[str, object]:
+ with pytest.raises(RuntimeError, match="no running event loop"):
+ asyncio.get_running_loop()
+ return asdict(value)
+
+ with (
+ patch("posthog.temporal.usage_report.activities.UsageCounterService.fetch_report", return_value=report),
+ patch("posthog.temporal.usage_report.activities.dataclasses.asdict", side_effect=convert_report),
+ patch("posthog.temporal.usage_report.storage.object_storage.write") as write,
+ ):
+ result = await activity_environment.run(fetch_usage_counter_report, ctx)
+
+ assert result.query_name == "usage_counters"
+ assert result.s3_key == queries_key(ctx, "usage_counters")
+ write.assert_called_once()
+ assert write.call_args.args[0] == result.s3_key
+ assert json.loads(write.call_args.args[1]) == {
+ "counts": {UsageCounter.EVENTS.value: [[1, 7]]},
+ "usage_sources": None,
+ "counter_comparisons": None,
+ }
+
+
[email protected]("prepared", [False, True])
+ "mode,failure",
+ [
+ (UsageCounterMode.LEGACY, None),
+ (UsageCounterMode.BOTH, None),
+ (UsageCounterMode.BOTH, "legacy"),
+ (UsageCounterMode.BOTH, "scan"),
+ (UsageCounterMode.REALTIME, "scan"),
+ (UsageCounterMode.REALTIME, "legacy"),
+ (UsageCounterMode.BOTH, "checkpoint"),
+ (UsageCounterMode.REALTIME, "checkpoint"),
+ (UsageCounterMode.BOTH, "write"),
+ ],
+)
+async def test_counter_report_records_query_metrics(
+ activity_environment, monkeypatch, mode: UsageCounterMode, failure: str | None, prepared: bool
+) -> None:
+ _install_in_memory_object_storage(monkeypatch)
+ write_to_storage = object_storage.write
+ period = DayRange(start=datetime(2026, 5, 4, tzinfo=UTC), end=datetime(2026, 5, 5, tzinfo=UTC))
+ ctx = WorkflowContext(
+ run_id="counter-metrics-test",
+ workflow_started_at=period.end,
+ period_start=period.start,
+ period_end=period.end,
+ date_str="2026-05-04",
+ prepared_legacy_counters=[] if prepared else None,
+ usage_counter_plan=UsageCounterPlan(
+ period=period,
+ caller="usage_reports_v2",
+ modes={
+ UsageCounter.CDP_INVOCATIONS: mode,
+ UsageCounter.EXCEPTIONS: UsageCounterMode.LEGACY,
+ UsageCounter.LOGS_RETENTION_30D_BYTES: UsageCounterMode.LEGACY,
+ UsageCounter.SANDBOX_COMPUTE_CREDITS: UsageCounterMode.LEGACY,
+ },
+ complete=True,
+ ),
+ )
+ fails_report = (
+ failure == "write"
+ or (failure in {"legacy", "checkpoint"} and mode != UsageCounterMode.REALTIME)
+ or (failure == "scan" and mode == UsageCounterMode.REALTIME)
+ )
+ with (
+ patch(
+ "posthog.tasks.usage_report.get_teams_with_cdp_billable_invocations_in_period", return_value=[(1, 7)]
+ ) as legacy,
+ patch(
+ "posthog.tasks.usage_report.get_usage_records_in_period",
+ return_value=UsageRecordTotals(
+ totals=[
+ UsageRecordTotal(
+ team_id=1, organization_id="org-a", usage_key="cdp_billable_invocations", quantity=9
+ )
+ ]
+ ),
+ ) as records,
+ patch("posthog.tasks.usage_report.get_teams_with_exceptions_captured_in_period", return_value=({}, [])),
+ patch("posthog.tasks.usage_report.get_teams_with_logs_retention_bytes_in_period", return_value={"30d": []}),
+ patch(
+ "posthog.tasks.usage_report.get_teams_with_billable_sandbox_compute_usage_in_period",
+ return_value=SandboxComputeUsageByTeam(credits=[], cpu_millicore_seconds=[], memory_mib_seconds=[]),
+ ),
+ patch("posthog.temporal.usage_report.storage.object_storage.write", wraps=object_storage.write) as write,
+ patch("posthog.temporal.common.metrics.get_metric_meter") as meter,
+ ):
+ if failure in {"write", "checkpoint"}:
+
+ def fail_write(
+ key: str, content: str | bytes, extras: dict | None = None, bucket: str | None = None
+ ) -> None:
+ failed_query = (
+ "usage_counters" if failure == "write" else f"legacy_{UsageCounter.CDP_INVOCATIONS.value}"
+ )
+ if key == queries_key(ctx, failed_query):
+ raise RuntimeError("unavailable")
+ write_to_storage(key, content, extras=extras, bucket=bucket)
+
+ write.side_effect = fail_write
+ elif failure is not None:
+ {"legacy": legacy, "scan": records}[failure].side_effect = RuntimeError("unavailable")
+ if fails_report:
+ with pytest.raises(RuntimeError, match="unavailable"):
+ await _fetch_counter_report(activity_environment, ctx)
+ else:
+ await _fetch_counter_report(activity_environment, ctx)
+ assert json.loads(write.call_args.args[1])["counts"][UsageCounter.CDP_INVOCATIONS.value] == [
+ [1, 9 if mode == UsageCounterMode.REALTIME else 7]
+ ]
+ legacy.assert_called_once()
+
+ expected = [
+ (UsageCounter.CDP_INVOCATIONS.value, "FAILED" if failure in {"legacy", "checkpoint"} else "COMPLETED"),
+ ]
+ if not (failure in {"legacy", "checkpoint"} and fails_report):
+ expected.extend(
+ (name, "COMPLETED") for name in ("exceptions_captured", "logs_retention_bytes", "sandbox_compute_usage")
+ )
+ if mode != UsageCounterMode.LEGACY and not (failure in {"legacy", "checkpoint"} and fails_report):
+ expected.append(("usage_records", "FAILED" if failure == "scan" else "COMPLETED"))
+ if not (prepared and failure in {"legacy", "checkpoint"} and fails_report):
+ expected.append(("usage_counters", "FAILED" if fails_report else "COMPLETED"))
+ assert [(call.args[0]["query_name"], call.args[0]["status"]) for call in meter.call_args_list] == expected
+ assert [call.args[0]["exception"] for call in meter.call_args_list] == [
+ "RuntimeError" if status == "FAILED" else "" for _, status in expected
+ ]
+ histograms = meter.return_value.create_histogram_timedelta
+ assert [call.kwargs["name"] for call in histograms.call_args_list] == [USAGE_REPORTS_QUERY_LATENCY] * len(expected)
+ assert histograms.return_value.record.call_count == len(expected)
+
+
[email protected]("cancel_during", ["cache_read", "legacy", "checkpoint", "last_checkpoint", "scan"])
[email protected]("cancel_source", ["temporal", "task"])
[email protected]("prepared", [False, True])
+async def test_cancelled_counter_activity_stops_background_work(
+ activity_environment, monkeypatch, cancel_during: str, cancel_source: str, prepared: bool
+) -> None:
+ _install_in_memory_object_storage(monkeypatch)
+ read_from_storage = object_storage.read_bytes
+ write_to_storage = object_storage.write
+ period = DayRange(start=datetime(2026, 5, 4, tzinfo=UTC), end=datetime(2026, 5, 5, tzinfo=UTC))
+ modes = {UsageCounter.CDP_INVOCATIONS: UsageCounterMode.BOTH}
+ if cancel_during != "last_checkpoint":
+ modes[UsageCounter.EVENTS] = UsageCounterMode.LEGACY
+ ctx = WorkflowContext(
+ run_id="counter-cancellation-test",
+ workflow_started_at=period.end,
+ period_start=period.start,
+ period_end=period.end,
+ date_str="2026-05-04",
+ prepared_legacy_counters=[] if prepared else None,
+ usage_counter_plan=UsageCounterPlan(period=period, caller="usage_reports_v2", modes=modes, complete=True),
+ )
+ started = asyncio.Event()
+ release = Event()
+ loop = asyncio.get_running_loop()
+
+ def block(stage: str) -> None:
+ if cancel_during == stage:
+ loop.call_soon_threadsafe(started.set)
+ assert release.wait(timeout=10)
+
+ def read_checkpoint(*args, **kwargs):
+ block("cache_read")
+ return read_from_storage(*args, **kwargs)
+
+ def legacy_query(*args, **kwargs):
+ block("legacy")
+ return [(1, 7)]
+
+ def write_checkpoint(key, *args, **kwargs):
+ if key == queries_key(ctx, f"legacy_{UsageCounter.CDP_INVOCATIONS.value}"):
+ block("checkpoint")
+ block("last_checkpoint")
+ write_to_storage(key, *args, **kwargs)
+
+ def scan_records(*args, **kwargs):
+ block("scan")
+ return UsageRecordTotals(totals=[])
+
+ with (
+ patch(
+ "posthog.tasks.usage_report.get_teams_with_cdp_billable_invocations_in_period",
+ side_effect=legacy_query,
+ ) as legacy,
+ patch("posthog.tasks.usage_report.get_teams_with_billable_event_count_in_period", return_value=[]) as events,
+ patch("posthog.tasks.usage_report.get_usage_records_in_period", side_effect=scan_records) as records,
+ patch("posthog.temporal.usage_report.storage.object_storage.read_bytes", side_effect=read_checkpoint) as read,
+ patch("posthog.temporal.usage_report.storage.object_storage.write", side_effect=write_checkpoint) as write,
+ ):
+ with ThreadPoolExecutor(max_workers=1) as executor:
+ with patch(
+ "posthog.temporal.usage_report.activities.database_sync_to_async_pool",
+ partial(database_sync_to_async_pool, executor=executor),
+ ):
+ task = asyncio.create_task(_fetch_counter_report(activity_environment, ctx))
+ try:
+ await asyncio.wait_for(started.wait(), timeout=10)
+ calls_at_cancellation = [mock.call_count for mock in (read, legacy, events, records, write)]
+ if cancel_source == "temporal":
+ activity_environment.cancel()
+ else:
+ task.cancel()
+ with pytest.raises(asyncio.CancelledError):
+ await task
+ finally:
+ release.set()
+ if not task.done():
+ task.cancel()
+ await asyncio.gather(task, return_exceptions=True)
+
+ assert [mock.call_count for mock in (read, legacy, events, records, write)] == calls_at_cancellation
+ assert all(call.args[0] != queries_key(ctx, "usage_counters") for call in write.call_args_list)
+
+
[email protected]("prepared", [False, True])
+async def test_counter_activity_reuses_successful_queries_on_retry(
+ activity_environment, monkeypatch, prepared: bool
+) -> None:
+ s3 = _install_in_memory_object_storage(monkeypatch)
+ period = DayRange(start=datetime(2026, 5, 4, tzinfo=UTC), end=datetime(2026, 5, 5, tzinfo=UTC))
+ ctx = WorkflowContext(
+ run_id="counter-retry-test",
+ workflow_started_at=period.end,
+ period_start=period.start,
+ period_end=period.end,
+ date_str="2026-05-04",
+ prepared_legacy_counters=[] if prepared else None,
+ usage_counter_plan=UsageCounterPlan(
+ period=period,
+ caller="usage_reports_v2",
+ complete=True,
+ modes={UsageCounter.EVENTS: UsageCounterMode.LEGACY, UsageCounter.EXCEPTIONS: UsageCounterMode.LEGACY},
+ ),
+ )
+ with (
+ patch(
+ "posthog.tasks.usage_report.get_teams_with_billable_event_count_in_period", return_value=[(1, 7)]
+ ) as events,
+ patch(
+ "posthog.tasks.usage_report.get_teams_with_exceptions_captured_in_period",
+ side_effect=[RuntimeError("unavailable"), ({"web": [(1, 3)]}, [(1, 3)])],
+ ) as exceptions,
+ ):
+ with pytest.raises(RuntimeError, match="unavailable"):
+ await _fetch_counter_report(activity_environment, ctx)
+ assert queries_key(ctx, "usage_counters") not in s3
+ result = await _fetch_counter_report(activity_environment, ctx)
+ events.assert_called_once()
+ assert exceptions.call_count == 2
+ assert json.loads(s3[result.s3_key])["counts"] == {
+ UsageCounter.EVENTS.value: [[1, 7]],
+ UsageCounter.EXCEPTIONS.value: [[1, 3]],
+ "teams_with_web_exceptions_captured_in_period": [[1, 3]],
+ }
@pytest.mark.asyncio
diff --git a/posthog/temporal/tests/usage_report/test_workflow.py b/posthog/temporal/tests/usage_report/test_workflow.py
index b055c515b44e..f5ccd8e7e448 100644
--- a/posthog/temporal/tests/usage_report/test_workflow.py
+++ b/posthog/temporal/tests/usage_report/test_workflow.py
@@ -6,34 +6,51 @@ can be verified without standing up real ClickHouse / Postgres / S3.
"""
import uuid
-from datetime import UTC, datetime
+import asyncio
+import logging
+from contextlib import nullcontext
+from datetime import UTC, datetime, timedelta
import pytest
+from unittest.mock import patch
import temporalio.worker
from parameterized import parameterized
-from temporalio import activity
+from temporalio import activity, workflow
from temporalio.client import WorkflowFailureError
from temporalio.contrib.pydantic import pydantic_data_converter
from temporalio.exceptions import ApplicationError
from temporalio.testing import WorkflowEnvironment
-from temporalio.worker import Worker
+from temporalio.worker import Replayer, Worker
+from posthog.temporal.usage_report.activities import plan_usage_counters
from posthog.temporal.usage_report.queries import QUERIES
from posthog.temporal.usage_report.types import (
AggregateInputs,
AggregateResult,
EnqueuePointerInputs,
+ RunLegacyCounterInputs,
RunQueryToS3Inputs,
RunQueryToS3Result,
RunUsageReportsInputs,
+ WorkflowContext,
)
from posthog.temporal.usage_report.workflow import (
+ PARALLEL_COUNTER_QUERIES_PATCH_ID,
+ QUERY_CONCURRENCY,
SANDBOX_COMPUTE_QUERY_NAME,
+ USAGE_COUNTER_SERVICE_PATCH_ID,
RunUsageReportsWorkflow,
_queries_for_sandbox_compute_patch,
build_context,
)
+from posthog.usage_counters import (
+ COUNTER_FLAG_NAMES,
+ LEGACY_QUERY_NAMES,
+ UsageCounter,
+ UsageCounterMode,
+ UsageCounterPlan,
+)
def test_sandbox_compute_query_is_versioned_for_existing_histories() -> None:
@@ -99,11 +116,47 @@ async def test_workflow_rejects_negative_day_offset() -> None:
@pytest.mark.asyncio
-async def test_workflow_runs_query_then_aggregate() -> None:
+ "report_behavior",
+ [
+ "disabled",
+ "enabled",
+ "activity_failure",
+ "query_failure",
+ "flag_failure",
+ "partial",
+ "pre_patch",
+ "pre_patch_query_failure",
+ "concurrency",
+ "serial_counters",
+ "counter_query_failure",
+ ],
+)
+async def test_workflow_runs_query_then_aggregate(report_behavior: str, caplog: pytest.LogCaptureFixture) -> None:
+ caplog.set_level(logging.INFO, logger="temporalio.activity")
+ caplog.set_level(logging.INFO, logger="temporalio.workflow")
seen_query_names: list[str] = []
+ seen_counters: list[UsageCounter] = []
aggregated_with: list[list[str]] = []
aggregate_payloads: list[AggregateInputs] = []
pointer_payloads: list[EnqueuePointerInputs] = []
+ plans: list[UsageCounterPlan] = []
+ counter_contexts: list[WorkflowContext] = []
+ query_started = asyncio.Event()
+ counter_started = asyncio.Event()
+ release_queries = asyncio.Event()
+ starts: asyncio.Queue[str] = asyncio.Queue()
+ releases: dict[str, asyncio.Event] = {}
+ active_queries: set[str] = set()
+ active_counters: set[str] = set()
+ max_active = 0
+ max_active_counters = 0
+ fails = report_behavior in {"activity_failure", "query_failure", "pre_patch_query_failure", "counter_query_failure"}
+ pre_patch = report_behavior.startswith("pre_patch")
+ parallel_counters = not pre_patch and report_behavior != "serial_counters"
+ expected_counter_report = RunQueryToS3Result(
+ query_name="usage_counters", s3_key="queries/counters.json", duration_ms=1
+ )
expected_aggregate = AggregateResult(
chunk_keys=["chunks/chunk_0000.jsonl.gz"],
manifest_key="manifest.json",
@@ -111,9 +164,62 @@ async def test_workflow_runs_query_then_aggregate() -> None:
total_orgs_with_usage=1,
)
+ @activity.defn(name="plan-usage-counters")
+ async def plan_mock(ctx: WorkflowContext) -> UsageCounterPlan:
+ with patch(
+ "posthoganalytics.get_feature_flag", return_value="legacy" if report_behavior == "disabled" else "both"
+ ) as flag:
+ if report_behavior == "flag_failure":
+ flag.side_effect = RuntimeError("flag service unavailable")
+ plan = await plan_usage_counters(ctx)
+ plans.append(plan)
+ return plan
+
+ @activity.defn(name="fetch-usage-counter-report")
+ async def fetch_mock(ctx: WorkflowContext) -> RunQueryToS3Result:
+ counter_contexts.append(ctx)
+ counter_started.set()
+ if report_behavior == "activity_failure":
+ await query_started.wait()
+ raise ApplicationError("unavailable", non_retryable=True)
+ if report_behavior == "query_failure":
+ await release_queries.wait()
+ return expected_counter_report
+
+ async def wait_for_query_release(name: str, *, counter: bool = False) -> None:
+ nonlocal max_active, max_active_counters
+ if report_behavior != "concurrency":
+ return
+ active_queries.add(name)
+ if counter:
+ active_counters.add(name)
+ max_active = max(max_active, len(active_queries))
+ max_active_counters = max(max_active_counters, len(active_counters))
+ releases[name] = asyncio.Event()
+ starts.put_nowait(name)
+ try:
+ await releases[name].wait()
+ finally:
+ active_queries.remove(name)
+ active_counters.discard(name)
+
+ @activity.defn(name="run-legacy-usage-counter")
+ async def legacy_counter_mock(inputs: RunLegacyCounterInputs) -> bool:
+ seen_counters.append(inputs.counter)
+ if report_behavior == "counter_query_failure":
+ raise ApplicationError("counter query unavailable", non_retryable=True)
+ await wait_for_query_release(LEGACY_QUERY_NAMES.get(inputs.counter, inputs.counter.value), counter=True)
+ return True
+
@activity.defn(name="run-usage-report-query")
async def query_mock(inputs: RunQueryToS3Inputs) -> RunQueryToS3Result:
seen_query_names.append(inputs.query_name)
+ query_started.set()
+ await wait_for_query_release(inputs.query_name)
+ if report_behavior in {"activity_failure", "counter_query_failure"} and len(seen_query_names) == 1:
+ await release_queries.wait()
+ if report_behavior in {"query_failure", "pre_patch_query_failure"}:
+ raise ApplicationError("query unavailable", non_retryable=True)
return RunQueryToS3Result(
query_name=inputs.query_name,
s3_key=f"queries/{inputs.query_name}.json",
@@ -137,23 +243,56 @@ async def test_workflow_runs_query_then_aggregate() -> None:
env.client,
task_queue=task_queue,
workflows=[RunUsageReportsWorkflow],
- activities=[query_mock, aggregate_mock, pointer_mock],
+ activities=[query_mock, aggregate_mock, pointer_mock, plan_mock, fetch_mock, legacy_counter_mock],
workflow_runner=temporalio.worker.UnsandboxedWorkflowRunner(),
):
- result = await env.client.execute_workflow(
- RunUsageReportsWorkflow.run,
- RunUsageReportsInputs(day_offset=1),
- id=workflow_id,
- task_queue=task_queue,
- )
+ patched = workflow.patched
+ with (
+ patch(
+ "temporalio.workflow.patched",
+ side_effect=lambda name: (
+ False
+ if (pre_patch and name == USAGE_COUNTER_SERVICE_PATCH_ID)
+ or (report_behavior == "serial_counters" and name == PARALLEL_COUNTER_QUERIES_PATCH_ID)
+ else patched(name)
+ ),
+ )
+ if pre_patch or report_behavior == "serial_counters"
+ else nullcontext()
+ ):
+ try:
+ with pytest.raises(WorkflowFailureError) if fails else nullcontext():
+ run = asyncio.create_task(
+ env.client.execute_workflow(
+ RunUsageReportsWorkflow.run,
+ RunUsageReportsInputs(day_offset=0 if report_behavior == "partial" else 1),
+ id=workflow_id,
+ task_queue=task_queue,
+ execution_timeout=timedelta(minutes=2),
+ ),
+ )
+ if report_behavior == "concurrency":
+ for offset in range(0, len(QUERIES), QUERY_CONCURRENCY):
+ batch = [
+ await asyncio.wait_for(starts.get(), timeout=10)
+ for _ in range(min(QUERY_CONCURRENCY, len(QUERIES) - offset))
+ ]
+ for name in batch:
+ releases[name].set()
+ result = await asyncio.wait_for(run, timeout=30 if fails else 120)
+ finally:
+ release_queries.set()
+ for release in releases.values():
+ release.set()
# Verify the per-query activity scheduling carried `summary=spec.name`
# so the Temporal UI shows which query is running.
handle = env.client.get_workflow_handle(workflow_id)
+ history = await handle.fetch_history()
scheduled_summaries: dict[str, str] = {}
async for event in handle.fetch_history_events():
attrs = event.activity_task_scheduled_event_attributes
- if attrs.activity_type.name != "run-usage-report-query":
+ if attrs.activity_type.name not in {"run-usage-report-query", "run-legacy-usage-counter"}:
continue
assert event.user_metadata.HasField("summary"), f"activity {attrs.activity_id} scheduled without a summary"
(decoded_summary,) = pydantic_data_converter.payload_converter.from_payloads(
@@ -161,12 +300,30 @@ async def test_workflow_runs_query_then_aggregate() -> None:
)
scheduled_summaries[attrs.activity_id] = decoded_summary
- expected_names = [spec.name for spec in QUERIES]
+ counter_names = plans[0].query_names if plans else set()
+ expected_names = [spec.name for spec in QUERIES if spec.name not in counter_names]
+ await Replayer(
+ workflows=[RunUsageReportsWorkflow],
+ data_converter=pydantic_data_converter,
+ workflow_runner=temporalio.worker.UnsandboxedWorkflowRunner(),
+ ).replay_workflow(history)
+ if fails:
+ assert set(seen_query_names) <= set(expected_names)
+ assert aggregated_with == []
+ assert pointer_payloads == []
+ return
+
# Queries run with bounded concurrency, so completion order is not
# deterministic — only assert the set. Result ordering (passed to the
# aggregator) is preserved via `asyncio.gather`.
assert set(seen_query_names) == set(expected_names)
assert len(seen_query_names) == len(expected_names)
+ expected_counters = plans[0].legacy_counters if parallel_counters else []
+ assert set(seen_counters) == set(expected_counters)
+ assert len(seen_counters) == len(expected_counters)
+ if report_behavior == "concurrency":
+ assert max_active == QUERY_CONCURRENCY
+ assert max_active_counters == QUERY_CONCURRENCY
assert len(aggregated_with) == 1
assert aggregated_with[0] == expected_names
@@ -174,10 +331,27 @@ async def test_workflow_runs_query_then_aggregate() -> None:
assert len(pointer_payloads) == 1
assert pointer_payloads[0].ctx == aggregate_payloads[0].ctx
assert pointer_payloads[0].aggregate == expected_aggregate
+ assert len(plans) == (0 if report_behavior == "pre_patch" else 1)
+ assert len(counter_contexts) == (0 if report_behavior == "pre_patch" else 1)
+ assert aggregate_payloads[0].counter_result == (expected_counter_report if report_behavior != "pre_patch" else None)
+ if counter_contexts:
+ assert counter_contexts[0].usage_counter_plan == plans[0]
+ assert counter_contexts[0].prepared_legacy_counters == (plans[0].legacy_counters if parallel_counters else None)
+ expected_mode = (
+ UsageCounterMode.LEGACY if report_behavior in {"disabled", "flag_failure"} else UsageCounterMode.BOTH
+ )
+ assert plans[0].modes == {
+ counter: expected_mode if counter in COUNTER_FLAG_NAMES else UsageCounterMode.LEGACY
+ for counter in UsageCounter
+ }
+ assert aggregate_payloads[0].ctx.usage_counter_plan == (plans[0] if plans else None)
# Each scheduled query activity carries its query name as the Temporal
# `summary`, so the UI surfaces which query is running.
- assert set(scheduled_summaries.values()) == set(expected_names)
- assert len(scheduled_summaries) == len(expected_names)
+ expected_summaries = set(expected_names) | {
+ LEGACY_QUERY_NAMES.get(counter, counter.value) for counter in expected_counters
+ }
+ assert set(scheduled_summaries.values()) == expected_summaries
+ assert len(scheduled_summaries) == len(expected_summaries)
assert result == expected_aggregate.model_dump()
diff --git a/posthog/temporal/usage_report/__init__.py b/posthog/temporal/usage_report/__init__.py
index 6d62adfed358..4095f5d14ad3 100644
--- a/posthog/temporal/usage_report/__init__.py
+++ b/posthog/temporal/usage_report/__init__.py
@@ -2,6 +2,9 @@ from posthog.temporal.usage_report.activities import (
aggregate_and_chunk_org_reports,
cleanup_intermediates,
enqueue_pointer_message,
+ fetch_usage_counter_report,
+ plan_usage_counters,
+ run_legacy_usage_counter,
run_query_to_s3,
)
from posthog.temporal.usage_report.workflow import RunUsageReportsWorkflow
@@ -11,6 +14,9 @@ WORKFLOWS = [
]
ACTIVITIES = [
+ plan_usage_counters,
+ fetch_usage_counter_report,
+ run_legacy_usage_counter,
run_query_to_s3,
aggregate_and_chunk_org_reports,
enqueue_pointer_message,
diff --git a/posthog/temporal/usage_report/activities.py b/posthog/temporal/usage_report/activities.py
index a782c627398e..041ad5398691 100644
--- a/posthog/temporal/usage_report/activities.py
+++ b/posthog/temporal/usage_report/activities.py
@@ -9,7 +9,10 @@ elsewhere so these stay easy to read and mock in tests.
import json
import time
import asyncio
+import dataclasses
+from functools import partial
from itertools import batched
+from threading import Event
from typing import Any
from django.conf import settings
@@ -19,7 +22,7 @@ from asgiref.sync import sync_to_async
from temporalio import activity
from posthog.sync import database_sync_to_async, database_sync_to_async_pool
-from posthog.tasks.usage_report import get_instance_metadata
+from posthog.tasks.usage_report import apply_usage_counter_metadata, get_instance_metadata
from posthog.temporal.common.heartbeat import Heartbeater
from posthog.temporal.common.metrics import ExecutionTimeRecorder
from posthog.temporal.usage_report.aggregator import (
@@ -31,6 +34,7 @@ from posthog.temporal.usage_report.aggregator import (
get_org_user_counts,
iter_chunk_lines,
load_all_data,
+ load_usage_counter_report,
sort_org_reports,
)
from posthog.temporal.usage_report.metrics import (
@@ -47,8 +51,10 @@ from posthog.temporal.usage_report.storage import (
chunk_key,
chunks_prefix,
delete_keys,
+ load_legacy_counter_counts,
manifest_key,
queries_key,
+ run_legacy_counter_query,
write_json,
write_jsonl_chunk_gzip,
)
@@ -57,9 +63,12 @@ from posthog.temporal.usage_report.types import (
AggregateResult,
CleanupInputs,
EnqueuePointerInputs,
+ RunLegacyCounterInputs,
RunQueryToS3Inputs,
RunQueryToS3Result,
+ WorkflowContext,
)
+from posthog.usage_counters import LEGACY_QUERY_NAMES, UsageCounterPlan, UsageCounterReport, UsageCounterService
from posthog.utils import DayRange, get_instance_region
logger = structlog.get_logger(__name__)
@@ -73,6 +82,109 @@ SQS_POINTER_VERSION = 2
SQS_QUEUE_NAME = "usage_reports_v2"
[email protected](name="plan-usage-counters")
+async def plan_usage_counters(ctx: WorkflowContext) -> UsageCounterPlan:
+ return await sync_to_async(UsageCounterService().resolve_plan, thread_sensitive=False)(
+ DayRange(start=ctx.period_start, end=ctx.period_end),
+ caller="usage_reports_v2",
+ complete=ctx.report_completeness == "complete",
+ )
+
+
+def record_query_latency(query_name: str) -> ExecutionTimeRecorder:
+ return ExecutionTimeRecorder(
+ USAGE_REPORTS_QUERY_LATENCY,
+ description="Run a usage-reports query or persist its result to S3.",
+ histogram_attributes={"query_name": query_name},
+ )
+
+
[email protected](name="fetch-usage-counter-report")
+async def fetch_usage_counter_report(ctx: WorkflowContext) -> RunQueryToS3Result:
+ async with Heartbeater():
+ with record_query_latency("usage_counters"):
+ if ctx.usage_counter_plan is None:
+ raise ValueError("Fetching usage counters requires a resolved plan")
+ started = time.monotonic()
+ stopped = Event()
+
+ def check_cancelled() -> None:
+ if stopped.is_set() or activity.is_cancelled():
+ raise asyncio.CancelledError()
+
+ try:
+
+ @database_sync_to_async_pool
+ def fetch_report() -> UsageCounterReport:
+ plan = ctx.usage_counter_plan
+ assert plan is not None
+ legacy_counts = (
+ load_legacy_counter_counts(
+ ctx,
+ (
+ LEGACY_QUERY_NAMES.get(counter, counter.value)
+ for counter in ctx.prepared_legacy_counters
+ ),
+ check_cancelled=check_cancelled,
+ )
+ if ctx.prepared_legacy_counters is not None
+ else None
+ )
+ return UsageCounterService(
+ record_query=record_query_latency,
+ run_legacy_query=partial(run_legacy_counter_query, ctx, check_cancelled=check_cancelled),
+ check_cancelled=check_cancelled,
+ ).fetch_report(
+ DayRange(start=ctx.period_start, end=ctx.period_end), plan=plan, legacy_counts=legacy_counts
+ )
+
+ report = await fetch_report()
+ key = queries_key(ctx, "usage_counters")
+
+ @sync_to_async(thread_sensitive=False)
+ def persist_report() -> None:
+ check_cancelled()
+ payload = dataclasses.asdict(report)
+ check_cancelled()
+ write_json(key, payload)
+
+ await persist_report()
+ return RunQueryToS3Result(
+ query_name="usage_counters",
+ s3_key=key,
+ duration_ms=int((time.monotonic() - started) * 1000),
+ )
+ finally:
+ # Cancelling the await leaves its sync worker running. Stop it between IO operations.
+ stopped.set()
+
+
[email protected](name="run-legacy-usage-counter")
+async def run_legacy_usage_counter(inputs: RunLegacyCounterInputs) -> bool:
+ """Return whether this query produced a checkpoint, including an empty result."""
+ plan = inputs.ctx.usage_counter_plan
+ if plan is None:
+ raise ValueError("Fetching a legacy counter requires a resolved plan")
+ plan = dataclasses.replace(plan, modes={inputs.counter: plan.modes[inputs.counter]})
+ stopped = Event()
+
+ def check_cancelled() -> None:
+ if stopped.is_set() or activity.is_cancelled():
+ raise asyncio.CancelledError()
+
+ async with Heartbeater():
+ try:
+ service = UsageCounterService(
+ record_query=record_query_latency,
+ run_legacy_query=partial(run_legacy_counter_query, inputs.ctx, check_cancelled=check_cancelled),
+ check_cancelled=check_cancelled,
+ )
+ counts = await database_sync_to_async_pool(service.fetch_legacy)(plan)
+ return bool(counts)
+ finally:
+ stopped.set()
+
+
@activity.defn(name="run-usage-report-query")
async def run_query_to_s3(inputs: RunQueryToS3Inputs) -> RunQueryToS3Result:
"""Run one gather query and persist the raw result to S3 as JSON.
@@ -82,11 +194,7 @@ async def run_query_to_s3(inputs: RunQueryToS3Inputs) -> RunQueryToS3Result:
well under Temporal's payload limits).
"""
async with Heartbeater():
- with ExecutionTimeRecorder(
- USAGE_REPORTS_QUERY_LATENCY,
- description="Run one usage-reports gather query and write its result to S3.",
- histogram_attributes={"query_name": inputs.query_name},
- ):
+ with record_query_latency(inputs.query_name):
spec = QUERY_INDEX[inputs.query_name]
# Use the pooled variant so concurrent query activities on the same
@@ -131,6 +239,8 @@ async def aggregate_and_chunk_org_reports(inputs: AggregateInputs) -> AggregateR
):
all_data = await sync_to_async(load_all_data)(inputs.query_results)
add_pre_sandbox_compute_patch_defaults(all_data, inputs.query_results)
+ counter_report = await sync_to_async(load_usage_counter_report)(inputs)
+ all_data.update({field: dict(rows) for field, rows in counter_report.counts.items()})
@database_sync_to_async
def aggregate_per_org() -> dict[str, Any]:
@@ -144,6 +254,14 @@ async def aggregate_and_chunk_org_reports(inputs: AggregateInputs) -> AggregateR
org_reports = await aggregate_per_org()
+ await sync_to_async(apply_usage_counter_metadata)(
+ org_reports,
+ counter_report,
+ caller="usage_reports_v2",
+ date=inputs.ctx.date_str,
+ organization_ids=inputs.ctx.organization_ids,
+ )
+
instance_metadata = await database_sync_to_async(get_instance_metadata)(
DayRange(start=inputs.ctx.period_start, end=inputs.ctx.period_end)
)
diff --git a/posthog/temporal/usage_report/aggregator.py b/posthog/temporal/usage_report/aggregator.py
index 07833d2b1323..331d25bfeb89 100644
--- a/posthog/temporal/usage_report/aggregator.py
+++ b/posthog/temporal/usage_report/aggregator.py
@@ -18,6 +18,8 @@ from typing import Any
from django.conf import settings
from django.db.models import Count
+from pydantic import TypeAdapter
+
from posthog.models import OrganizationMembership, Team
from posthog.tasks.usage_report import (
InstanceMetadata,
@@ -31,7 +33,8 @@ from posthog.tasks.usage_report import (
)
from posthog.temporal.usage_report.queries import QUERY_INDEX
from posthog.temporal.usage_report.storage import bucket, read_json
-from posthog.temporal.usage_report.types import Manifest, RunQueryToS3Result, WorkflowContext
+from posthog.temporal.usage_report.types import AggregateInputs, Manifest, RunQueryToS3Result, WorkflowContext
+from posthog.usage_counters import UsageCounterReport
_SANDBOX_COMPUTE_QUERY_NAME = "sandbox_compute_usage"
_SANDBOX_COMPUTE_DESTINATION_KEYS = (
@@ -41,6 +44,14 @@ _SANDBOX_COMPUTE_DESTINATION_KEYS = (
)
+def load_usage_counter_report(inputs: AggregateInputs) -> UsageCounterReport:
+ if inputs.counter_result is None:
+ if inputs.ctx.usage_counter_plan is not None:
+ raise ValueError("The usage counter report is missing")
+ return UsageCounterReport(counts={})
+ return TypeAdapter(UsageCounterReport).validate_python(read_json(inputs.counter_result.s3_key))
+
+
def load_all_data(query_results: list[RunQueryToS3Result]) -> dict[str, dict[int, int]]:
"""Reconstruct the legacy `all_data` map from per-query S3 files.
diff --git a/posthog/temporal/usage_report/queries.py b/posthog/temporal/usage_report/queries.py
index d1b98ae226d6..9571cdbfdf77 100644
--- a/posthog/temporal/usage_report/queries.py
+++ b/posthog/temporal/usage_report/queries.py
@@ -45,7 +45,6 @@ from typing import Any, Literal
from django.db.models import Count
-from posthog.constants import FlagRequestType
from posthog.models.group_type_mapping import count_group_type_mappings_per_team
from posthog.tasks.usage_report import (
get_all_event_metrics_in_period,
@@ -60,13 +59,11 @@ from posthog.tasks.usage_report import (
get_teams_with_billable_enhanced_persons_event_count_in_period,
get_teams_with_billable_event_count_in_period,
get_teams_with_billable_sandbox_compute_usage_in_period,
- get_teams_with_cdp_billable_invocations_in_period,
get_teams_with_dwh_mat_views_storage_in_s3,
get_teams_with_dwh_tables_storage_in_s3,
get_teams_with_dwh_total_storage_in_s3,
get_teams_with_event_count_with_groups_in_period,
get_teams_with_exceptions_captured_in_period,
- get_teams_with_feature_flag_requests_count_in_period,
get_teams_with_free_historical_rows_synced_in_period,
get_teams_with_heatmap_count_in_period,
get_teams_with_hog_function_calls_in_period,
@@ -89,12 +86,9 @@ from posthog.tasks.usage_report import (
get_teams_with_signals_credits_used_in_period,
get_teams_with_survey_responses_count_in_period,
get_teams_with_task_sandbox_usage_in_period,
- get_teams_with_workflow_billable_invocations_in_period,
- get_teams_with_workflow_emails_sent_in_period,
- get_teams_with_workflow_push_sent_in_period,
- get_teams_with_workflow_sms_sent_in_period,
get_teams_with_zero_duration_recording_count_in_period,
)
+from posthog.usage_counters import UsageCounter, UsageCounterService
from products.dashboards.backend.models.dashboard import Dashboard
from products.error_tracking.backend.facade import api as error_tracking_api
@@ -357,11 +351,11 @@ QUERIES: list[QuerySpec] = [
# ---- ClickHouse: feature flag requests -----------------------------------
QuerySpec(
name="teams_with_decide_requests_count_in_period",
- fn=lambda b, e: get_teams_with_feature_flag_requests_count_in_period(b, e, FlagRequestType.DECIDE),
+ fn=lambda b, e: UsageCounterService().get_legacy(UsageCounter.FEATURE_FLAG_REQUESTS, b, e),
),
QuerySpec(
name="teams_with_local_evaluation_requests_count_in_period",
- fn=lambda b, e: get_teams_with_feature_flag_requests_count_in_period(b, e, FlagRequestType.LOCAL_EVALUATION),
+ fn=lambda b, e: UsageCounterService().get_legacy(UsageCounter.FEATURE_FLAG_LOCAL_EVALUATION_REQUESTS, b, e),
),
# ---- ClickHouse: query metrics -------------------------------------------
QuerySpec(
@@ -484,7 +478,7 @@ QUERIES: list[QuerySpec] = [
),
QuerySpec(
name="teams_with_cdp_billable_invocations_in_period",
- fn=get_teams_with_cdp_billable_invocations_in_period,
+ fn=lambda b, e: UsageCounterService().get_legacy(UsageCounter.CDP_INVOCATIONS, b, e),
),
# ---- ClickHouse: AI ------------------------------------------------------
QuerySpec(
@@ -527,19 +521,19 @@ QUERIES: list[QuerySpec] = [
# ---- ClickHouse: workflows / messaging ----------------------------------
QuerySpec(
name="teams_with_workflow_emails_sent_in_period",
- fn=get_teams_with_workflow_emails_sent_in_period,
+ fn=lambda b, e: UsageCounterService().get_legacy(UsageCounter.WORKFLOW_EMAILS, b, e),
),
QuerySpec(
name="teams_with_workflow_push_sent_in_period",
- fn=get_teams_with_workflow_push_sent_in_period,
+ fn=lambda b, e: UsageCounterService().get_legacy(UsageCounter.WORKFLOW_PUSH, b, e),
),
QuerySpec(
name="teams_with_workflow_sms_sent_in_period",
- fn=get_teams_with_workflow_sms_sent_in_period,
+ fn=lambda b, e: UsageCounterService().get_legacy(UsageCounter.WORKFLOW_SMS, b, e),
),
QuerySpec(
name="teams_with_workflow_billable_invocations_in_period",
- fn=get_teams_with_workflow_billable_invocations_in_period,
+ fn=lambda b, e: UsageCounterService().get_legacy(UsageCounter.WORKFLOW_INVOCATIONS, b, e),
),
# ---- ClickHouse: logs ---------------------------------------------------
QuerySpec(
diff --git a/posthog/temporal/usage_report/storage.py b/posthog/temporal/usage_report/storage.py
index 1b9793f6dcdd..36ca97e5fa72 100644
--- a/posthog/temporal/usage_report/storage.py
+++ b/posthog/temporal/usage_report/storage.py
@@ -11,17 +11,20 @@ configuration.
import io
import gzip
import json
-from collections.abc import Iterable
+from collections.abc import Callable, Iterable
from typing import Any
from django.conf import settings
import structlog
+from pydantic import TypeAdapter
from posthog.storage import object_storage
from posthog.temporal.usage_report.types import WorkflowContext
+from posthog.usage_counters import LegacyCounterQuery, UsageCounterCounts
logger = structlog.get_logger(__name__)
+_COUNTER_COUNTS_ADAPTER = TypeAdapter(UsageCounterCounts)
def bucket() -> str:
@@ -79,6 +82,41 @@ def read_json(key: str) -> Any:
return json.loads(raw)
+def run_legacy_counter_query(
+ ctx: WorkflowContext,
+ query_name: str,
+ query: LegacyCounterQuery,
+ *,
+ check_cancelled: Callable[[], None] | None = None,
+) -> UsageCounterCounts:
+ check_cancelled = check_cancelled or (lambda: None)
+ check_cancelled()
+ key = queries_key(ctx, f"legacy_{query_name}")
+ raw = object_storage.read_bytes(key, bucket=bucket(), missing_ok=True)
+ check_cancelled()
+ if raw is not None:
+ return _COUNTER_COUNTS_ADAPTER.validate_json(raw)
+ result = query()
+ check_cancelled()
+ write_json(key, result)
+ return result
+
+
+def load_legacy_counter_counts(
+ ctx: WorkflowContext, query_names: Iterable[str], *, check_cancelled: Callable[[], None]
+) -> UsageCounterCounts:
+ counts: UsageCounterCounts = {}
+ for name in query_names:
+ check_cancelled()
+ key = queries_key(ctx, f"legacy_{name}")
+ raw = object_storage.read_bytes(key, bucket=bucket())
+ check_cancelled()
+ if raw is None:
+ raise FileNotFoundError(f"Legacy counter checkpoint not found: {key}")
+ counts.update(_COUNTER_COUNTS_ADAPTER.validate_json(raw))
+ return counts
+
+
def write_jsonl_chunk_gzip(key: str, lines: Iterable[dict[str, Any]]) -> int:
"""Stream-encode `lines` as JSONL straight into gzip, then PUT the
compressed body to S3 in a single `put_object` call.
diff --git a/posthog/temporal/usage_report/types.py b/posthog/temporal/usage_report/types.py
index fce4a1648180..45ab3c2229ed 100644
--- a/posthog/temporal/usage_report/types.py
+++ b/posthog/temporal/usage_report/types.py
@@ -10,6 +10,8 @@ from typing import Literal, Optional
from pydantic import BaseModel
+from posthog.usage_counters import UsageCounter, UsageCounterPlan
+
# What billing reads off the pointer/manifest: "partial" = intraday snapshot
# of a day still in progress, "complete" = the day was already over when
# queried (finalizer or backfill run), so the numbers are final for that date.
@@ -41,6 +43,13 @@ class WorkflowContext(BaseModel):
date_str: str
report_completeness: ReportCompleteness = "partial"
organization_ids: Optional[list[str]] = None
+ usage_counter_plan: UsageCounterPlan | None = None
+ prepared_legacy_counters: list[UsageCounter] | None = None
+
+
+class RunLegacyCounterInputs(BaseModel):
+ ctx: WorkflowContext
+ counter: UsageCounter
class RunQueryToS3Inputs(BaseModel):
@@ -57,6 +66,7 @@ class RunQueryToS3Result(BaseModel):
class AggregateInputs(BaseModel):
ctx: WorkflowContext
query_results: list[RunQueryToS3Result]
+ counter_result: RunQueryToS3Result | None = None
class Manifest(BaseModel):
diff --git a/posthog/temporal/usage_report/workflow.py b/posthog/temporal/usage_report/workflow.py
index 7be556e49e8c..24d93714a4f4 100644
--- a/posthog/temporal/usage_report/workflow.py
+++ b/posthog/temporal/usage_report/workflow.py
@@ -26,25 +26,32 @@ from posthog.temporal.common.base import PostHogWorkflow
from posthog.temporal.usage_report.activities import (
aggregate_and_chunk_org_reports,
enqueue_pointer_message,
+ fetch_usage_counter_report,
+ plan_usage_counters,
+ run_legacy_usage_counter,
run_query_to_s3,
)
from posthog.temporal.usage_report.metrics import get_workflow_finished_metric, record_workflow_latency
-from posthog.temporal.usage_report.queries import QUERIES, QuerySpec
+from posthog.temporal.usage_report.queries import QUERIES, QUERY_INDEX, QuerySpec
from posthog.temporal.usage_report.storage import run_prefix
from posthog.temporal.usage_report.types import (
AggregateInputs,
EnqueuePointerInputs,
+ RunLegacyCounterInputs,
RunQueryToS3Inputs,
RunQueryToS3Result,
RunUsageReportsInputs,
WorkflowContext,
)
+from posthog.usage_counters import LEGACY_QUERY_NAMES, UsageCounter
# Cap concurrent gather queries so we don't overwhelm ClickHouse / Postgres
# with ~40 simultaneous heavy queries.
QUERY_CONCURRENCY = 4
SANDBOX_COMPUTE_QUERY_PATCH_ID = "usage-report-sandbox-compute-query-2026-08"
SANDBOX_COMPUTE_QUERY_NAME = "sandbox_compute_usage"
+USAGE_COUNTER_SERVICE_PATCH_ID = "usage-report-counter-service-2026-09"
+PARALLEL_COUNTER_QUERIES_PATCH_ID = "usage-report-parallel-counter-queries-2026-10"
def _queries_for_sandbox_compute_patch(patch_applied: bool) -> list[QuerySpec]:
@@ -99,6 +106,15 @@ class RunUsageReportsWorkflow(PostHogWorkflow):
try:
ctx = build_context(inputs, run_id=workflow.info().run_id, now=started_at)
queries = _queries_for_sandbox_compute_patch(workflow.patched(SANDBOX_COMPUTE_QUERY_PATCH_ID))
+ if workflow.patched(USAGE_COUNTER_SERVICE_PATCH_ID):
+ ctx.usage_counter_plan = await workflow.execute_activity(
+ plan_usage_counters,
+ ctx,
+ start_to_close_timeout=timedelta(minutes=1),
+ retry_policy=common.RetryPolicy(maximum_attempts=3),
+ )
+ counter_names = ctx.usage_counter_plan.query_names
+ queries = [spec for spec in queries if spec.name not in counter_names]
workflow.logger.info(
"Starting usage reports workflow",
extra={
@@ -116,18 +132,33 @@ class RunUsageReportsWorkflow(PostHogWorkflow):
# but a small batch shortens wall-clock substantially without
# overwhelming the databases.
sem = asyncio.Semaphore(QUERY_CONCURRENCY)
+ counter_task = (
+ asyncio.create_task(self._fetch_counter_report(ctx, sem))
+ if ctx.usage_counter_plan is not None
+ else None
+ )
async def _run_with_sem(spec: QuerySpec) -> RunQueryToS3Result:
async with sem:
return await self._run_query(ctx, spec)
- query_results: list[RunQueryToS3Result] = list(
- await asyncio.gather(*(_run_with_sem(spec) for spec in queries))
- )
+ tasks = [asyncio.create_task(_run_with_sem(spec)) for spec in queries]
+ if counter_task is not None:
+ tasks.append(counter_task)
+ try:
+ results = await asyncio.gather(*tasks)
+ finally:
+ # Histories without the counter-service patch do not include these cancellation commands.
+ if counter_task is not None:
+ for task in tasks:
+ if not task.done():
+ task.cancel()
+ query_results = results[: len(queries)]
+ counter_result = results[-1] if counter_task is not None else None
agg = await workflow.execute_activity(
aggregate_and_chunk_org_reports,
- AggregateInputs(ctx=ctx, query_results=query_results),
+ AggregateInputs(ctx=ctx, query_results=query_results, counter_result=counter_result),
start_to_close_timeout=timedelta(minutes=60),
retry_policy=common.RetryPolicy(
maximum_attempts=2,
@@ -189,6 +220,46 @@ class RunUsageReportsWorkflow(PostHogWorkflow):
except Exception:
workflow.logger.warning("Failed to record usage-reports workflow metrics", exc_info=True)
+ async def _fetch_counter_report(self, ctx: WorkflowContext, sem: asyncio.Semaphore) -> RunQueryToS3Result:
+ if workflow.patched(PARALLEL_COUNTER_QUERIES_PATCH_ID):
+ assert ctx.usage_counter_plan is not None
+ tasks = [
+ asyncio.create_task(self._run_legacy_counter(ctx, counter, sem))
+ for counter in ctx.usage_counter_plan.legacy_counters
+ ]
+ try:
+ prepared = await asyncio.gather(*tasks)
+ finally:
+ for task in tasks:
+ if not task.done():
+ task.cancel()
+ ctx = ctx.model_copy(
+ update={"prepared_legacy_counters": [counter for counter in prepared if counter is not None]}
+ )
+ async with sem:
+ return await workflow.execute_activity(
+ fetch_usage_counter_report,
+ ctx,
+ start_to_close_timeout=timedelta(minutes=120),
+ retry_policy=common.RetryPolicy(maximum_attempts=3, initial_interval=timedelta(seconds=30)),
+ heartbeat_timeout=timedelta(minutes=2),
+ )
+
+ async def _run_legacy_counter(
+ self, ctx: WorkflowContext, counter: UsageCounter, sem: asyncio.Semaphore
+ ) -> UsageCounter | None:
+ name = LEGACY_QUERY_NAMES.get(counter, counter.value)
+ async with sem:
+ prepared = await workflow.execute_activity(
+ run_legacy_usage_counter,
+ RunLegacyCounterInputs(ctx=ctx, counter=counter),
+ start_to_close_timeout=timedelta(minutes=QUERY_INDEX[name].timeout_minutes),
+ retry_policy=common.RetryPolicy(maximum_attempts=3, initial_interval=timedelta(seconds=10)),
+ heartbeat_timeout=timedelta(minutes=1),
+ summary=name,
+ )
+ return counter if prepared else None
+
async def _run_query(self, ctx: WorkflowContext, spec: QuerySpec) -> RunQueryToS3Result:
return await workflow.execute_activity(
run_query_to_s3,
diff --git a/posthog/usage_counters.py b/posthog/usage_counters.py
new file mode 100644
index 000000000000..9a3a9e9f13db
--- /dev/null
+++ b/posthog/usage_counters.py
@@ -0,0 +1,534 @@
+import time
+from collections.abc import Callable, Collection
+from contextlib import AbstractContextManager, nullcontext
+from dataclasses import field
+from datetime import UTC, datetime, timedelta
+from enum import StrEnum
+from functools import partial
+from threading import RLock
+from typing import Literal, TypedDict
+
+from django.conf import settings
+
+import structlog
+import posthoganalytics
+from cachetools import TTLCache, cached
+from prometheus_client import Counter, Gauge
+
+from posthog.dataclasses import frozen
+from posthog.utils import DayRange
+
+logger = structlog.get_logger(__name__)
+
+SHADOW_FAILURES = Counter("usage_counter_shadow_failures_total", "Usage counter shadow failures", ["caller", "stage"])
+SHADOW_MISSING_ORGS = Gauge(
+ "usage_counter_shadow_missing_organizations", "Organizations with shadow usage but no report", ["caller"]
+)
+REALTIME_BLOCKED = Counter(
+ "usage_counter_realtime_blocked_total",
+ "Realtime mode requests resolved to both for a producer discrepancy",
+ ["counter"],
+)
+
+
+class UsageCounter(StrEnum):
+ EVENTS = "teams_with_event_count_in_period"
+ ENHANCED_PERSON_EVENTS = "teams_with_enhanced_persons_event_count_in_period"
+ RECORDINGS = "teams_with_recording_count_in_period"
+ MOBILE_RECORDINGS = "teams_with_mobile_recording_count_in_period"
+ MOBILE_BILLABLE_RECORDINGS = "teams_with_mobile_billable_recording_count_in_period"
+ SURVEY_RESPONSES = "teams_with_survey_responses_count_in_period"
+ AI_EVENTS = "teams_with_ai_event_count_in_period"
+ EXCEPTIONS = "teams_with_exceptions_captured_in_period"
+ CDP_INVOCATIONS = "teams_with_cdp_billable_invocations_in_period"
+ FEATURE_FLAG_REQUESTS = "teams_with_decide_requests_count_in_period"
+ FEATURE_FLAG_LOCAL_EVALUATION_REQUESTS = "teams_with_local_evaluation_requests_count_in_period"
+ WORKFLOW_EMAILS = "teams_with_workflow_emails_sent_in_period"
+ WORKFLOW_PUSH = "teams_with_workflow_push_sent_in_period"
+ WORKFLOW_SMS = "teams_with_workflow_sms_sent_in_period"
+ WORKFLOW_INVOCATIONS = "teams_with_workflow_billable_invocations_in_period"
+ ROWS_SYNCED = "teams_with_rows_synced_in_period"
+ FREE_HISTORICAL_ROWS_SYNCED = "teams_with_free_historical_rows_synced_in_period"
+ ROWS_EXPORTED = "teams_with_rows_exported_in_period"
+ LOGS_BYTES = "teams_with_logs_bytes_in_period"
+ LOGS_RETENTION_30D_BYTES = "teams_with_logs_retention_30d_bytes_in_period"
+ LOGS_RETENTION_BYTE_DAYS = "teams_with_logs_retention_byte_days_in_period"
+ AI_CREDITS = "teams_with_ai_credits_used_in_period"
+ SIGNALS_CREDITS = "teams_with_signals_credits_used_in_period"
+ POSTHOG_CODE_CREDITS = "teams_with_posthog_code_credits_used_in_period"
+ SANDBOX_COMPUTE_CREDITS = "teams_with_sandbox_compute_credits_used_in_period"
+ REPLAY_VISION_CREDITS = "teams_with_replay_vision_credits_used_in_period"
+
+
+UsageCounterQuery = Callable[[datetime, datetime], list[tuple[int, int]]]
+UsageCounterCounts = dict[str, list[tuple[int, int]]]
+LegacyCounterQuery = Callable[[], UsageCounterCounts]
+LegacyCounterRunner = Callable[[str, LegacyCounterQuery], UsageCounterCounts]
+LEGACY_QUERY_NAMES = {
+ UsageCounter.EXCEPTIONS: "exceptions_captured",
+ UsageCounter.LOGS_RETENTION_30D_BYTES: "logs_retention_bytes",
+ UsageCounter.SANDBOX_COMPUTE_CREDITS: "sandbox_compute_usage",
+}
+
+
+class UsageCounterMode(StrEnum):
+ LEGACY = "legacy"
+ BOTH = "both"
+ REALTIME = "realtime"
+
+
+UsageCounterCaller = Literal["daily_report", "usage_reports_v2", "quota_limiting"]
+
+
+@frozen
+class UsageRecordTotal:
+ team_id: int
+ organization_id: str
+ usage_key: str
+ quantity: int
+
+
+@frozen
+class UsageRecordTotals:
+ totals: list[UsageRecordTotal]
+ errors: dict[str, str] = field(default_factory=dict)
+
+
+RECORD_USAGE_KEYS = {
+ UsageCounter.EVENTS: "events",
+ UsageCounter.ENHANCED_PERSON_EVENTS: "enhanced_person_events",
+ UsageCounter.RECORDINGS: "session_replay_recordings",
+ UsageCounter.MOBILE_RECORDINGS: "mobile_replay_recordings",
+ UsageCounter.MOBILE_BILLABLE_RECORDINGS: "mobile_replay_recordings",
+ UsageCounter.SURVEY_RESPONSES: "survey_responses",
+ UsageCounter.AI_EVENTS: "ai_events",
+ UsageCounter.EXCEPTIONS: "exceptions",
+ UsageCounter.CDP_INVOCATIONS: "cdp_billable_invocations",
+ UsageCounter.FEATURE_FLAG_REQUESTS: "feature_flag_requests",
+ UsageCounter.FEATURE_FLAG_LOCAL_EVALUATION_REQUESTS: "feature_flag_local_evaluation_requests",
+ UsageCounter.WORKFLOW_EMAILS: "workflow_emails_sent",
+ UsageCounter.WORKFLOW_PUSH: "workflow_push_sent",
+ UsageCounter.WORKFLOW_SMS: "workflow_sms_sent",
+ UsageCounter.WORKFLOW_INVOCATIONS: "workflow_billable_invocations",
+}
+RECORD_USAGE_UNITS = {
+ "events": "events",
+ "enhanced_person_events": "events",
+ "session_replay_recordings": "recordings",
+ "mobile_replay_recordings": "recordings",
+ "survey_responses": "events",
+ "ai_events": "events",
+ "exceptions": "events",
+ "cdp_billable_invocations": "invocations",
+ "feature_flag_requests": "requests",
+ "feature_flag_local_evaluation_requests": "requests",
+ "workflow_emails_sent": "invocations",
+ "workflow_push_sent": "invocations",
+ "workflow_sms_sent": "invocations",
+ "workflow_billable_invocations": "invocations",
+}
+COUNTER_FLAG_NAMES = {
+ UsageCounter.EVENTS: "events",
+ UsageCounter.ENHANCED_PERSON_EVENTS: "enhanced-persons",
+ UsageCounter.RECORDINGS: "recordings",
+ UsageCounter.MOBILE_RECORDINGS: "mobile-recordings",
+ UsageCounter.MOBILE_BILLABLE_RECORDINGS: "mobile-billable-recordings",
+ UsageCounter.SURVEY_RESPONSES: "survey-responses",
+ UsageCounter.AI_EVENTS: "ai-events",
+ UsageCounter.EXCEPTIONS: "exceptions",
+ UsageCounter.CDP_INVOCATIONS: "cdp-invocations",
+ UsageCounter.FEATURE_FLAG_REQUESTS: "feature-flag-requests",
+ UsageCounter.FEATURE_FLAG_LOCAL_EVALUATION_REQUESTS: "feature-flag-local-evaluation-requests",
+ UsageCounter.WORKFLOW_EMAILS: "workflow-emails",
+ UsageCounter.WORKFLOW_PUSH: "workflow-push",
+ UsageCounter.WORKFLOW_SMS: "workflow-sms",
+ UsageCounter.WORKFLOW_INVOCATIONS: "workflow-invocations",
+}
+_REPLAY_UNDERCOUNT = (
+ "The replay pipeline marks a session as seen before it parses the first message. "
+ "When that message fails, the session writes no usage record, even when later messages record."
+)
+_WORKFLOW_PUSH_UNDERCOUNT = (
+ "The legacy count bills fetch and push dispatches as workflow invocations. "
+ "Push dispatches write `workflow_push_sent` records, so `workflow_billable_invocations` holds only fetches."
+)
+_EVENT_DATE_ATTRIBUTION = (
+ "Event usage records use capture time; legacy queries use source event time. "
+ "A cutover must prevent counting the same event under both dates or omitting it from both."
+)
+_FLAG_REQUEST_DATE_ATTRIBUTION = (
+ "Flag usage records use Rust flush time; legacy billing events use the later Celery export time. "
+ "A cutover must reconcile these dates to avoid missing or double-counting requests."
+)
+_CDP_DATE_ATTRIBUTION = (
+ "CDP and workflow usage records and legacy app metrics use independent flush-time clocks. "
+ "A cutover must reconcile dispatches across those dates to avoid missing or double-counting them."
+)
+_LOCAL_EVALUATION_UNDERCOUNT = (
+ "Django's feature-flag list endpoint counts older SDK requests in Redis but emits no usage records. "
+ "Only the Rust definitions endpoint contributes to the record total."
+)
+# Keep legacy totals authoritative until producer discrepancies are resolved or confirmed as intended billing behavior.
+RECORD_REALTIME_BLOCKERS = {
+ UsageCounter.EVENTS: _EVENT_DATE_ATTRIBUTION,
+ UsageCounter.ENHANCED_PERSON_EVENTS: _EVENT_DATE_ATTRIBUTION,
+ UsageCounter.EXCEPTIONS: _EVENT_DATE_ATTRIBUTION,
+ UsageCounter.CDP_INVOCATIONS: _CDP_DATE_ATTRIBUTION,
+ UsageCounter.RECORDINGS: _REPLAY_UNDERCOUNT,
+ UsageCounter.MOBILE_RECORDINGS: _REPLAY_UNDERCOUNT,
+ UsageCounter.MOBILE_BILLABLE_RECORDINGS: _REPLAY_UNDERCOUNT,
+ UsageCounter.WORKFLOW_EMAILS: _CDP_DATE_ATTRIBUTION,
+ UsageCounter.WORKFLOW_PUSH: _CDP_DATE_ATTRIBUTION,
+ UsageCounter.WORKFLOW_SMS: _CDP_DATE_ATTRIBUTION,
+ UsageCounter.WORKFLOW_INVOCATIONS: f"{_WORKFLOW_PUSH_UNDERCOUNT} {_CDP_DATE_ATTRIBUTION}",
+ UsageCounter.FEATURE_FLAG_REQUESTS: _FLAG_REQUEST_DATE_ATTRIBUTION,
+ UsageCounter.FEATURE_FLAG_LOCAL_EVALUATION_REQUESTS: _LOCAL_EVALUATION_UNDERCOUNT,
+ UsageCounter.SURVEY_RESPONSES: "Survey usage records include product-tour responses that legacy billing exempts.",
+ UsageCounter.AI_EVENTS: "AI usage records omit the legacy exemptions for wallet-billed gateway and sponsored relay events.",
+}
+
+
+def validate_usage_record_window(period: DayRange) -> None:
+ if period.start.tzinfo is None or period.end.tzinfo is None:
+ raise ValueError("Usage record windows must be timezone-aware")
+ start = period.start.astimezone(UTC)
+ end = period.end.astimezone(UTC)
+ next_midnight = start.replace(hour=0, minute=0, second=0, microsecond=0) + timedelta(days=1)
+ if end <= start or end > next_midnight:
+ raise ValueError("Usage record windows must stay within one UTC day")
+
+
+@frozen
+class UsageCounterPlan:
+ period: DayRange
+ caller: UsageCounterCaller
+ modes: dict[UsageCounter, UsageCounterMode]
+ # True when the period is a past day. Temporal decodes a plan without this field as a partial day.
+ complete: bool = False
+
+ def __post_init__(self) -> None:
+ validate_usage_record_window(self.period)
+
+ @property
+ def query_names(self) -> set[str]:
+ return {LEGACY_QUERY_NAMES.get(counter, counter.value) for counter in self.modes}
+
+ @property
+ def legacy_counters(self) -> list[UsageCounter]:
+ # Realtime counters only need legacy queries for complete-day comparisons or report breakdowns.
+ return [
+ counter
+ for counter, mode in self.modes.items()
+ if mode != UsageCounterMode.REALTIME
+ or self.complete
+ or (
+ counter in LEGACY_QUERY_NAMES
+ and not (counter == UsageCounter.EXCEPTIONS and self.caller == "quota_limiting")
+ )
+ ]
+
+
+@frozen
+class UsageCounterComparisonRows:
+ legacy_by_team: dict[int, int]
+ realtime_by_team: dict[int, dict[str, int]]
+
+
+class UsageCounterComparison(TypedDict):
+ legacy: int
+ realtime: int
+
+
+@frozen
+class UsageCounterReport:
+ counts: dict[str, list[tuple[int, int]]]
+ usage_sources: dict[str, UsageCounterMode] | None = None
+ # A missing counter means its comparison failed or did not run; empty totals mean a successful zero.
+ counter_comparisons: dict[str, UsageCounterComparisonRows] | None = None
+
+
+def record_shadow_failure(caller: UsageCounterCaller, stage: str) -> None:
+ try:
+ SHADOW_FAILURES.labels(caller=caller, stage=stage).inc()
+ except Exception:
+ logger.exception("usage_counter_shadow_metric_failed", caller=caller, stage=stage)
+
+
+def log_usage_counter_comparisons(report: UsageCounterReport, *, caller: UsageCounterCaller, date: str) -> None:
+ if report.usage_sources is None:
+ return
+ try:
+ logger.info("usage_counter_sources", caller=caller, date=date, usage_sources=report.usage_sources)
+ for counter, rows in (report.counter_comparisons or {}).items():
+ realtime = {team: sum(orgs.values()) for team, orgs in rows.realtime_by_team.items()}
+ differing_teams = 0
+ absolute_difference = 0
+ for team in rows.legacy_by_team.keys() | realtime.keys():
+ difference = abs(rows.legacy_by_team.get(team, 0) - realtime.get(team, 0))
+ differing_teams += int(difference != 0)
+ absolute_difference += difference
+ logger.info(
+ "usage_counter_comparison",
+ caller=caller,
+ date=date,
+ counter=counter,
+ source=report.usage_sources[counter],
+ legacy=sum(rows.legacy_by_team.values()),
+ realtime=sum(realtime.values()),
+ differing_teams=differing_teams,
+ absolute_difference=absolute_difference,
+ )
+ except Exception:
+ logger.exception("usage_counter_comparison_logging_failed", caller=caller, date=date)
+ record_shadow_failure(caller, "diagnostics")
+
+
+_mode_cache: TTLCache[tuple[UsageCounter, str], UsageCounterMode] = TTLCache(
+ maxsize=128, ttl=60, timer=lambda: time.monotonic()
+)
+
+
+@cached(_mode_cache, key=lambda counter, overrides, caller: (counter, overrides), lock=RLock())
+def _resolve_counter_mode(counter: UsageCounter, overrides: str, caller: UsageCounterCaller) -> UsageCounterMode:
+ flag_name = COUNTER_FLAG_NAMES.get(counter)
+ if flag_name is None:
+ return UsageCounterMode.LEGACY
+ override = dict(item.strip().split(":", 1) for item in overrides.split(",") if ":" in item)
+ mode: str | bool | None
+ if flag_name in override:
+ mode = override[flag_name].strip()
+ else:
+ try:
+ mode = posthoganalytics.get_feature_flag(f"usage-counter-realtime-{flag_name}", "internal_billing_events")
+ except Exception:
+ logger.exception("usage_counter_flag_resolution_failed", counter=counter)
+ record_shadow_failure(caller, "flags")
+ return UsageCounterMode.LEGACY
+ if not isinstance(mode, str):
+ return UsageCounterMode.LEGACY
+ try:
+ resolved = UsageCounterMode(mode)
+ except ValueError:
+ return UsageCounterMode.LEGACY
+ if resolved == UsageCounterMode.REALTIME and counter in RECORD_REALTIME_BLOCKERS:
+ logger.warning("usage_counter_realtime_blocked", counter=counter, reason=RECORD_REALTIME_BLOCKERS[counter])
+ REALTIME_BLOCKED.labels(counter=counter.value).inc()
+ return UsageCounterMode.BOTH
+ return resolved
+
+
+def resolve_modes(caller: UsageCounterCaller) -> dict[UsageCounter, UsageCounterMode]:
+ return {
+ counter: _resolve_counter_mode(counter, settings.USAGE_COUNTER_REALTIME_MODES, caller)
+ for counter in UsageCounter
+ }
+
+
+class UsageCounterService:
+ def __init__(
+ self,
+ *,
+ record_query: Callable[[str], AbstractContextManager[object]] | None = None,
+ run_legacy_query: LegacyCounterRunner | None = None,
+ check_cancelled: Callable[[], None] | None = None,
+ ) -> None:
+ # The legacy query module imports this service for report assembly.
+ from posthog.tasks import usage_report
+
+ self._record_query = record_query or (lambda _: nullcontext())
+ self._run_legacy_query = run_legacy_query or (lambda _name, query: query())
+ self._check_cancelled = check_cancelled or (lambda: None)
+ self._queries: dict[UsageCounter, UsageCounterQuery] = {
+ UsageCounter.EVENTS: lambda begin, end: usage_report.get_teams_with_billable_event_count_in_period(
+ begin, end, count_distinct=True
+ ),
+ UsageCounter.ENHANCED_PERSON_EVENTS: lambda begin, end: (
+ usage_report.get_teams_with_billable_enhanced_persons_event_count_in_period(
+ begin, end, count_distinct=True
+ )
+ ),
+ UsageCounter.RECORDINGS: lambda begin, end: usage_report.get_teams_with_recording_count_in_period(
+ begin, end, snapshot_source="web"
+ ),
+ UsageCounter.MOBILE_RECORDINGS: lambda begin, end: usage_report.get_teams_with_recording_count_in_period(
+ begin, end, snapshot_source="mobile"
+ ),
+ UsageCounter.MOBILE_BILLABLE_RECORDINGS: usage_report.get_teams_with_mobile_billable_recording_count_in_period,
+ UsageCounter.SURVEY_RESPONSES: usage_report.get_teams_with_survey_responses_count_in_period,
+ UsageCounter.AI_EVENTS: usage_report.get_teams_with_ai_event_count_in_period,
+ UsageCounter.EXCEPTIONS: lambda begin, end: [
+ (team_id, count) for team_id, count in self._exceptions_query(begin, end)[1]
+ ],
+ UsageCounter.CDP_INVOCATIONS: usage_report.get_teams_with_cdp_billable_invocations_in_period,
+ UsageCounter.FEATURE_FLAG_REQUESTS: lambda begin, end: (
+ usage_report.get_teams_with_feature_flag_requests_count_in_period(
+ begin, end, usage_report.FlagRequestType.DECIDE
+ )
+ ),
+ UsageCounter.FEATURE_FLAG_LOCAL_EVALUATION_REQUESTS: lambda begin, end: (
+ usage_report.get_teams_with_feature_flag_requests_count_in_period(
+ begin, end, usage_report.FlagRequestType.LOCAL_EVALUATION
+ )
+ ),
+ UsageCounter.WORKFLOW_EMAILS: usage_report.get_teams_with_workflow_emails_sent_in_period,
+ UsageCounter.WORKFLOW_PUSH: usage_report.get_teams_with_workflow_push_sent_in_period,
+ UsageCounter.WORKFLOW_SMS: usage_report.get_teams_with_workflow_sms_sent_in_period,
+ UsageCounter.WORKFLOW_INVOCATIONS: usage_report.get_teams_with_workflow_billable_invocations_in_period,
+ UsageCounter.ROWS_SYNCED: usage_report.get_teams_with_rows_synced_in_period,
+ UsageCounter.FREE_HISTORICAL_ROWS_SYNCED: usage_report.get_teams_with_free_historical_rows_synced_in_period,
+ UsageCounter.ROWS_EXPORTED: usage_report.get_teams_with_rows_exported_in_period,
+ UsageCounter.LOGS_BYTES: usage_report.get_teams_with_logs_bytes_in_period,
+ UsageCounter.LOGS_RETENTION_30D_BYTES: lambda begin, end: self._logs_retention_query(begin, end)["30d"],
+ UsageCounter.LOGS_RETENTION_BYTE_DAYS: usage_report.get_teams_with_logs_retention_byte_days_in_period,
+ UsageCounter.AI_CREDITS: usage_report.get_teams_with_ai_credits_used_in_period,
+ UsageCounter.SIGNALS_CREDITS: usage_report.get_teams_with_signals_credits_used_in_period,
+ UsageCounter.POSTHOG_CODE_CREDITS: usage_report.get_teams_with_posthog_code_credits_used_in_period,
+ UsageCounter.SANDBOX_COMPUTE_CREDITS: lambda begin, end: self._sandbox_compute_query(begin, end).credits,
+ UsageCounter.REPLAY_VISION_CREDITS: usage_report.get_teams_with_replay_vision_credits_used_in_period,
+ }
+ self._quota_events_query = usage_report.get_teams_with_billable_event_count_in_period
+ self._exceptions_query = usage_report.get_teams_with_exceptions_captured_in_period
+ self._logs_retention_query = usage_report.get_teams_with_logs_retention_bytes_in_period
+ self._sandbox_compute_query = usage_report.get_teams_with_billable_sandbox_compute_usage_in_period
+ self._records_query = usage_report.get_usage_records_in_period
+ self._team_counts = usage_report.convert_team_usage_rows_to_dict
+
+ def resolve_plan(
+ self,
+ period: DayRange,
+ *,
+ caller: UsageCounterCaller,
+ complete: bool,
+ counters: Collection[UsageCounter] | None = None,
+ ) -> UsageCounterPlan:
+ modes = resolve_modes(caller)
+ return UsageCounterPlan(
+ period=period,
+ caller=caller,
+ modes={counter: mode for counter, mode in modes.items() if counters is None or counter in counters},
+ complete=complete,
+ )
+
+ def get_legacy(
+ self, counter: UsageCounter, begin: datetime, end: datetime, *, caller: UsageCounterCaller = "daily_report"
+ ) -> list[tuple[int, int]]: # nosemgrep: tuple-return-prefer-dataclass -- Legacy query contract: (team_id, count).
+ if caller == "quota_limiting" and counter == UsageCounter.EVENTS:
+ rows = self._quota_events_query(begin, end, count_distinct=False)
+ else:
+ rows = self._queries[counter](begin, end)
+ # Flag readers return string team IDs, and the rows synced and exported readers return dictionaries.
+ return list(self._team_counts(rows).items())
+
+ def _fetch_legacy_counter(self, counter: UsageCounter, plan: UsageCounterPlan) -> UsageCounterCounts:
+ if counter == UsageCounter.EXCEPTIONS and plan.caller != "quota_limiting":
+ # The records have no library breakdown, which reports still need after the total switches.
+ libraries, totals = self._exceptions_query(plan.period.start, plan.period.end)
+ return {
+ counter.value: [(team_id, count) for team_id, count in totals],
+ **{
+ f"teams_with_{'js_lite' if library == 'web_lite' else library}_exceptions_captured_in_period": [
+ (team_id, count) for team_id, count in rows
+ ]
+ for library, rows in libraries.items()
+ },
+ }
+ if counter == UsageCounter.LOGS_RETENTION_30D_BYTES:
+ retention = self._logs_retention_query(plan.period.start, plan.period.end)
+ return {f"teams_with_logs_retention_{tier}_bytes_in_period": rows for tier, rows in retention.items()}
+ if counter == UsageCounter.SANDBOX_COMPUTE_CREDITS:
+ sandbox_compute = self._sandbox_compute_query(plan.period.start, plan.period.end)
+ return {
+ counter.value: sandbox_compute.credits,
+ "teams_with_sandbox_compute_cpu_millicore_seconds_in_period": sandbox_compute.cpu_millicore_seconds,
+ "teams_with_sandbox_compute_memory_mib_seconds_in_period": sandbox_compute.memory_mib_seconds,
+ }
+ return {counter.value: self.get_legacy(counter, plan.period.start, plan.period.end, caller=plan.caller)}
+
+ def fetch_legacy(self, plan: UsageCounterPlan) -> UsageCounterCounts:
+ counts: UsageCounterCounts = {}
+ for counter in plan.legacy_counters:
+ mode = plan.modes[counter]
+ requires_breakdown = counter in LEGACY_QUERY_NAMES and not (
+ counter == UsageCounter.EXCEPTIONS and plan.caller == "quota_limiting"
+ )
+ self._check_cancelled()
+ try:
+ with self._record_query(LEGACY_QUERY_NAMES.get(counter, counter.value)):
+ counts.update(
+ self._run_legacy_query(
+ LEGACY_QUERY_NAMES.get(counter, counter.value),
+ partial(self._fetch_legacy_counter, counter, plan),
+ )
+ )
+ except Exception:
+ if mode != UsageCounterMode.REALTIME or requires_breakdown:
+ raise
+ logger.exception("usage_counter_legacy_comparison_failed", caller=plan.caller, counter=counter)
+ record_shadow_failure(plan.caller, "legacy_comparison")
+ return counts
+
+ def _fetch_records(self, plan: UsageCounterPlan, record_counters: list[UsageCounter]) -> UsageRecordTotals | None:
+ self._check_cancelled()
+ try:
+ with self._record_query("usage_records"):
+ records = self._records_query(
+ plan.period,
+ tuple(dict.fromkeys(RECORD_USAGE_KEYS[counter] for counter in record_counters)),
+ plan.caller,
+ )
+ self._check_cancelled()
+ except Exception:
+ if UsageCounterMode.REALTIME in plan.modes.values():
+ raise
+ logger.exception("usage_counter_shadow_scan_failed", caller=plan.caller)
+ record_shadow_failure(plan.caller, "scan")
+ return None
+ for counter in record_counters:
+ error = records.errors.get(RECORD_USAGE_KEYS[counter])
+ if error is not None and plan.modes[counter] == UsageCounterMode.REALTIME:
+ raise ValueError(error)
+ for usage_key, error in records.errors.items():
+ logger.error("usage_counter_shadow_validation_failed", caller=plan.caller, usage_key=usage_key, error=error)
+ record_shadow_failure(plan.caller, "validation")
+ return records
+
+ def fetch_report(
+ self,
+ period: DayRange,
+ *,
+ plan: UsageCounterPlan | None = None,
+ legacy_counts: UsageCounterCounts | None = None,
+ ) -> UsageCounterReport:
+ if plan is None:
+ plan = UsageCounterPlan(
+ period=period,
+ caller="daily_report",
+ modes=dict.fromkeys(UsageCounter, UsageCounterMode.LEGACY),
+ complete=True,
+ )
+ if plan.period != period:
+ raise ValueError("A usage counter plan cannot be shared across periods")
+ counts = self.fetch_legacy(plan) if legacy_counts is None else legacy_counts
+ record_counters = [counter for counter, mode in plan.modes.items() if mode != UsageCounterMode.LEGACY]
+ if not record_counters:
+ return UsageCounterReport(counts=counts)
+ sources = {counter.value.removeprefix("teams_with_"): mode for counter, mode in plan.modes.items()}
+ records = self._fetch_records(plan, record_counters)
+ if records is None:
+ return UsageCounterReport(counts=counts, usage_sources=sources)
+ by_team: dict[str, dict[int, dict[str, int]]] = {RECORD_USAGE_KEYS[counter]: {} for counter in record_counters}
+ for row in records.totals:
+ orgs = by_team[row.usage_key].setdefault(row.team_id, {})
+ orgs[row.organization_id] = orgs.get(row.organization_id, 0) + row.quantity
+ comparisons: dict[str, UsageCounterComparisonRows] = {}
+ for counter in record_counters:
+ if RECORD_USAGE_KEYS[counter] in records.errors:
+ continue
+ teams = by_team[RECORD_USAGE_KEYS[counter]]
+ if counter.value in counts:
+ comparisons[counter.value.removeprefix("teams_with_")] = UsageCounterComparisonRows(
+ legacy_by_team=dict(counts[counter.value]), realtime_by_team=teams
+ )
+ if plan.modes[counter] == UsageCounterMode.REALTIME:
+ counts[counter.value] = [(team_id, sum(orgs.values())) for team_id, orgs in teams.items()]
+ return UsageCounterReport(counts=counts, usage_sources=sources, counter_comparisons=comparisons or None)
diff --git a/products/endpoints/backend/tests/test_endpoint.py b/products/endpoints/backend/tests/test_endpoint.py
index d3f328a89899..4dbfffa21865 100644
--- a/products/endpoints/backend/tests/test_endpoint.py
+++ b/products/endpoints/backend/tests/test_endpoint.py
@@ -50,6 +50,7 @@ class TestEndpoint(ClickhouseTestMixin, APIBaseTest):
)
self.sample_hogql_query = {
"connectionId": None,
+ "executionTarget": None,
"explain": None,
"filters": None,
"kind": "HogQLQuery",
@@ -347,6 +348,7 @@ class TestEndpoint(ClickhouseTestMixin, APIBaseTest):
self.assertFalse(response_data["is_active"])
want_query = {
"connectionId": None,
+ "executionTarget": None,
"explain": None,
"filters": None,
"kind": "HogQLQuery",
diff --git a/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/test_import_data.py b/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/test_import_data.py
index 2ff051c4a1b1..4e1a26f8a9c5 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/test_import_data.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/tests/e2e/test_import_data.py
@@ -177,6 +177,7 @@ async def test_job_inputs_with_whitespace(activity_environment, team, **kwargs):
is_xmin=False,
xmin_cursor=None,
activity_attempt=1,
+ worker_deaths=0,
resumable_source_manager=mock.ANY,
)
@@ -231,6 +232,7 @@ async def test_postgres_source_without_ssh_tunnel(activity_environment, team, **
is_xmin=False,
xmin_cursor=None,
activity_attempt=1,
+ worker_deaths=0,
resumable_source_manager=mock.ANY,
)
@@ -297,6 +299,7 @@ async def test_postgres_source_with_ssh_tunnel_disabled(activity_environment, te
is_xmin=False,
xmin_cursor=None,
activity_attempt=1,
+ worker_deaths=0,
resumable_source_manager=mock.ANY,
)
@@ -378,6 +381,7 @@ async def test_postgres_source_with_ssh_tunnel_enabled(activity_environment, tea
is_xmin=False,
xmin_cursor=None,
activity_attempt=1,
+ worker_deaths=0,
resumable_source_manager=mock.ANY,
)