feat(eve): record the caller and accept authored instrumentation events - #507
feat(eve): record the caller and accept authored instrumentation events#507HugoRCD wants to merge 2 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
🦋 Changeset detectedLatest commit: 72df56a The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Thank you for following the naming conventions! 🙏 |
commit: |
📝 WalkthroughWalkthroughEve events now include authenticated caller identifiers. Eve instrumentation accepts custom event handlers and merges authored runtime context with evlog turn/session context, with authored keys taking precedence. ChangesEve instrumentation updates
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant EveSession
participant buildCaller
participant buildLineage
participant stepStarted
participant UserHandler
EveSession->>buildCaller: authenticated principal
buildCaller->>buildLineage: principalId, principalType, authenticator
buildLineage-->>EveSession: eve.caller on turn/session events
stepStarted->>UserHandler: runtime event
UserHandler-->>stepStarted: authored context
stepStarted->>stepStarted: merge evlog context
stepStarted-->>EveSession: merged runtime context
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/docs/content/5.use-cases/5.eve.md`:
- Line 229: Update the PostHog sentence in the instrumentation guidance to say
that PostHog links spans to the initiating user, correcting the grammar while
keeping the prose factual and plain.
In `@packages/evlog/README.md`:
- Line 599: Update packages/evlog/README.md lines 599-599 to state that
authenticated turns carry eve.caller and unauthenticated turns omit it. Update
apps/docs/content/5.use-cases/5.eve.md lines 234-238 so the example omits
caller.id or returns undefined when principalId is absent.
- Line 597: Update the documentation sentence describing the events merge
behavior near defineEvlogInstrumentation() to limit the claim specifically to
events['step.started']; clarify that authored and evlog runtime context are
merged only in the wrapped step.started handler, while other custom event
handlers pass through unchanged.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 66d90459-a924-4a65-b34c-55a829034847
📒 Files selected for processing (2)
apps/docs/content/5.use-cases/5.eve.mdpackages/evlog/README.md
|
|
||
| ### Combine with another integration | ||
|
|
||
| An agent has exactly one `agent/instrumentation.ts`, and other integrations want the same `step.started` slot — PostHog's links spans to the initiating user. Pass `events` and yours is merged with evlog's rather than replacing it: |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Correct the PostHog sentence.
PostHog's links spans is not grammatical. Replace it with PostHog links spans to the initiating user.
As per coding guidelines, prose must remain factual and plain.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@apps/docs/content/5.use-cases/5.eve.md` at line 229, Update the PostHog
sentence in the instrumentation guidance to say that PostHog links spans to the
initiating user, correcting the grammar while keeping the prose factual and
plain.
Source: Coding guidelines
| `defineEvlogHook()` maps eve turn lifecycle events to one wide event per turn. Call `useLogger()` in tools — the logger is bound via AsyncLocalStorage on `turn.started`. Pass `ctx` only when ALS is unavailable (`useLogger(ctx)`). Pretty-printing follows `isDev()` by default (tree locally, JSON in production); set `init.pretty: false` explicitly if you need to override. | ||
|
|
||
| `defineEvlogInstrumentation()` is optional: it stamps `evlog.request_id` onto eve's AI SDK spans so a trace joins back to its wide event, and back. Requires eve 0.30 or later. Complements eve Agent Runs — see the [eve use case](https://evlog.dev/use-cases/eve). | ||
| `defineEvlogInstrumentation()` is optional: it stamps `evlog.request_id` onto eve's AI SDK spans so a trace joins back to its wide event, and back. Pass `events` to merge your own runtime context with evlog's, so another integration can share the single `agent/instrumentation.ts` slot. Requires eve 0.30 or later. Complements eve Agent Runs — see the [eve use case](https://evlog.dev/use-cases/eve). |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Limit the event-merging claim to events['step.started'].
defineEvlogInstrumentation() merges authored and evlog runtime context in the wrapped step.started handler. Other custom event handlers pass through unchanged. Update this sentence so users do not expect evlog context on every event.
Proposed fix
-`defineEvlogInstrumentation()` is optional: it stamps `evlog.request_id` onto eve's AI SDK spans so a trace joins back to its wide event, and back. Pass `events` to merge your own runtime context with evlog's, so another integration can share the single `agent/instrumentation.ts` slot. Requires eve 0.30 or later. Complements eve Agent Runs — see the [eve use case](https://evlog.dev/use-cases/eve).
+`defineEvlogInstrumentation()` is optional: it stamps `evlog.request_id` onto eve's AI SDK spans so a trace joins back to its wide event, and back. Pass an `events['step.started']` handler to merge your own runtime context with evlog's, so another integration can share the single `agent/instrumentation.ts` slot. Requires eve 0.30 or later. Complements eve Agent Runs — see the [eve use case](https://evlog.dev/use-cases/eve).📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| `defineEvlogInstrumentation()` is optional: it stamps `evlog.request_id` onto eve's AI SDK spans so a trace joins back to its wide event, and back. Pass `events` to merge your own runtime context with evlog's, so another integration can share the single `agent/instrumentation.ts` slot. Requires eve 0.30 or later. Complements eve Agent Runs — see the [eve use case](https://evlog.dev/use-cases/eve). | |
| `defineEvlogInstrumentation()` is optional: it stamps `evlog.request_id` onto eve's AI SDK spans so a trace joins back to its wide event, and back. Pass an `events['step.started']` handler to merge your own runtime context with evlog's, so another integration can share the single `agent/instrumentation.ts` slot. Requires eve 0.30 or later. Complements eve Agent Runs — see the [eve use case](https://evlog.dev/use-cases/eve). |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/evlog/README.md` at line 597, Update the documentation sentence
describing the events merge behavior near defineEvlogInstrumentation() to limit
the claim specifically to events['step.started']; clarify that authored and
evlog runtime context are merged only in the wrapped step.started handler, while
other custom event handlers pass through unchanged.
| `defineEvlogInstrumentation()` is optional: it stamps `evlog.request_id` onto eve's AI SDK spans so a trace joins back to its wide event, and back. Requires eve 0.30 or later. Complements eve Agent Runs — see the [eve use case](https://evlog.dev/use-cases/eve). | ||
| `defineEvlogInstrumentation()` is optional: it stamps `evlog.request_id` onto eve's AI SDK spans so a trace joins back to its wide event, and back. Pass `events` to merge your own runtime context with evlog's, so another integration can share the single `agent/instrumentation.ts` slot. Requires eve 0.30 or later. Complements eve Agent Runs — see the [eve use case](https://evlog.dev/use-cases/eve). | ||
|
|
||
| Every turn event carries `eve.caller` — `principalId`, `principalType` and `authenticator` — so cost and volume group by who triggered the turn. |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win
Keep unauthenticated caller handling consistent in the documentation.
The implementation omits caller data when no authenticated principal exists. The README says every turn carries eve.caller, while the example emits an empty caller.id.
packages/evlog/README.md#L599: state that authenticated turns carryeve.callerand unauthenticated turns omit it.apps/docs/content/5.use-cases/5.eve.md#L234-L238: omitcaller.idor returnundefinedwhenprincipalIdis absent.
As per coding guidelines, prose must remain factual and plain.
📍 Affects 2 files
packages/evlog/README.md#L599-L599(this comment)apps/docs/content/5.use-cases/5.eve.md#L234-L238
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/evlog/README.md` at line 599, Update packages/evlog/README.md lines
599-599 to state that authenticated turns carry eve.caller and unauthenticated
turns omit it. Update apps/docs/content/5.use-cases/5.eve.md lines 234-238 so
the example omits caller.id or returns undefined when principalId is absent.
Source: Coding guidelines
An agent has exactly one
agent/instrumentation.ts, and other integrations want the samestep.startedslot — PostHog's links spans to the initiating user.defineEvlogInstrumentationowned that slot outright, so adopting one meant dropping the other.It now accepts
events, merged with the runtime context it contributes. evlog'sevlog.request_id/evlog.session_idare applied first, so authored keys win on a collision:Turn and session events also carry
eve.callernow:principalId,principalType,authenticator, taken from the principal eve resolved at dispatch. On a multi-user channel that is the dimension you group cost, volume and refusals by, and it was previously unreachable — the enrich hook is HTTP-shaped and exposes no path to the eve session.subjectandattributesare excluded on purpose, since a channel may put a name or an email in them.Docs
/use-cases/evegainseve.callerin the wide-event field table and a "Combine with another integration" section under the correlation guide. The package README notes both. No skill coversevlog/eve, so none needed updating.Testing
packages/evlog/test/eve.test.ts— 66 passing. Seven new cases: the merge, an authored key winning a collision, an authored context surviving outside a tracked turn, neither side contributing, the caller on the event, the caller's field set being exactly the three identifiers, and its absence without an authenticated principal.pnpm api:snapshotis unchanged.Summary by CodeRabbit