CLI-727 Telemetry foundation: timed() utility, CliAnalysisFindingDetected types, and findings path constant#497
Conversation
…cted types, and findings path constant
✅ Deploy Preview for sonarqube-cli canceled.
|
| export interface StoredFindingEvent { | ||
| metadata: { | ||
| event_id: string; | ||
| source: { domain: 'CLI' }; | ||
| event_type: 'Analytics.Cli.CliAnalysisFindingDetected'; | ||
| event_timestamp: string; | ||
| }; |
There was a problem hiding this comment.
💡 Quality: event_timestamp format undocumented for finding events
TelemetryEventMetadata.event_timestamp is documented as "Epoch milliseconds as a string" (state.ts:417-418), but the inlined metadata.event_timestamp in the new StoredFindingEvent (state.ts:484-490) has no doc comment specifying the same format. Since CliAnalysisFindingDetected events are sent to the same backend, downstream code in CLI-728 could write an ISO string instead of epoch-ms, causing a silent format divergence between the two event types that the backend may reject or misparse. Add a matching doc comment (and ideally factor out a shared metadata type or event_timestamp semantic) to lock the format in. Note also that StoredFindingEvent.metadata duplicates the shape of TelemetryEventMetadata rather than reusing it; this is acceptable because event_type is a different literal, but documenting the timestamp keeps the two in sync.
Was this helpful? React with 👍 / 👎
Code Review 👍 Approved with suggestions 0 resolved / 1 findingsAdds telemetry infrastructure including a timed utility, new finding types, and file path constants. Please document the event_timestamp format for finding events to ensure consistency. 💡 Quality: event_timestamp format undocumented for finding events📄 src/lib/state.ts:417-418 📄 src/lib/state.ts:484-490
🤖 Prompt for agentsOptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change:
Was this helpful? React with 👍 / 👎 | Gitar |
|



What
Purely additive foundation that the subsequent CLI-728, CLI-730, CLI-731, and CLI-733 PRs depend on. No behaviour changes.
src/lib/timed.ts— generictimed<T>(fn: () => Promise<T>)utility that wraps any async call and returns its result alongside the wall-clock duration in milliseconds. Used by all three analyzer call sites (sonar-secrets, SQAA, SCA) to measure scan duration without changing existing function signatures.src/lib/state.ts— two new types:AnalysisFindingEventPayload(the four new fieldscaller_command,analyzer,rule_key,scan_duration_msplus all shared identity/connection fields fromCliCommandExecuted) andStoredFindingEvent(metadata envelope + payload, mirrorsStoredTelemetryEvent).src/lib/config-constants.ts—TELEMETRY_DIRandFINDINGS_NDJSON_PATHconstants pointing to~/.sonar/sonarqube-cli/telemetry/findings.ndjson, the append-only NDJSON sink introduced in CLI-728.Tests
timed()returns the correct value and a non-negativedurationMstimed()propagates errors from the wrapped function unchangeddurationMsreflects actual elapsed time (wraps a real 50 ms sleep and asserts the result lands within tolerance — catches implementations that always return 0)Dependencies
None. Must land before CLI-728 (sink + flush), CLI-730 (secrets call sites), CLI-731 (SQAA call sites), and CLI-733 (SCA call sites).