docs: fix the Node.js inbound trace-context example to use a real tool-registration API - #2223
Open
examon wants to merge 1 commit into
Open
docs: fix the Node.js inbound trace-context example to use a real tool-registration API#2223examon wants to merge 1 commit into
examon wants to merge 1 commit into
Conversation
…l-registration API The Node.js example in the "CLI -> SDK (inbound)" section of docs/observability/opentelemetry.md registered a tool by calling session.registerTool(myTool, handler). That method is not part of the public CopilotSession API, so copying the example fails to compile with error TS2339: Property 'registerTool' does not exist on type 'CopilotSession' and, if the types are bypassed, throws "TypeError: session.registerTool is not a function" at runtime. The plural registerTools() is marked @internal and stripped from the shipped declarations, so there is no public session method to register a tool with after the session exists. Move the trace-restoring handler into defineTool() and register the tool through client.createSession({ tools: [myTool] }), which is the public registration path and the one used by the rest of the documentation. The trace-context logic is unchanged; only the registration mechanism is corrected. As a side effect the handler's args and invocation parameters are now contextually typed, so the invocation.traceparent / invocation.tracestate access in the example is actually type-checked.
Contributor
There was a problem hiding this comment.
🟢 Ready to approve
The example now uses verified public APIs while preserving the trace-restoration logic.
This review doesn't count toward merge requirements. Sign up for the private preview to control whether Copilot approvals count.
Pull request overview
Fixes #2222 by replacing a nonexistent session API with the public Node.js tool-registration flow.
Changes:
- Defines the traced handler with
defineTool(). - Registers the tool through
client.createSession().
File summaries
| File | Description |
|---|---|
docs/observability/opentelemetry.md |
Corrects the inbound trace-context example. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Balanced
We're testing this review assessment. Please use 👍 or 👎 to tell us if it's correct.
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.
Fixes #2222
Problem
The Node.js example in the CLI -> SDK (inbound) part of
docs/observability/opentelemetry.mdregistered a tool by calling
session.registerTool(myTool, handler). That method is not part of thepublic
CopilotSessionAPI, so the documented snippet does not compile:and throws
TypeError: session.registerTool is not a functionif the types are bypassed. The pluralregisterTools()is@internaland removed from the shipped declarations bystripInternal: true,so there is no public session method to swap in - the registration step has to be restructured.
The example's trace-restoration logic was always correct:
ToolInvocation.traceparentand.tracestateare public and are delivered to the handler. Only the registration mechanism was wrong.Fix
Move the trace-restoring handler into
defineTool()and register the tool throughclient.createSession({ tools: [myTool] }), the public registration path already used by the rest ofthe documentation. Every part of the trace-context logic is carried over unchanged:
propagation.extract(context.active(), carrier),trace.getTracer("my-app"),context.with(parentCtx, ...),tracer.startActiveSpan("my-tool", ...)andspan.end()in afinally.One file changes, and only the one fenced block inside it. No API, no behaviour, and no other
documentation is touched.
The
<!-- docs-validate: skip -->marker on the block is deliberately kept:scripts/docs-validationhas no
@opentelemetry/apidependency, so unskipping the block would make it fail on the missingthird-party import rather than validate anything about the SDK.
Verification
Reproducer, against the published package so it does not depend on this branch:
Before - the old snippet, with only the scaffolding the surrounding docs supply out-of-band
(
session,myTool,doWork):After - the new snippet extracted from the updated doc, with
clientanddoWorkdeclared:Both results hold against the published
@github/copilot-sdk@1.0.8and against a local build of thisbranch, and under both TypeScript 5.9.3 and 7.0.2. The two
TS7006errors disappear with the fixbecause
argsandinvocationbecome contextually typed, so the example'sinvocation.traceparent/.tracestateaccess is now genuinely type-checked.Runtime confirmation that the old call could never have worked:
I also confirmed the corrected path really does deliver the trace context, so the section still does
what it promises:
createSession()passesconfig.toolsto the session, the session stores eachtool's handler by name, and the handler is invoked with a
ToolInvocationcarryingtraceparentandtracestatefrom the incoming request.scripts/docs-validationwas run before and after; its extracted-block manifest is identical, whichconfirms no collateral damage (it skips this block by design, so it is a regression check, not proof
of the fix - the compile above is the proof).
Out of scope
The feature table in
docs/troubleshooting/compatibility.mdlists two methods that are absent fromthe shipped declarations:
registerTools()at line 35 anddestroy()at line 19, both under the"Available in SDK" heading. Line 35 is not the only stale cell there, so correcting just it in an
OpenTelemetry docs fix would be arbitrary. That table looks like its own small pass, so I left it
alone.