Skip to content

Add track() API for custom event tracking - #360

Merged
hansott merged 6 commits into
mainfrom
custom-event-tracking
Oct 20, 2026
Merged

hansott merged 6 commits into
mainfrom
custom-event-tracking

Conversation

@timokoessler

Copy link
Copy Markdown
Member

No description provided.

@codecov

codecov Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.42857% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
..._api/src/main/java/dev/aikido/agent_api/Track.java 94.28% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

eventName, // name
buildRequestData(context), // request
getManagerInfo(), // agent
context != null ? context.getUser() : null, // user

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.

need to format the user here I think? so that we don't include the usual heartbeat props?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

See b061545

return;
}

if (currentContext.incrementTrackedEventCount() > MAX_EVENTS_PER_REQUEST) {

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.

Let's trigger once per request? (the warning)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

See b061545


@Test
void createAPIEvent_WithContextButNoUser_ReturnsCustomEventEventWithNullUser() {
// Arrange

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.

let's get rid of these comments? doesn't add much value imo ^^

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Are also part of other existing test files, but will remove.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

See b061545

Comment thread docs/track.md Outdated

`track` only works inside an HTTP request. If you call it in a background job or outside of a request, nothing gets sent and you'll see a warning in the console.

Each request accepts up to 25 tracked events. Any further calls within the same request are dropped and logged as a warning.

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.

align with other custom event docs? (a bit more compact)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

See b061545

Comment thread agent_api/src/main/java/dev/aikido/agent_api/Track.java Outdated
@hansott
hansott force-pushed the custom-event-tracking branch from b061545 to b616b2b Compare October 5, 2026 13:52
Comment thread agent_api/src/main/java/dev/aikido/agent_api/Track.java
@hansott
hansott force-pushed the custom-event-tracking branch from c2ea7ba to f65225b Compare October 20, 2026 11:24
Comment on lines +17 to +19
// Events pile up while Aikido's API is slow or down, so cap memory use. add() drops events when full.
private static final int MAX_QUEUE_SIZE = 100;
private static final BlockingQueue<APIEvent> queue = new LinkedBlockingQueue<>(MAX_QUEUE_SIZE);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium - Bounded shared event queue lets tracked traffic suppress attack reporting and playbook counts

An unauthenticated client can repeatedly hit an application route that calls Track.track(...), such as the documented failed-login flow. The PR changes the shared AttackQueue to a 100-item queue that drops new entries when full, and both custom events and detected attacks use that same queue. Once the queue is saturated, later custom events and real attack reports are discarded, so Aikido stops counting them for dashboard visibility and playbook-based blocking until the backlog drains.

Suggested change
// Events pile up while Aikido's API is slow or down, so cap memory use. add() drops events when full.
private static final int MAX_QUEUE_SIZE = 100;
private static final BlockingQueue<APIEvent> queue = new LinkedBlockingQueue<>(MAX_QUEUE_SIZE);
private static final BlockingQueue<APIEvent> queue = new LinkedBlockingQueue<>();

More info - Reply on this comment to give feedback or ignore the issue.

@hansott
hansott force-pushed the custom-event-tracking branch from b99eb96 to d0cbadd Compare October 20, 2026 11:34
@hansott
hansott merged commit 22dd587 into main Oct 20, 2026
283 checks passed
@hansott
hansott deleted the custom-event-tracking branch October 20, 2026 11:46
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.

2 participants