feat(agents): add OpenTelemetry telemetry support#75
Conversation
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 detectedLatest commit: deed9e0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds 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 Changes
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (12)
.changeset/telemetry-otel-support.mdpackages/agents/docs/telemetry.mdpackages/agents/src/core/agents/base/agent.tspackages/agents/src/core/agents/base/telemetry.test.tspackages/agents/src/core/agents/base/telemetry.tspackages/agents/src/core/agents/base/utils.tspackages/agents/src/core/agents/flow/engine.tspackages/agents/src/core/agents/flow/flow-agent.tspackages/agents/src/core/agents/flow/steps/factory.tspackages/agents/src/core/agents/flow/types.tspackages/agents/src/core/agents/types.tspackages/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>
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
packages/agents/docs/telemetry.md
Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
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
📒 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>
Summary
telemetrysettings through agents, flow agents, and flow engines to the AI SDK'sexperimental_telemetryoptionfunctionId(defaults to agent name) andfunkai.agentChainmetadata for multi-agent trace visibilityChanges
base/telemetry.tsresolveTelemetry()helper — merges config + override, auto-sets functionId and agentChainbase/telemetry.test.tsbase/agent.tsresolveTelemetry()inprepareGeneration(), pass to AI SDK and sub-agentsbase/utils.tstelemetrytoParentAgentContextandbuildParentParams()types.tstelemetrytoAgentConfigandAgentGenerateOverrides, re-exportTelemetrySettingsflow/types.tstelemetrytoFlowAgentConfigBaseflow/flow-agent.tsflow/steps/factory.ts$.agent()callsflow/engine.tstelemetrytoFlowEngineConfig, merge engine + flow telemetryindex.tsTelemetrySettingsdocs/telemetry.mdTest plan
pnpm typecheck --filter=@funkai/agents— cleanpnpm test --filter=@funkai/agents— 664 tests pass (including 10 new telemetry tests)