Skip to content

Commit 2ef297b

Browse files
authored
Add diagnostics for sdk detection (#35610)
* Add diagnostics for sdk detection * changelog
1 parent df408e8 commit 2ef297b

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

sdk/monitor/azure-monitor-opentelemetry/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
### Features Added
66

7+
- Add diagnostics for sdk detection and backoff
8+
([#35610](https://github.com/Azure/azure-sdk-for-python/pull/35610))
9+
710
### Breaking Changes
811

912
### Bugs Fixed

sdk/monitor/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_diagnostics/diagnostic_logging.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
_ATTACH_SUCCESS_CONFIGURATOR = "4201"
3434
_ATTACH_FAILURE_DISTRO = "4400"
3535
_ATTACH_FAILURE_CONFIGURATOR = "4401"
36+
_ATTACH_DETECTS_SDK = "4402"
3637

3738

3839
class AzureDiagnosticLogging:

sdk/monitor/azure-monitor-opentelemetry/azure/monitor/opentelemetry/_diagnostics/status_logger.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def _get_status_logger_file_name(pid):
2727
class AzureStatusLogger:
2828
@classmethod
2929
def _get_status_json(
30-
cls, agent_initialized_successfully, pid, reason=None
30+
cls, agent_initialized_successfully, pid, reason=None, sdk_present=None
3131
):
3232
status_json = {
3333
"AgentInitializedSuccessfully": agent_initialized_successfully,
@@ -40,14 +40,16 @@ def _get_status_json(
4040
}
4141
if reason:
4242
status_json["Reason"] = reason
43+
if sdk_present:
44+
status_json["SDKPresent"] = sdk_present
4345
return status_json
4446

4547
@classmethod
46-
def log_status(cls, agent_initialized_successfully, reason=None):
48+
def log_status(cls, agent_initialized_successfully, reason=None, sdk_present=None):
4749
if _IS_DIAGNOSTICS_ENABLED and _STATUS_LOG_PATH:
4850
pid = getpid()
4951
status_json = AzureStatusLogger._get_status_json(
50-
agent_initialized_successfully, pid, reason
52+
agent_initialized_successfully, pid, reason, sdk_present
5153
)
5254
if not exists(_STATUS_LOG_PATH):
5355
makedirs(_STATUS_LOG_PATH)

sdk/monitor/azure-monitor-opentelemetry/tests/diagnostics/test_status_logger.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def set_up(file_path, is_diagnostics_enabled=True):
6666
).start()
6767

6868

69-
def check_file_for_messages(agent_initialized_successfully, file_path, reason=None):
69+
def check_file_for_messages(agent_initialized_successfully, file_path, reason=None, sdk_present=None):
7070
with open(file_path, "r") as f:
7171
f.seek(0)
7272
json = loads(f.readline())
@@ -81,6 +81,10 @@ def check_file_for_messages(agent_initialized_successfully, file_path, reason=No
8181
assert json["Reason"] == reason
8282
else:
8383
assert "Reason" not in json
84+
if sdk_present:
85+
assert json["SDKPresent"] == sdk_present
86+
else:
87+
assert "SDKPresent" not in json
8488
assert not f.read()
8589

8690

@@ -110,6 +114,12 @@ def test_log_status_no_reason(self, temp_file_path):
110114
AzureStatusLogger.log_status(True)
111115
check_file_for_messages(True, temp_file_path)
112116

117+
def test_log_status_sdk_present(self, temp_file_path):
118+
set_up(temp_file_path, is_diagnostics_enabled=True)
119+
AzureStatusLogger.log_status(True, reason=MESSAGE1)
120+
AzureStatusLogger.log_status(False, reason=MESSAGE2, sdk_present=True)
121+
check_file_for_messages(agent_initialized_successfully=False, file_path=temp_file_path, reason=MESSAGE2, sdk_present=True)
122+
113123
def test_disabled_log_status_success(self, temp_file_path):
114124
set_up(temp_file_path, is_diagnostics_enabled=False)
115125
AzureStatusLogger.log_status(False, MESSAGE1)
@@ -128,6 +138,12 @@ def test_disabled_log_status_no_reason(self, temp_file_path):
128138
AzureStatusLogger.log_status(True)
129139
check_file_is_empty(temp_file_path)
130140

141+
def test_disabled_log_status_sdk_present(self, temp_file_path):
142+
set_up(temp_file_path, is_diagnostics_enabled=False)
143+
AzureStatusLogger.log_status(True, reason=MESSAGE1)
144+
AzureStatusLogger.log_status(False, reason=MESSAGE2, sdk_present=True)
145+
check_file_is_empty(temp_file_path)
146+
131147
@patch(
132148
"azure.monitor.opentelemetry._diagnostics.status_logger._MACHINE_NAME",
133149
TEST_MACHINE_NAME,

0 commit comments

Comments
 (0)