Skip to content

feat(agents): add OpenTelemetry telemetry support#75

Merged
zrosenbauer merged 7 commits intomainfrom
feat/agents-telemetry-otel
Apr 2, 2026
Merged

feat(agents): add OpenTelemetry telemetry support#75
zrosenbauer merged 7 commits intomainfrom
feat/agents-telemetry-otel

Conversation

@zrosenbauer
Copy link
Copy Markdown
Member

Summary

  • Thread telemetry settings through agents, flow agents, and flow engines to the AI SDK's experimental_telemetry option
  • Auto-enrich spans with functionId (defaults to agent name) and funkai.agentChain metadata for multi-agent trace visibility
  • Telemetry propagates to sub-agents and merges across layers (engine -> flow -> agent -> per-call) with shallow-merged metadata
  • Add telemetry docs with provider setup guides (Braintrust, VoltAgent, Langfuse, Laminar, PostHog, SigNoz/Jaeger/OTLP)

Changes

File Description
base/telemetry.ts New resolveTelemetry() helper — merges config + override, auto-sets functionId and agentChain
base/telemetry.test.ts 10 unit tests for merge logic, chain serialization, precedence
base/agent.ts Call resolveTelemetry() in prepareGeneration(), pass to AI SDK and sub-agents
base/utils.ts Add telemetry to ParentAgentContext and buildParentParams()
types.ts Add telemetry to AgentConfig and AgentGenerateOverrides, re-export TelemetrySettings
flow/types.ts Add telemetry to FlowAgentConfigBase
flow/flow-agent.ts Pass config telemetry to step builder
flow/steps/factory.ts Thread telemetry through step builders and $.agent() calls
flow/engine.ts Add telemetry to FlowEngineConfig, merge engine + flow telemetry
index.ts Re-export TelemetrySettings
docs/telemetry.md Full telemetry documentation mirroring Vercel AI SDK structure

Test plan

  • pnpm typecheck --filter=@funkai/agents — clean
  • pnpm test --filter=@funkai/agents — 664 tests pass (including 10 new telemetry tests)
  • CI passes

Thread telemetry settings through agents, flow agents, and flow engines
to the AI SDK's experimental_telemetry option. Auto-enriches spans with
functionId (defaults to agent name) and funkai.agentChain metadata for
multi-agent trace visibility. Telemetry propagates to sub-agents and
merges across layers with shallow-merged metadata.

Co-Authored-By: Claude <noreply@anthropic.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 1, 2026

🦋 Changeset detected

Latest commit: deed9e0

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

This PR includes changesets to release 1 package
Name Type
@funkai/agents Minor

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

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 1, 2026

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

Project Deployment Actions Updated (UTC)
funkai Ready Ready Preview, Comment Apr 2, 2026 4:42pm

Request Review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 1, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds OpenTelemetry telemetry support across agents and flows: new telemetry config fields at engine/flow/agent/per-call layers, a resolver that shallow-merges metadata and injects functionId and funkai.agentChain, and threads resolved settings into the AI SDK as experimental_telemetry. Documentation and tests added.

Changes

Cohort / File(s) Summary
Changeset & Docs
​.changeset/telemetry-otel-support.md, packages/agents/docs/telemetry.md
New changeset and comprehensive telemetry documentation describing enablement, span attributes, merge/precedence rules, provider examples, and TelemetrySettings reference.
Telemetry Core & Tests
packages/agents/src/core/agents/base/telemetry.ts, packages/agents/src/core/agents/base/telemetry.test.ts
Added exported resolveTelemetry(...) to merge config and per-call telemetry (override wins), shallow-merge metadata, inject funkai.agentChain string, default functionId to agent name; tests cover precedence, merging, and edge cases.
Agent Base & Context plumbing
packages/agents/src/core/agents/base/agent.ts, packages/agents/src/core/agents/base/utils.ts
Resolve telemetry during prepare, attach telemetry to ParentAgentContext, include telemetry in buildParentParams, and pass experimental_telemetry into AI SDK generate()/stream() calls.
Flow Engine / Flow Agent Integration
packages/agents/src/core/agents/flow/engine.ts, packages/agents/src/core/agents/flow/flow-agent.ts, packages/agents/src/core/agents/flow/types.ts, packages/agents/src/core/agents/flow/steps/factory.ts
Added telemetry to FlowEngine/flow/flow-agent configs; engine merges engine & flow defaults (mergeTelemetry) with shallow metadata merge; threaded telemetry into step builder and ensured $.agent() forwards flow telemetry to sub-agents.
Types & Exports
packages/agents/src/core/agents/types.ts, packages/agents/src/index.ts
Re-exported TelemetrySettings from ai; added telemetry?: TelemetrySettings to AgentConfig and per-call AgentGenerateOverrides; updated public exports to include telemetry types.

