Custom event tracking#286
Conversation
0018654 to
17f3482
Compare
17f3482 to
23ffc5f
Compare
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
for port in PostgreSQL tests
for port in MySQL tests
To detect whether the update method completed.
An updater method returns early if the updater is already updating.
By mocking Aikido::Zen::APIStream to prevent real HTTP request to https://runtime.aikido.dev/api/runtime/stream.
By scaling down durations by 10x.
23ffc5f to
29ebef3
Compare
| event = {} | ||
|
|
||
| begin | ||
| event_str.each_line do |line| |
There was a problem hiding this comment.
APIStream#work contains 5 levels of nested control flow (http.request -> response.read_body -> while buffer loop -> begin/rescue -> event_str.each_line), making parsing hard to read. Extract the event parsing into a separate method to reduce nesting.
Details
✨ AI Reasoning
The APIStream#work method introduced a deeply nested control flow chain while parsing server-sent events: an HTTP request block contains a response body read block, which contains a loop for event boundaries, a begin/rescue block for parsing, and a per-line loop. This 5-level nesting reduces readability and testability of the parsing logic and was added in this PR (new file).
🔧 How do I fix it?
Keep nesting levels under 4. Extract complex logic into separate functions when indentation exceeds 4 levels.
Reply @AikidoSec feedback: [FEEDBACK] to get better review comments in the future.
Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info
| end | ||
| end | ||
|
|
||
| private def work |
There was a problem hiding this comment.
APIStream#work contains deep nested loops and conditionals; extract/paraphrase parsing into smaller helpers and use early returns/continues to flatten control flow for readability.
Details
✨ AI Reasoning
APIStream#work processes streaming data with multiple nested loops and conditionals, burying the core event dispatch logic inside several levels of nesting. Early guard clauses (e.g., return unless running?, continue on invalid buffer content, or extract a small helper to parse and dispatch one event with early exits) would flatten the function and improve readability and maintainability.
🔧 How do I fix it?
Place parameter validation and guard clauses at the function start. Use early returns to reduce nesting levels and improve readability.
Reply @AikidoSec feedback: [FEEDBACK] to get better review comments in the future.
Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info
| case response.code.to_i | ||
| when 200 | ||
| # empty | ||
| when 401, 403 | ||
| @running.make_false | ||
| return nil | ||
| else | ||
| return nil | ||
| end | ||
|
|
There was a problem hiding this comment.
This will fix the Use early returns and guard clauses issue detected on line: 124.
Show Fix
Aikido AutoFix Patch Suggestion - low confidence
This patch mitigates deep nesting in the work method by replacing a case statement with early guard clauses that return immediately for non-200 response codes, flattening the control flow and improving readability.
| case response.code.to_i | |
| when 200 | |
| # empty | |
| when 401, 403 | |
| @running.make_false | |
| return nil | |
| else | |
| return nil | |
| end | |
| if response.code.to_i == 401 || response.code.to_i == 403 | |
| @running.make_false | |
| return nil | |
| end | |
| return nil unless response.code.to_i == 200 | |
Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info
This change adds support for tracking named user events, sent from application code using
Aikido::Zen.track_user_event. User events include the event name, user ID, and IP address.This change extends and should be reviewed after #285.
Summary by Aikido
🚀 New Features
⚡ Enhancements
🐛 Bugfixes
More info