Skip to content

Commit d08bf30

Browse files
authored
[Cosmos] deprecating old diagnostics (Azure#31133)
* removing old diagnostics * remove weird uses of record diagnostics * Revert "removing old diagnostics" This reverts commit a6d69c1. * mark diagnostics.py for deprecation * Update diagnostics.py * Update diagnostics.py * Update test_diagnostics.py * Update diagnostics.py * CaseInsensitiveDict from azrue.core * errors importing case insensitive dict which we don't need anyway * Update test_diagnostics.py * module-level get_attr returns warning * Update diagnostics.py * Update diagnostics.py * commenting this out to see if pipelines still fail * retrying the get_attr * Update diagnostics.py * Update diagnostics.py * remove caseinsensitivedict * Update test_diagnostics.py * update core version * Update test_diagnostics.py * Update CHANGELOG.md
1 parent 3285b56 commit d08bf30

File tree

7 files changed

+33
-27
lines changed

7 files changed

+33
-27
lines changed

sdk/cosmos/azure-cosmos/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99
#### Bugs Fixed
1010

1111
#### Other Changes
12+
* Marked the outdated `diagnostics.py` file for deprecation since we now recommend the use of our `CosmosHttpLoggingPolicy` for diagnostics.
13+
For more on the `CosmosHttpLoggingPolicy` see our [README](https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/cosmos/azure-cosmos#logging-diagnostics).
1214

1315
### 4.5.1 (2023-09-12)
1416

1517
#### Bugs Fixed
1618
* Fixed bug when query with DISTINCT + OFFSET/LIMIT operators returns unexpected result. See [PR 31925](https://github.com/Azure/azure-sdk-for-python/pull/31925).
1719

1820
#### Other Changes
19-
- Added additional checks for resource creation using specific characters that cause issues. See [PR 31861](https://github.com/Azure/azure-sdk-for-python/pull/31861).
21+
* Added additional checks for resource creation using specific characters that cause issues. See [PR 31861](https://github.com/Azure/azure-sdk-for-python/pull/31861).
2022

2123
### 4.5.0 (2023-08-09)
2224

sdk/cosmos/azure-cosmos/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,10 +607,10 @@ HTTP status code 409: The ID (name) provided for the container is already in use
607607
The container name must be unique within the database.""")
608608

609609
```
610-
### Logging
610+
### Logging Diagnostics
611611

612612
This library uses the standard
613-
[logging](https://docs.python.org/3.5/library/logging.html) library for logging.
613+
[logging](https://docs.python.org/3.5/library/logging.html) library for logging diagnostics.
614614
Basic information about HTTP sessions (URLs, headers, etc.) is logged at INFO
615615
level.
616616

sdk/cosmos/azure-cosmos/azure/cosmos/diagnostics.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,19 @@
2020
# SOFTWARE.
2121

2222
"""Diagnostic tools for Azure Cosmos database service operations.
23+
IMPORTANT: This file has been marked for deprecation and will be removed in the future. For diagnostics logging in our
24+
SDK, please use our CosmosHttpLoggingPolicy outlined in our README.
2325
"""
2426

25-
from requests.structures import CaseInsensitiveDict
27+
from azure.core.utils import CaseInsensitiveDict
28+
import warnings
2629

2730

28-
class RecordDiagnostics(object):
29-
"""Record Response headers from Cosmos read operations.
31+
class _RecordDiagnostics(object):
32+
"""This file is currently deprecated and will be removed in the future. Please use our CosmosHttpLoggingPolicy
33+
for logging SDK diagnostics moving forward. More information on this can be found in our README.
34+
35+
Record Response headers from Cosmos read operations.
3036
3137
The full response headers are stored in the ``headers`` property.
3238
@@ -84,3 +90,16 @@ def __getattr__(self, name):
8490
if key in self._common:
8591
return self._headers[key]
8692
raise AttributeError(name)
93+
94+
95+
def __getattr__(name):
96+
if name == 'RecordDiagnostics':
97+
warnings.warn(
98+
"RecordDiagnostics is deprecated and should not be used. " +
99+
"For logging diagnostics information for the SDK, please use our CosmosHttpLoggingPolicy. " +
100+
"For more information on this, please see our README.",
101+
DeprecationWarning
102+
)
103+
return _RecordDiagnostics
104+
105+
raise AttributeError(f"module 'azure.cosmos.diagnostics' has no attribute {name}")

sdk/cosmos/azure-cosmos/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@
7272
packages=find_packages(exclude=exclude_packages),
7373
python_requires=">=3.6",
7474
install_requires=[
75-
'azure-core<2.0.0,>=1.23.0'
75+
'azure-core<2.0.0,>=1.25.0'
7676
],
7777
)

sdk/cosmos/azure-cosmos/test/test_crud.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import test_config
4444
import azure.cosmos._base as base
4545
import azure.cosmos.cosmos_client as cosmos_client
46-
from azure.cosmos.diagnostics import RecordDiagnostics
4746
from azure.cosmos.partition_key import PartitionKey
4847
from azure.cosmos import _retry_utility
4948
import requests
@@ -210,16 +209,10 @@ def test_collection_crud(self):
210209
before_create_collections_count = len(collections)
211210
collection_id = 'test_collection_crud ' + str(uuid.uuid4())
212211
collection_indexing_policy = {'indexingMode': 'consistent'}
213-
created_recorder = RecordDiagnostics()
214212
created_collection = created_db.create_container(id=collection_id,
215213
indexing_policy=collection_indexing_policy,
216-
partition_key=PartitionKey(path="/pk", kind="Hash"),
217-
response_hook=created_recorder)
214+
partition_key=PartitionKey(path="/pk", kind="Hash"))
218215
self.assertEqual(collection_id, created_collection.id)
219-
assert isinstance(created_recorder.headers, Mapping)
220-
assert 'Content-Type' in created_recorder.headers
221-
assert isinstance(created_recorder.body, Mapping)
222-
assert 'id' in created_recorder.body
223216

224217
created_properties = created_collection.read()
225218
self.assertEqual('consistent', created_properties['indexingPolicy']['indexingMode'])

sdk/cosmos/azure-cosmos/test/test_crud_async.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
from azure.cosmos.http_constants import HttpHeaders, StatusCodes
4141
import azure.cosmos._base as base
4242
from azure.cosmos.aio import CosmosClient, _retry_utility_async
43-
from azure.cosmos.diagnostics import RecordDiagnostics
4443
from azure.cosmos.partition_key import PartitionKey
4544
import requests
4645
from urllib3.util.retry import Retry
@@ -198,16 +197,10 @@ async def test_collection_crud(self):
198197
before_create_collections_count = len(collections)
199198
collection_id = 'test_collection_crud ' + str(uuid.uuid4())
200199
collection_indexing_policy = {'indexingMode': 'consistent'}
201-
created_recorder = RecordDiagnostics()
202200
created_collection = await created_db.create_container(id=collection_id,
203201
indexing_policy=collection_indexing_policy,
204-
partition_key=PartitionKey(path="/pk", kind="Hash"),
205-
response_hook=created_recorder)
202+
partition_key=PartitionKey(path="/pk", kind="Hash"))
206203
self.assertEqual(collection_id, created_collection.id)
207-
assert isinstance(created_recorder.headers, Mapping)
208-
assert 'Content-Type' in created_recorder.headers
209-
assert isinstance(created_recorder.body, Mapping)
210-
assert 'id' in created_recorder.body
211204

212205
created_properties = await created_collection.read()
213206
self.assertEqual('consistent', created_properties['indexingPolicy']['indexingMode'])

sdk/cosmos/azure-cosmos/test/test_diagnostics.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import unittest
21
import pytest
32
import azure.cosmos.diagnostics as m
43

54
_common = {
65
'x-ms-activity-id',
76
'x-ms-session-token',
8-
97
'x-ms-item-count',
108
'x-ms-request-quota',
119
'x-ms-resource-usage',
@@ -15,7 +13,8 @@
1513
_headers = dict(zip(_common, _common))
1614
_headers['other'] = 'other'
1715

18-
class BaseUnitTests(unittest.TestCase):
16+
17+
class TestOldDiagnostics:
1918

2019
def test_init(self):
2120
rh = m.RecordDiagnostics()
@@ -33,7 +32,7 @@ def test_headers_case(self):
3332
rh_headers = rh.headers
3433
for key in rh.headers.keys():
3534
assert key.upper() in rh_headers
36-
assert key.lower() in rh_headers
35+
assert key.lower() in rh_headers
3736

3837
def test_common_attrs(self):
3938
rh = m.RecordDiagnostics()

0 commit comments

Comments
 (0)