Skip to content

Commit 714953a

Browse files
author
Max Wang
committed
remove functionality for user to specify correlation scope
1 parent 8ebd080 commit 714953a

4 files changed

Lines changed: 3 additions & 95 deletions

File tree

README.md

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -300,25 +300,6 @@ except ValidationError as e:
300300
print(f"Validation error: {e.message}")
301301
```
302302

303-
### Correlate multiple requests to debug
304-
305-
Give your own identifier to every HTTP call by wrapping operations in
306-
`DataverseClient.correlation_scope()`:
307-
308-
```python
309-
from uuid import uuid4
310-
311-
with client.correlation_scope(str(uuid4())):
312-
client.create("account", {"name": "Scoped Request"})
313-
pages = client.get("account", filter="statecode eq 0")
314-
for batch in pages:
315-
...
316-
```
317-
318-
All nested SDK calls inside the block (including pagination and retries) reuse
319-
the provided value for the `x-ms-correlation-request-id` header, which makes it
320-
easy to align Dataverse traces. If you omit the context manager, the SDK automatically generates unique correlation IDs.
321-
322303
### Authentication issues
323304

324305
**Common fixes:**

src/PowerPlatform/Dataverse/client.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -698,37 +698,4 @@ def flush_cache(self, kind) -> int:
698698
with self._scoped_odata() as od:
699699
return od._flush_cache(kind)
700700

701-
# Other utilities
702-
@contextmanager
703-
def correlation_scope(self, correlation_id: str) -> Iterator["DataverseClient"]:
704-
"""Share a caller-specified correlation id across nested SDK calls.
705-
706-
Use this context manager to stamp your own identifier on every Dataverse
707-
request made within the ``with`` block. Nested SDK calls reuse the
708-
existing correlation id, and concurrent scopes remain isolated.
709-
710-
:param correlation_id: Non-empty identifier to propagate to
711-
``x-ms-correlation-request-id``.
712-
:type correlation_id: :class:`str`
713-
:raises TypeError: If ``correlation_id`` is not a string.
714-
:raises ValueError: If ``correlation_id`` is empty after trimming.
715-
716-
Example::
717-
718-
with client.correlation_scope("6f187988-5fb4-4bd2-9f25-4d7a1c9e24ce"):
719-
client.create("account", {"name": "Scoped Run"})
720-
for batch in client.get("account", filter="statecode eq 0"):
721-
...
722-
"""
723-
724-
if not isinstance(correlation_id, str):
725-
raise TypeError("correlation_id must be str")
726-
trimmed = correlation_id.strip()
727-
if not trimmed:
728-
raise ValueError("correlation_id cannot be empty")
729-
od = self._get_odata()
730-
with od._call_scope(trimmed):
731-
yield self
732-
733-
734701
__all__ = ["DataverseClient"]

src/PowerPlatform/Dataverse/data/_odata.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,9 @@ def __init__(
154154
self._picklist_cache_ttl_seconds = 3600 # 1 hour TTL
155155

156156
@contextmanager
157-
def _call_scope(self, correlation_id: Optional[str] = None):
158-
"""Context manager to share a correlation id across nested SDK calls."""
159-
existing = _CALL_SCOPE_CORRELATION_ID.get()
160-
if correlation_id is not None:
161-
if not (_GUID_RE.fullmatch(correlation_id)):
162-
raise ValueError("correlation_id provided must be a GUID string")
163-
shared_id = correlation_id
164-
elif existing is not None:
165-
shared_id = existing
166-
else:
167-
shared_id = str(uuid.uuid4())
157+
def _call_scope(self):
158+
"""Context manager to generate a new correlation id for each SDK call scope."""
159+
shared_id = str(uuid.uuid4())
168160
token = _CALL_SCOPE_CORRELATION_ID.set(shared_id)
169161
try:
170162
yield shared_id

tests/unit/core/test_http_errors.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -182,35 +182,3 @@ def test_correlation_id_shared_inside_call_scope():
182182
assert h1["x-ms-correlation-id"] == h2["x-ms-correlation-id"]
183183

184184

185-
def test_dataverse_client_correlation_scope_accepts_guid_and_sets_header():
186-
responses = [
187-
(200, {}, {"value": []}),
188-
(200, {}, {"value": []}),
189-
]
190-
client = DataverseClient("https://org.example", DummyCredential(), DataverseConfig())
191-
mock = MockClient([])
192-
recorder = RecordingHTTP(responses)
193-
mock._http = recorder
194-
client._odata = mock
195-
guid = "2f3cbe8f-2d3d-4f0a-9bb2-1c9a1f8f0b1b"
196-
with client.correlation_scope(guid):
197-
mock._request("get", mock.api + "/accounts")
198-
mock._request("get", mock.api + "/accounts")
199-
assert len(recorder.recorded_headers) == 2
200-
h1, h2 = recorder.recorded_headers
201-
assert h1["x-ms-correlation-id"] == guid
202-
assert h2["x-ms-correlation-id"] == guid
203-
204-
205-
def test_correlation_scope_rejects_blank_identifier():
206-
client = DataverseClient("https://org.example", DummyCredential(), DataverseConfig())
207-
with pytest.raises(ValueError):
208-
with client.correlation_scope(" "):
209-
pass
210-
211-
212-
def test_correlation_scope_rejects_non_guid_identifier():
213-
client = DataverseClient("https://org.example", DummyCredential(), DataverseConfig())
214-
with pytest.raises(ValueError):
215-
with client.correlation_scope("not-a-guid"):
216-
pass

0 commit comments

Comments
 (0)