Skip to content

Commit 5c39fb2

Browse files
CopilotnikhilNava
andcommitted
Restore agent/tenant IDs and response text in exporter log messages
Agent IDs and tenant IDs are not sensitive data and are useful for debugging. Restore them in debug/error log messages. Also restore truncated response text in HTTP error logs to help developers debug failures. Log levels remain at DEBUG (from the prior security fix). Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com>
1 parent d3dd882 commit 5c39fb2

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

libraries/microsoft-agents-a365-observability-core/microsoft_agents_a365/observability/core/exporters/agent365_exporter.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,15 @@ def export(self, spans: Sequence[ReadableSpan]) -> SpanExportResult:
115115
"This may expose credentials in transit."
116116
)
117117
headers["authorization"] = f"Bearer {token}"
118-
logger.debug("Token resolved successfully.")
118+
logger.debug(f"Token resolved successfully for agent {agent_id}")
119119
else:
120-
logger.debug("No token returned by resolver.")
120+
logger.debug(f"No token returned for agent {agent_id}")
121121
except Exception as e:
122122
# If token resolution fails, treat as failure for this group
123-
logger.error(f"Token resolution failed: {type(e).__name__}")
123+
logger.error(
124+
f"Token resolution failed for agent {agent_id}, "
125+
f"tenant {tenant_id}: {type(e).__name__}"
126+
)
124127
any_failure = True
125128
continue
126129

@@ -195,10 +198,14 @@ def _post_with_retries(self, url: str, body: str, headers: dict[str, str]) -> bo
195198
if 200 <= resp.status_code < 300:
196199
logger.debug(
197200
f"HTTP {resp.status_code} success on attempt {attempt + 1}. "
198-
f"Correlation ID: {correlation_id}."
201+
f"Correlation ID: {correlation_id}. "
202+
f"Response: {self._truncate_text(resp.text, 200)}"
199203
)
200204
return True
201205

206+
# Log non-success responses
207+
response_text = self._truncate_text(resp.text, 500)
208+
202209
# Retry transient
203210
if resp.status_code in (408, 429) or 500 <= resp.status_code < 600:
204211
# Respect Retry-After header for 429 responses
@@ -214,13 +221,15 @@ def _post_with_retries(self, url: str, body: str, headers: dict[str, str]) -> bo
214221
logger.error(
215222
f"HTTP {resp.status_code} final failure after "
216223
f"{DEFAULT_MAX_RETRIES + 1} attempts. "
217-
f"Correlation ID: {correlation_id}."
224+
f"Correlation ID: {correlation_id}. "
225+
f"Response: {response_text}"
218226
)
219227
else:
220228
# Non-retryable error
221229
logger.error(
222230
f"HTTP {resp.status_code} non-retryable error. "
223-
f"Correlation ID: {correlation_id}."
231+
f"Correlation ID: {correlation_id}. "
232+
f"Response: {response_text}"
224233
)
225234
return False
226235

tests/observability/core/test_agent365_exporter.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,13 @@ def test_export_logging(self, mock_logger):
322322
"(tenant: test-tenant-123, agent: test-agent-456)"
323323
),
324324
# Should log token resolution success at DEBUG
325-
unittest.mock.call.debug("Token resolved successfully."),
325+
unittest.mock.call.debug(
326+
"Token resolved successfully for agent test-agent-456"
327+
),
326328
# Should log HTTP success at DEBUG
327329
unittest.mock.call.debug(
328-
"HTTP 200 success on attempt 1. Correlation ID: test-correlation-123."
330+
"HTTP 200 success on attempt 1. "
331+
"Correlation ID: test-correlation-123. Response: success"
329332
),
330333
]
331334

0 commit comments

Comments
 (0)