Skip to content

feat(eve): record the caller and accept authored instrumentation events - #507

Open
HugoRCD wants to merge 2 commits into
mainfrom
feat/eve-instrumentation-events-caller
Open

feat(eve): record the caller and accept authored instrumentation events#507
HugoRCD wants to merge 2 commits into
mainfrom
feat/eve-instrumentation-events-caller

Conversation

@HugoRCD

@HugoRCD HugoRCD commented Aug 7, 2026

Copy link
Copy Markdown
Owner

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. defineEvlogInstrumentation owned that slot outright, so adopting one meant dropping the other.

It now accepts events, merged with the runtime context it contributes. evlog's evlog.request_id / evlog.session_id are applied first, so authored keys win on a collision:

export default defineEvlogInstrumentation({
  setup: ({ agentName }) => registerOTel({ serviceName: agentName }),
  events: {
    'step.started': ({ session }) => ({
      runtimeContext: { 'caller.id': session.auth.current?.principalId ?? '' },
    }),
  },
})

Turn and session events also carry eve.caller now: 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. subject and attributes are excluded on purpose, since a channel may put a name or an email in them.

Docs

/use-cases/eve gains eve.caller in the wide-event field table and a "Combine with another integration" section under the correlation guide. The package README notes both. No skill covers evlog/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:snapshot is unchanged.

Summary by CodeRabbit

  • New Features
    • Instrumentation events can include custom runtime context.
    • Custom context takes precedence when keys overlap with request or session context.
    • Events can record authenticated caller ID, type, and authenticator when available.
    • Integrations can share the instrumentation slot with evlog.
  • Bug Fixes
    • Caller details no longer include sensitive subject or attribute data.
    • Events without an authenticated caller omit caller information.
    • Context is handled consistently inside and outside tracked turns.
  • Documentation
    • Added guidance for caller information and combining instrumentation integrations.

@vercel

vercel Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
evlog-docs Ready Ready Preview, v0 Aug 7, 2026 4:20pm
evlog-render-lab Ready Ready Preview Aug 7, 2026 4:20pm
evlog-telemetry Ready Ready Preview Aug 7, 2026 4:20pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
evi Skipped Skipped Aug 7, 2026 4:20pm
just-use-evlog Skipped Skipped Aug 7, 2026 4:20pm

Request Review

@changeset-bot

changeset-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 72df56a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
evlog Minor
@evlog/cli Patch

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

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Thank you for following the naming conventions! 🙏

@pkg-pr-new

pkg-pr-new Bot commented Aug 7, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/@evlog/cli@507
npm i https://pkg.pr.new/evlog@507
npm i https://pkg.pr.new/@evlog/nuxthub@507
npm i https://pkg.pr.new/@evlog/telemetry@507

commit: 72df56a

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Eve 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.

Changes

Eve instrumentation updates

Layer / File(s) Summary
Authenticated caller lineage
packages/evlog/src/eve/index.ts, packages/evlog/test/eve.test.ts, apps/docs/content/5.use-cases/5.eve.md, packages/evlog/README.md
Eve lineage records the principal ID, type, and authenticator when available. Tests and documentation cover caller fields and the exclusion of subject and attributes.
Instrumentation event context
packages/evlog/src/eve/index.ts, packages/evlog/test/eve.test.ts, apps/docs/content/5.use-cases/5.eve.md, .changeset/eve-instrumentation-events-and-caller.md
defineEvlogInstrumentation() accepts custom event handlers. The step.started handler merges evlog and authored context, gives authored keys precedence, and returns no context when both sources are absent. Tests and documentation cover tracked and untracked turns.

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
Loading

Possibly related PRs

  • HugoRCD/evlog#504: Introduces the related Eve instrumentation API extended by this PR.
  • HugoRCD/evlog#505: Modifies and tests the same defineEvlogInstrumentation() behavior.
  • HugoRCD/evlog#506: Adds related Eve instrumentation and runtime-context handling.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes both primary changes: caller recording and authored instrumentation event support.
Description check ✅ Passed The description explains the problem, implementation, documentation, and testing, although it does not explicitly link an issue or include the checklist.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/eve-instrumentation-events-caller

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 02f1fb5 and 72df56a.

📒 Files selected for processing (2)
  • apps/docs/content/5.use-cases/5.eve.md
  • packages/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:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 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

Comment thread packages/evlog/README.md
`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).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🗄️ 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.

Suggested change
`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.

Comment thread packages/evlog/README.md
`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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🗄️ 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 carry eve.caller and unauthenticated turns omit it.
  • apps/docs/content/5.use-cases/5.eve.md#L234-L238: omit caller.id or return undefined when principalId is 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant