Add opt-in HTTP diagnostics logging with automatic header redaction#135
Open
Add opt-in HTTP diagnostics logging with automatic header redaction#135
Conversation
Co-authored-by: saurabhrb <32964911+saurabhrb@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add opt-in local file logging for HTTP diagnostics
Add opt-in HTTP diagnostics logging with automatic header redaction
Mar 10, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an opt-in, local file HTTP diagnostics logger to the Dataverse SDK, wired from DataverseConfig into the OData HTTP client so request/response traffic can be captured with header redaction and body truncation.
Changes:
- Introduces
LogConfigand internal_HttpLoggerto format and persist redacted HTTP request/response diagnostics with file rotation. - Wires
DataverseConfig.log_configthrough_ODataClientinto_HttpClientfor request/response/error logging. - Adds unit tests validating defaults, redaction, truncation behavior, and basic integration with
_HttpClient.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/data/test_enum_optionset_payload.py | Updates test stub config to include the new log_config attribute expected by _ODataClient. |
| tests/unit/core/test_http_logger.py | Adds unit/integration tests for LogConfig, _HttpLogger, and _HttpClient logger plumbing. |
| src/PowerPlatform/Dataverse/data/_odata.py | Creates _HttpLogger from config.log_config and passes it into _HttpClient. |
| src/PowerPlatform/Dataverse/core/log_config.py | Defines frozen LogConfig dataclass with defaults and redacted header set. |
| src/PowerPlatform/Dataverse/core/config.py | Adds log_config optional field to DataverseConfig and from_env(). |
| src/PowerPlatform/Dataverse/core/_http_logger.py | Implements structured diagnostics logging with redaction and truncation. |
| src/PowerPlatform/Dataverse/core/_http.py | Adds optional logger support; logs request (once), response (with elapsed), and transport errors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
This was referenced Mar 13, 2026
Closed
Closed
…icrosoft/PowerPlatform-DataverseClient-Python into copilot/add-local-file-logging
… logging section to readme
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.
Adds local file logging of HTTP request/response traffic to the SDK. Disabled by default (zero overhead); enabled by passing a
LogConfigtoDataverseConfig.New modules
core/log_config.py—LogConfigfrozen dataclass: configurable log folder, file prefix (timestamp auto-appended), body capture limit, redacted headers, log level, andRotatingFileHandlerrotation settingscore/_http_logger.py—_HttpLogger: structured log formatting, case-insensitive header redaction (Authorization,Proxy-Authorization,OCP-Apim-Subscription-Key,X-MS-Authorization-Auxiliary), body truncation with byte limit, dedicated named logger (propagate=Falseto avoid side effects)Wiring
config.py—DataverseConfiggainslog_config: Optional[LogConfig] = None(TYPE_CHECKING guard to avoid circular imports)_http.py—_HttpClient.__init__accepts optionallogger;_request()logs outbound request once (before retry loop), logs response with elapsed ms, logs transport errors onRequestException_odata.py— instantiates_HttpLoggerfromconfig.log_configand passes it through to_HttpClientUsage
Sample log output:
Original prompt
Summary
Add opt-in local file logging of HTTP request/response diagnostics to the Dataverse Python SDK. When enabled via a
LogConfigpassed throughDataverseConfig, every HTTP request and response is logged to timestamped.logfiles with automatic redaction of sensitive headers (e.g.,Authorizationbearer tokens).Design
The implementation consists of 2 new files and 3 modified files, with zero new external dependencies (uses only stdlib
logging,os,datetime).New Files
1.
src/PowerPlatform/Dataverse/core/log_config.py—LogConfigdataclassA frozen dataclass for opt-in logging configuration:
2.
src/PowerPlatform/Dataverse/core/_http_logger.py—_HttpLoggerinternal helperHandles structured log formatting, header redaction, body truncation, and file rotation: