Skip to content

Conversation

@zhaodongwang-msft
Copy link
Collaborator

This pull request introduces support for propagating correlation IDs across nested SDK calls in the Dataverse client, enabling easier debugging and trace alignment for HTTP requests. The main changes include new context manager APIs for correlation scopes, consistent header propagation, and improved error reporting with expanded request ID details.

Correlation ID propagation and context management:

  • Added a correlation_scope context manager to the DataverseClient class, allowing users to specify a correlation ID that is automatically injected into all nested HTTP requests via the x-ms-correlation-request-id header. This makes it easier to correlate logs and traces for a group of related operations.
  • Implemented an internal _call_scope context manager in _ODataClient using Python's contextvars to manage correlation IDs across nested calls, ensuring thread safety and isolation. [1] [2]
  • Updated all CRUD and metadata methods in DataverseClient to use the new _scoped_odata context manager, ensuring correlation IDs are consistently propagated. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13]

Request header and error reporting improvements:

  • All outgoing requests now include both x-ms-correlation-request-id and a unique x-ms-client-request-id in their headers, and these values are logged for debugging.
  • The HttpError class and its constructor have been updated to separately track and report correlation IDs, client request IDs, and service request IDs, providing more detailed error diagnostics. [1] [2] [3] [4] [5]

Documentation and testing:

  • Added documentation and usage examples for the new correlation scope feature to README.md.
  • Introduced new test helpers in tests/unit/core/test_http_errors.py to record and verify request headers, ensuring correct propagation of correlation and client request IDs. [1] [2]

These changes provide a robust foundation for request tracing and debugging, making it easier to correlate SDK activity with Dataverse server logs and distributed traces.…lso service request id correctly

@zhaodongwang-msft zhaodongwang-msft requested a review from a team as a code owner November 20, 2025 00:29
Copilot AI review requested due to automatic review settings November 20, 2025 00:29
Copy link

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 adds correlation ID propagation across nested SDK calls to improve debugging and request tracing in the Dataverse client. It introduces context managers for scoped correlation IDs and expands error reporting to include separate client request IDs, correlation IDs, and service request IDs.

  • Implemented correlation_scope() context manager allowing users to specify custom correlation IDs for groups of operations
  • Added _call_scope() internal context manager using Python's contextvars for thread-safe correlation ID management
  • Updated all CRUD and metadata methods to use _scoped_odata() wrapper ensuring correlation ID propagation

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/PowerPlatform/Dataverse/data/_odata.py Added _call_scope() context manager, updated _request() to inject correlation and client request IDs into headers, modified error handling to separately track correlation, client request, and service request IDs
src/PowerPlatform/Dataverse/core/errors.py Updated HttpError constructor to accept separate correlation_id, client_request_id, and service_request_id parameters with updated documentation
src/PowerPlatform/Dataverse/client.py Added correlation_scope() public API and _scoped_odata() helper, updated all data and metadata methods to use scoped contexts
tests/unit/core/test_http_errors.py Added test helpers RecordingHTTP and DummyCredential, added tests for correlation ID propagation behavior
README.md Added documentation section explaining how to use correlation_scope() for request correlation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

3 participants