Skip to content

docs: fix OpenTelemetry guide to use correct SDK APIs#597

Merged
patniko merged 2 commits intomainfrom
fix/otel-guide-sdk-accuracy
Feb 27, 2026
Merged

docs: fix OpenTelemetry guide to use correct SDK APIs#597
patniko merged 2 commits intomainfrom
fix/otel-guide-sdk-accuracy

Conversation

@patniko
Copy link
Contributor

@patniko patniko commented Feb 27, 2026

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:

  • CopilotClient constructor: Changed from CopilotClient(SessionConfig(model="gpt-5")) to CopilotClient() — the client takes CopilotClientOptions, not SessionConfig. The model parameter belongs on create_session().
  • Event subscription pattern: Replaced all async for event in session.send(...) with the correct callback pattern using session.on(handler). The SDK's send() returns a message ID string, not an async iterator.
  • Message format: Changed session.send("string") to session.send({"prompt": "string"}) — the method takes a MessageOptions dict.
  • Permission handler: Added required on_permission_request to all create_session() calls (SDK raises ValueError without it).
  • Imports: Fixed from copilot import SessionConfig to from copilot import PermissionHandler.

What was already correct (unchanged):

  • All SessionEventType values referenced
  • Event data field names (input_tokens, output_tokens, model, tool_name, etc.)
  • OpenTelemetry semantic convention attribute names and patterns
  • MCP semantic conventions section
  • Mapping tables, best practices, and troubleshooting

- 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>
@patniko patniko requested a review from a team as a code owner February 27, 2026 03:53
Copilot AI review requested due to automatic review settings February 27, 2026 03:53
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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

Comment on lines +96 to +97
# Or send and wait for the session to become idle
response = await session.send_and_wait({"prompt": "Hello, world!"})
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
# 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!"})

Copilot uses AI. Check for mistakes.
data = event.data

if event.type == SessionEventType.TOOL_EXECUTION_START and data:
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
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.

2 participants