Skip to content

feat(usage-report): add per-sdk logs counters for web and ruby#65939

Merged
turnipdabeets merged 2 commits into
masterfrom
usage-report-web-ruby-sdk-logs
Jun 25, 2026
Merged

feat(usage-report): add per-sdk logs counters for web and ruby#65939
turnipdabeets merged 2 commits into
masterfrom
usage-report-web-ruby-sdk-logs

Conversation

@turnipdabeets

Copy link
Copy Markdown
Contributor

Problem

logs_records_in_period in the org usage report has no SDK dimension, and the per-SDK split (get_teams_with_sdk_logs_records_in_period) only matched the mobile SDKs. Web and Ruby log volume was therefore not attributable, even though both SDKs now stamp telemetry.sdk.name on every record:

The previous code comment said web was omitted because posthog-js "doesn't set telemetry.sdk.name yet" — that's no longer true.

Changes

Add web and ruby to the per-SDK logs split, mirroring the existing mobile pattern:

  • SDK_TELEMETRY_NAMES: add "web": "web" and "posthog-ruby": "ruby" (and refresh the stale comment)
  • UsageReportCounters: add web_logs_records_in_period, ruby_logs_records_in_period
  • wire both through _get_all_usage_data and _get_team_report, plus the temporal multi_keys_mapping

The logs_distributed query itself is unchanged — this only widens the telemetry.sdk.name match list and adds the matching counters. (The earlier per-SDK PR was reverted once for querying the wrong table; this change deliberately doesn't touch the query.)

How did you test this code?

I'm an agent (Claude Code, human-directed). Automated only — no manual/product testing claimed.

Extended test_logs_per_sdk_usage_metrics to insert real web and posthog-ruby records into logs_distributed and assert the new counters (web=3, ruby=7), with a posthog-node / no-telemetry.sdk.name record staying uncounted. Ran locally against ClickHouse + Postgres:

  • TestHogFunctionUsageReports::test_logs_per_sdk_usage_metrics — passed
  • full TestHogFunctionUsageReports class — 6 passed

Regression caught: a new SDK that stamps telemetry.sdk.name would silently go uncounted (and a typo'd suffix would KeyError at report assembly) — the assertions on web/ruby counts cover both.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Docs update

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

  • Tool: Claude Code. Companion to feat(rails): stamp telemetry.sdk.name on forwarded logs posthog-ruby#197 (the posthog-rails side that stamps telemetry.sdk.name = "posthog-ruby").
  • Decision: matched on telemetry.sdk.name (consistent with the mobile SDKs and feat(usage-report): re-add per-sdk logs counters via logs_distributed #60706) rather than telemetry.sdk.language / instrumentation_scope. The latter would work retroactively without an SDK release, but diverges from the established per-SDK convention; chose consistency.
  • Scope check: confirmed test_aggregate_activity.py needs no change and the .ambr snapshot doesn't capture the per-SDK logs query, so neither required updates.
  • No new ClickHouse query was added, so no migration/snapshot churn.

@turnipdabeets turnipdabeets self-assigned this Jun 24, 2026
@greptile-apps

greptile-apps Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "feat(usage-report): add per-sdk logs cou..." | Re-trigger Greptile

@turnipdabeets turnipdabeets marked this pull request as ready for review June 24, 2026 22:34
@assign-reviewers-posthog assign-reviewers-posthog Bot requested a review from a team June 24, 2026 22:35
@turnipdabeets turnipdabeets requested a review from a team June 24, 2026 22:35
@turnipdabeets turnipdabeets force-pushed the usage-report-web-ruby-sdk-logs branch from 22ab5d9 to e35ec51 Compare June 24, 2026 22:37
@tests-posthog

tests-posthog Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

⏭️ Skipped snapshot commit because branch advanced to e35ec51 while workflow was testing 22ab5d9.

The new commit will trigger its own snapshot update workflow.

If you expected this workflow to succeed: This can happen due to concurrent commits. To get a fresh workflow run, either:

  • Merge master into your branch, or
  • Push an empty commit: git commit --allow-empty -m 'trigger CI' && git push

@turnipdabeets turnipdabeets force-pushed the usage-report-web-ruby-sdk-logs branch from e35ec51 to 0830994 Compare June 25, 2026 00:05

@pawel-cebula pawel-cebula left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of nit comments, approving it.

Comment thread posthog/temporal/usage_report/queries.py
Comment thread posthog/tasks/usage_report.py

@marandaneto marandaneto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

already some comments from billing otherwise lgtm

posthog-js already stamps telemetry.sdk.name='web' and posthog-rails
stamps 'posthog-ruby' on forwarded log records, so split web and ruby
log volume out of logs_records_in_period the same way the mobile SDKs
are split. Only widens the existing telemetry.sdk.name match list and
adds the matching counters; the logs_distributed query is unchanged.
@turnipdabeets turnipdabeets force-pushed the usage-report-web-ruby-sdk-logs branch from 0830994 to 560cb91 Compare June 25, 2026 14:32
@turnipdabeets turnipdabeets enabled auto-merge (squash) June 25, 2026 14:45
@turnipdabeets turnipdabeets merged commit 21f3951 into master Jun 25, 2026
229 checks passed
@turnipdabeets turnipdabeets deleted the usage-report-web-ruby-sdk-logs branch June 25, 2026 15:16
@deployment-status-posthog

deployment-status-posthog Bot commented Jun 25, 2026

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-06-25 15:58 UTC Run
prod-us ✅ Deployed 2026-06-25 16:20 UTC Run
prod-eu ✅ Deployed 2026-06-25 16:52 UTC Run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants