Repository navigation
fix(telemetry): record development instances only, skip in debug mode - #999
Conversation
Drives TelemetryCollector against a Ktor MockEngine and asserts which instance types reach the wire. Fails on main: development events are dropped and production events are sent with it="PRODUCTION". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The gate was ported from clerk-ios' `guard instanceType == "development"
else { skip }` without the negation, so Android sent telemetry from
production instances and dropped it from development ones. Match
clerk-js: record only when the instance type is "development" and debug
mode is off.
ClerkTelemetryEnvironment reported the enum constant name
("DEVELOPMENT"). Report the serial name ("development") so the `it`
field matches clerk-js and clerk-ios.
The flush() hunk is ktfmt 0.64 reformatting from spotless ratcheting.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: clerk/clerk-android/.coderabbit.yaml Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (5)
Limit details: You’ve used all 4 included reviews currently available. Your 61 included PR review attempts over the past 7 days set your current allowance at 4 reviews per hour. 📝 WalkthroughWalkthroughThe telemetry environment now supplies a serialized instance type. The collector records events only for development instances when debug mode is off. New host tests check these conditions and use a mock HTTP client to inspect flushed events. ChangesTelemetry filtering
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~12 minutes Change: Bug fix Suggested reviewers: Merge Risk: ⚪ Minimal · up to This change fixes telemetry gating so that only development instances with telemetry enabled and debug mode off send events. No actionable merge-blocking risk was identified. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 4 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
Verified on an Android emulatorSetup. Workbench app on a clean Pixel (API 36) emulator, development key for
|
swolfand
left a comment
There was a problem hiding this comment.
The gate logic and the lowercase environment name are correct. Non-blocking: CI doesn't run :source:telemetry tests, so the new TelemetryCollectorTest only runs locally. Worth adding it to the test matrix in a follow-up. The check against "development" is now an exact match, where the old one ignored case. That's fine for the built-in environment, but it matters for any custom TelemetryEnvironment. LGTM.
Summary
TelemetryCollector.shouldRecordskipped events when the instance type was"development"and recorded everything else. So Android sent telemetry from production apps and dropped it from development apps. clerk-js and clerk-ios do the reverse. The gate came from clerk-ios'sguard instanceTypeString() == "development" else { skip }, but the port lost the negation. Its skip reason,"production instance", contradicts the condition it guarded. Mike confirmed the production-only behavior was a bug, not a decision.The gate now matches clerk-js
#shouldRecord. An event passes only when telemetry is enabled, the instance type is"development", and debug mode is off. Sampling and throttling then apply as before. The old code never readisDebugModeEnabled().ClerkTelemetryEnvironment()reportedClerk.instanceEnvironmentType.name, which is"DEVELOPMENT". It now reports the enum's serial name,"development", which is the value clerk-js sends in theitfield.Behavior change. Production apps (
pk_live_keys) stop sending telemetry. Development apps (pk_test_keys) with telemetry enabled and debug mode off start sending it. WithenableDebugMode = truethe SDK sends nothing, which matches clerk-js. clerk-ios still records in debug mode and only adds logging, so on this point Android follows clerk-js rather than clerk-ios.The
flush()hunk only changes formatting. Spotless ratchets fromorigin/mainand reformats every touched file with ktfmt 0.64.Testing
TelemetryCollectorTestruns the realTelemetryCollectoragainst a KtorMockEngineand asserts whichitvalues reach/v1/event. It covers development (sent as"development"), production, unknown, telemetry disabled, and debug mode. Two more cases use the realClerkTelemetryEnvironment()with apk_test_key and apk_live_key. On main, 5 of the 7 tests fail. The live key givesexpected:<[]> but was:<[PRODUCTION]>, and development givesexpected:<[development]> but was:<[]>. With the fix, all 7 pass.skipsWhenDebugModeIsEnabledfailed. So the test does guard that branch../gradlew :source:telemetry:testAndroidHostTest :source:telemetry:spotlessCheck :source:telemetry:detektpasses (9 tests, 0 failures). With this branch merged with fix(ui): share one process-wide TelemetryCollector #1000,:source:ui:testDebugUnitTestalso passes on JDK 21 (506 tests, 0 failures).io.ktor:ktor-client-mock:3.5.2to the version catalog. OnlyandroidHostTestuses it.Overlap with open PRs
ClerkTelemetryEnvironmentTest.kt. This PR leaves that file alone and puts its tests in a newTelemetryCollectorTest.kt.🤖 Generated with Claude Code
Summary by CodeRabbit