docs: fix OpenTelemetry guide to use correct SDK APIs#597
Conversation
- CopilotClient() takes CopilotClientOptions, not SessionConfig; model
is set on create_session() instead
- session.send() returns a message ID, not an async iterator; events
are received via session.on(handler) callbacks
- session.send() takes a dict {"prompt": ...}, not a bare string
- Add required on_permission_request to all create_session() calls
- Fix imports: SessionConfig → PermissionHandler
- Rewrite complete example with correct event subscription pattern
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes critical API usage errors in the OpenTelemetry instrumentation guide that was originally added in #529. The guide had code examples using incorrect Copilot SDK Python APIs that would not work in practice.
Changes:
- Fixed CopilotClient constructor to not accept SessionConfig (model now specified in create_session)
- Replaced incorrect async iteration pattern with correct callback-based event subscription using session.on()
- Changed message format from string to MessageOptions dict with "prompt" key
- Added required on_permission_request handler to all session creation examples
| # Or send and wait for the session to become idle | ||
| response = await session.send_and_wait({"prompt": "Hello, world!"}) |
There was a problem hiding this comment.
The example sends two messages to the same session (lines 94 and 97), which may be confusing since the comment on line 96 says "Or send and wait..." suggesting these are alternatives. Consider either: 1) removing one of the send calls to show a single approach, or 2) clarifying in the comments that this demonstrates two different ways to send messages, or 3) restructuring to show them as separate examples.
| # Or send and wait for the session to become idle | |
| response = await session.send_and_wait({"prompt": "Hello, world!"}) | |
| # Or, alternatively, send and wait for the session to become idle: | |
| # response = await session.send_and_wait({"prompt": "Hello, world!"}) |
| data = event.data | ||
|
|
||
| if event.type == SessionEventType.TOOL_EXECUTION_START and data: |
There was a problem hiding this comment.
The code example uses uuid.uuid4() but the uuid module is not imported in this code block. Since this is a standalone example, it should include import uuid along with the other imports shown (json on line 188) to be self-contained and runnable.
Summary
Fixes the OpenTelemetry instrumentation guide (
docs/opentelemetry-instrumentation.md) to use the correct Copilot SDK Python APIs. The original guide (merged in #529) had code examples that used incorrect API patterns.Changes
Critical fixes:
CopilotClientconstructor: Changed fromCopilotClient(SessionConfig(model="gpt-5"))toCopilotClient()— the client takesCopilotClientOptions, notSessionConfig. Themodelparameter belongs oncreate_session().async for event in session.send(...)with the correct callback pattern usingsession.on(handler). The SDK'ssend()returns a message ID string, not an async iterator.session.send("string")tosession.send({"prompt": "string"})— the method takes aMessageOptionsdict.on_permission_requestto allcreate_session()calls (SDK raisesValueErrorwithout it).from copilot import SessionConfigtofrom copilot import PermissionHandler.What was already correct (unchanged):
SessionEventTypevalues referencedinput_tokens,output_tokens,model,tool_name, etc.)