Add span links support and BaggageBuilder.invokeAgentServer method#224
Merged
Add span links support and BaggageBuilder.invokeAgentServer method#224
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds OpenTelemetry span link propagation across observability scope types and extends the baggage fluent API to set server.address / server.port for invoke-agent scenarios.
Changes:
- Add optional
spanLinks?: Link[]toOpenTelemetryScopeand all derived scopestart(...)APIs, wiring through tostartSpan({ links }). - Add
BaggageBuilder.invokeAgentServer(address, port?)with logic to omit/clearserver.portfor443/undefined. - Add/adjust tests and update design docs + changelog to reflect the new APIs.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/observability/core/span-links.test.ts | New tests asserting Link[] are forwarded into created spans. |
| tests/observability/core/BaggageBuilder.test.ts | Adds tests for the new invokeAgentServer fluent setter. |
| packages/agents-a365-observability/src/tracing/scopes/OpenTelemetryScope.ts | Accepts spanLinks?: Link[] and forwards to OTel startSpan options. |
| packages/agents-a365-observability/src/tracing/scopes/InvokeAgentScope.ts | Threads spanLinks through start(...) and super(...). |
| packages/agents-a365-observability/src/tracing/scopes/InferenceScope.ts | Threads spanLinks through start(...) and super(...). |
| packages/agents-a365-observability/src/tracing/scopes/ExecuteToolScope.ts | Threads spanLinks through start(...) and super(...). |
| packages/agents-a365-observability/src/tracing/scopes/OutputScope.ts | Threads spanLinks through start(...) and super(...). |
| packages/agents-a365-observability/src/tracing/middleware/BaggageBuilder.ts | Implements invokeAgentServer(address, port?) and port cleanup behavior. |
| packages/agents-a365-observability/docs/design.md | Documents span link support and the new baggage builder method. |
| CHANGELOG.md | Records the new APIs under “Added”. |
) Add optional `spanLinks` parameter to all scope classes (OpenTelemetryScope, InvokeAgentScope, InferenceScope, ExecuteToolScope, OutputScope) to support OTel span link propagation. Add `invokeAgentServer()` to BaggageBuilder for setting server address/port baggage with proper cleanup of stale port entries. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Move jest.spyOn console mocks from beforeAll to beforeEach (restoreMocks compatibility) - Remove trace.disable() from afterAll to avoid resetting global provider for other test suites - Add test for clearing previously set non-443 port when invokeAgentServer is called again with port=443 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
ee4f0a6 to
1e81f01
Compare
packages/agents-a365-observability/src/tracing/middleware/BaggageBuilder.ts
Show resolved
Hide resolved
nikhilNava
requested changes
Mar 26, 2026
packages/agents-a365-observability/src/tracing/scopes/OpenTelemetryScope.ts
Outdated
Show resolved
Hide resolved
…ryScope constructor Update the base OpenTelemetryScope constructor signature from 9 positional parameters to 6 by accepting SpanDetails and UserDetails as structured objects. This encapsulates span configuration in the base class so subclasses simply pass spanDetails through without destructuring. Adding new span options now only requires changes to SpanDetails and the base class.
juliomenendez
previously approved these changes
Mar 26, 2026
nikhilNava
previously approved these changes
Mar 26, 2026
Contributor
nikhilNava
left a comment
There was a problem hiding this comment.
Can you do the same for span kind in the base scope
Move the `kind` parameter from a standalone constructor argument into the `SpanDetails` object in OpenTelemetryScope. Each subclass now builds a `resolvedSpanDetails` with its required span kind before calling super(). Simplify the `spanLinks` JSDoc in contracts.ts and clarify that the base class defaults spanKind to SpanKind.CLIENT. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
packages/agents-a365-observability/src/tracing/scopes/ExecuteToolScope.ts
Outdated
Show resolved
Hide resolved
ExecuteToolScope always forces SpanKind.INTERNAL regardless of any spanKind override in SpanDetails. Update the test expectation to verify the override is correctly ignored. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
Author
fixed . |
juliomenendez
previously approved these changes
Mar 26, 2026
nikhilNava
approved these changes
Mar 26, 2026
packages/agents-a365-observability/src/tracing/scopes/OpenTelemetryScope.ts
Show resolved
Hide resolved
juliomenendez
approved these changes
Mar 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
spanLinks?: Link[]toSpanDetailsinterface and thread through all scope classes (OpenTelemetryScope,InvokeAgentScope,InferenceScope,ExecuteToolScope,OutputScope) to support OTel span link propagation for causal relationships between spansinvokeAgentServer(address, port?)toBaggageBuilderfor setting server address/port baggage with proper cleanup of stale port entries when port is 443 or omittedOpenTelemetryScopeconstructor from 9 positional parameters to 6 by acceptingSpanDetailsandUserDetailsas structured objects. Subclasses now passspanDetailsthrough tosuper()without destructuring individual fields. Adding new span options only requires changes toSpanDetailsand the base class.Console Exporter Output (from basic-agent-sdk-sample)
invoke_agent span — 3 span links + server.address/port
Chat gpt-4 span — 2 span links
execute_tool send-email span — 1 span link
New features in the output:
invoke_agenthas 3 links,Chathas 2 links,execute_toolhas 1 link — each with typed attributesserver.address/server.portinvoke_agentspan — set viaBaggageBuilder.invokeAgentServer()Test plan
invokeAgentServersets address baggage and omits port for 443/undefined🤖 Generated with Claude Code