Skip to content

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

Merged
HugoRCD merged 4 commits into
mainfrom
feat/eve-instrumentation-events-caller
Aug 7, 2026
Merged

feat(eve): record the caller and accept authored instrumentation events#507
HugoRCD merged 4 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 instrumentation with evlog.
  • Bug Fixes
    • Caller details exclude sensitive subject and attribute data.
    • Unauthenticated events 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 6:15pm
evlog-render-lab Ready Ready Preview Aug 7, 2026 6:15pm
evlog-telemetry Ready Ready Preview Aug 7, 2026 6:15pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
evi Ignored Ignored Preview Aug 7, 2026 6:15pm
just-use-evlog Ignored Ignored Preview Aug 7, 2026 6:15pm

Request Review

@changeset-bot

changeset-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0405b7c

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: 0405b7c

@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 and 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 HookSession
  participant buildCaller
  participant buildLineage
  participant defineEvlogInstrumentation
  participant UserEventHandler
  participant evlogRuntimeContext
  HookSession->>buildCaller: authenticated principal
  buildCaller->>buildLineage: principal identifiers
  buildLineage-->>HookSession: eve.caller on turn and session events
  defineEvlogInstrumentation->>UserEventHandler: invoke step.started handler
  UserEventHandler-->>defineEvlogInstrumentation: authored context
  defineEvlogInstrumentation->>evlogRuntimeContext: tracked step input
  evlogRuntimeContext-->>defineEvlogInstrumentation: evlog context or undefined
  defineEvlogInstrumentation-->>UserEventHandler: 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
Title check ✅ Passed The title clearly summarizes the two main changes: caller recording and authored instrumentation events.
Description check ✅ Passed The description explains the changes, rationale, documentation updates, and testing, but does not include a linked issue or explicit checklist.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 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

Comment thread apps/docs/content/5.use-cases/5.eve.md Outdated
Comment thread packages/evlog/README.md Outdated
Comment thread packages/evlog/README.md

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/evlog/src/eve/index.ts (1)

1516-1529: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

Preserve the events API or publish a breaking release.

defineEvlogInstrumentation() still accepts EvlogEveInstrumentationOptions, but the interface does not expose events and the implementation installs only the built-in step.started handler. Existing callers cannot pass custom event callbacks through this public API.

  • packages/evlog/src/eve/index.ts#L1516: retain callback composition or add migration docs.
  • .changeset/eve-instrumentation-events-and-caller.md#L2: change the release type from minor to major if this removal is intentional.
🤖 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/src/eve/index.ts` around lines 1516 - 1529, Update
defineEvlogInstrumentation in packages/evlog/src/eve/index.ts to preserve the
public events API: expose and forward caller-provided event callbacks while
retaining the built-in step.started handler through callback composition. If
removing custom events is intentional instead, update
.changeset/eve-instrumentation-events-and-caller.md at line 2 to classify the
release as major; otherwise no changes are required there.

Source: Coding guidelines

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

Outside diff comments:
In `@packages/evlog/src/eve/index.ts`:
- Around line 1516-1529: Update defineEvlogInstrumentation in
packages/evlog/src/eve/index.ts to preserve the public events API: expose and
forward caller-provided event callbacks while retaining the built-in
step.started handler through callback composition. If removing custom events is
intentional instead, update .changeset/eve-instrumentation-events-and-caller.md
at line 2 to classify the release as major; otherwise no changes are required
there.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 3459c412-18bd-4d39-a606-65055d54bf8e

📥 Commits

Reviewing files that changed from the base of the PR and between 72df56a and 0405b7c.

⛔ Files ignored due to path filters (1)
  • packages/evlog/test/toolkit/__snapshots__/api-surface.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (5)
  • .changeset/eve-instrumentation-events-and-caller.md
  • apps/docs/content/5.use-cases/5.eve.md
  • packages/evlog/README.md
  • packages/evlog/src/eve/index.ts
  • packages/evlog/test/eve.test.ts

@HugoRCD
HugoRCD merged commit 1838d60 into main Aug 7, 2026
20 checks passed
@HugoRCD
HugoRCD deleted the feat/eve-instrumentation-events-caller branch August 7, 2026 18:21
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