Sequence Diagram(s)

sequenceDiagram
    participant FlowEngine as FlowEngine
    participant FlowAgent as FlowAgent
    participant Agent as Agent
    participant AI as AI SDK

    FlowEngine->>FlowAgent: create flow (mergeTelemetry(engine.telemetry, flow.telemetry))
    activate FlowAgent
    FlowAgent->>FlowAgent: forward telemetry to StepBuilder
    loop for each $.agent() call
        FlowAgent->>Agent: call agent(params + telemetry)
        activate Agent
        Agent->>Agent: resolveTelemetry(config.telemetry, params.telemetry, agentName, agentChain)
        Note over Agent: precedence: override → agent → flow/engine\ninject functionId (agentName) if missing\ninject metadata["funkai.agentChain"] = "id1 > id2"
        Agent->>AI: generate/stream (experimental_telemetry: resolvedTelemetry)
        AI-->>Agent: emit spans (GenAI + funkai metadata)
        deactivate Agent
    end
    deactivate FlowAgent
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding OpenTelemetry telemetry support to the agents package.
Description check ✅ Passed The description comprehensively outlines the implementation details, file-by-file changes, and test coverage for the telemetry feature.
Docstring Coverage ✅ Passed Docstring coverage is 81.82% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/agents/src/core/agents/types.ts`:
- Line 32: Add a JSDoc block above the exported type TelemetrySettings to
document the new public export: provide a one-line description, any relevant
property notes, and a short usage/example (e.g., "import type {
TelemetrySettings } from '@funkai/agents';"); ensure the block sits immediately
above the export statement "export type { TelemetrySettings } from 'ai';" and
include any required tags per project guidelines (e.g., `@example` and
`@typedef/`@type or `@remarks`) so the exported type is properly documented for
consumers.
🪄 Autofix (Beta)

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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: aa3628b1-ea93-4833-85cd-520ad6b09a10

📥 Commits

Reviewing files that changed from the base of the PR and between a7d1e53 and 324e5c6.

📒 Files selected for processing (12)
  • .changeset/telemetry-otel-support.md
  • packages/agents/docs/telemetry.md
  • packages/agents/src/core/agents/base/agent.ts
  • packages/agents/src/core/agents/base/telemetry.test.ts
  • packages/agents/src/core/agents/base/telemetry.ts
  • packages/agents/src/core/agents/base/utils.ts
  • packages/agents/src/core/agents/flow/engine.ts
  • packages/agents/src/core/agents/flow/flow-agent.ts
  • packages/agents/src/core/agents/flow/steps/factory.ts
  • packages/agents/src/core/agents/flow/types.ts
  • packages/agents/src/core/agents/types.ts
  • packages/agents/src/index.ts

Merge separate `from "ai"` import statements to satisfy oxlint
no-duplicates rule.

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/agents/docs/telemetry.md`:
- Around line 193-198: The fenced diagram showing telemetry precedence should
include a language identifier for formatting; update the code block to use a
language tag like ```text (or replace it with a Markdown quote block) so the
diagram containing FlowEngine.telemetry, FlowAgentConfig.telemetry,
AgentConfig.telemetry, and GenerateParams.telemetry is rendered consistently and
follows doc formatting standards.
🪄 Autofix (Beta)

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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: a6261202-0d17-4e74-9021-5626c8e8e571

📥 Commits

Reviewing files that changed from the base of the PR and between f3dd5da and 2bad852.

📒 Files selected for processing (1)
  • packages/agents/docs/telemetry.md

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/agents/docs/telemetry.md`:
- Line 68: Update the telemetry docs to clarify that while per-call scalar
fields override config and metadata is shallow-merged between config and
per-call values, the reserved key "funkai.agentChain" is injected by the system
after the merge and cannot be overridden by either config or per-call metadata;
explicitly state that "funkai.agentChain" is an exception to the
preservation/override rules and will always be set by the system post-merge so
readers know it cannot be changed via metadata.
🪄 Autofix (Beta)

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: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7091bc4e-2556-4699-b815-63c659f49146

📥 Commits

Reviewing files that changed from the base of the PR and between 2bad852 and e3dbe99.

📒 Files selected for processing (1)
  • packages/agents/docs/telemetry.md

…ge semantics

Co-Authored-By: Claude <noreply@anthropic.com>
… subagent)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
@zrosenbauer zrosenbauer merged commit e6a2df8 into main Apr 2, 2026
5 checks passed
@zrosenbauer zrosenbauer deleted the feat/agents-telemetry-otel branch April 2, 2026 20:59
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.

1 participant