Address comments

This commit is contained in:
Tao Chen
2026-05-01 16:04:22 -07:00
Unverified
parent 32cda35b72
commit 10906359d6
14 changed files with 23 additions and 44 deletions
@@ -1181,6 +1181,7 @@ class TestClaudeAgentTelemetry:
mock_client = self._create_mock_client(messages)
monkeypatch.setattr(OBSERVABILITY_SETTINGS, "enable_instrumentation", False)
monkeypatch.setattr(OBSERVABILITY_SETTINGS, "enable_sensitive_data", False)
with (
patch("agent_framework_claude._agent.ClaudeSDKClient", return_value=mock_client),
@@ -691,7 +691,7 @@ class ObservabilitySettings:
Model diagnostics are enabled if either diagnostic is enabled or diagnostic with sensitive events is enabled.
"""
return self.enable_instrumentation or self.enable_sensitive_data
return self.enable_instrumentation
@property
def SENSITIVE_DATA_ENABLED(self) -> bool:
@@ -1015,30 +1015,6 @@ def test_observability_settings_is_setup_initial(monkeypatch):
assert settings.is_setup is False
@pytest.mark.parametrize(
("enable_instrumentation", "enable_sensitive_data", "expected"),
[
(False, False, False),
(True, False, True),
(False, True, True),
(True, True, True),
],
)
def test_observability_settings_enabled_property(
monkeypatch, enable_instrumentation: bool, enable_sensitive_data: bool, expected: bool
):
"""ENABLED is True when either instrumentation or sensitive data is enabled."""
from agent_framework.observability import ObservabilitySettings
monkeypatch.delenv("ENABLE_INSTRUMENTATION", raising=False)
monkeypatch.delenv("ENABLE_SENSITIVE_DATA", raising=False)
settings = ObservabilitySettings(
enable_instrumentation=enable_instrumentation,
enable_sensitive_data=enable_sensitive_data,
)
assert settings.ENABLED is expected
# region Test enable_instrumentation function
@@ -173,7 +173,7 @@ Finally we have `VS_CODE_EXTENSION_PORT` which you can set to a port, which can
The framework will emit observability data when the `ENABLE_INSTRUMENTATION` environment variable is set to `true`. If both are `true` then it will also emit sensitive information. When these are not set, or set to false, you can use the `enable_instrumentation()` function from the `agent_framework.observability` module to turn on instrumentation programmatically. This is useful when you want to control this via code instead of environment variables.
> **Note**: Sensitive information includes prompts, responses, and more, and should only be enabled in a development or test environment. It is not recommended to enable this in production environments as it may expose sensitive data. Enabling this will automatically enable instrumentation if it is not already enabled.
> **Note**: Sensitive information includes prompts, responses, and more, and should only be enabled in a development or test environment. It is not recommended to enable this in production environments as it may expose sensitive data.
The two other variables, `ENABLE_CONSOLE_EXPORTERS` and `VS_CODE_EXTENSION_PORT`, are used to configure where the observability data is sent. Those are only activated when calling `configure_otel_providers()`.
@@ -3,4 +3,5 @@ __pycache__
*.pyc
*.pyo
*.pyd
.Python
.Python
.env
@@ -3,4 +3,5 @@ __pycache__
*.pyc
*.pyo
*.pyd
.Python
.Python
.env
@@ -3,4 +3,5 @@ __pycache__
*.pyc
*.pyo
*.pyd
.Python
.Python
.env
@@ -3,4 +3,5 @@ __pycache__
*.pyc
*.pyo
*.pyd
.Python
.Python
.env
@@ -3,4 +3,5 @@ __pycache__
*.pyc
*.pyo
*.pyd
.Python
.Python
.env
@@ -4,6 +4,7 @@ __pycache__
*.pyo
*.pyd
.Python
.env
# Local-only client tooling and sample data; not needed inside the agent image.
resources/
@@ -3,4 +3,5 @@ __pycache__
*.pyc
*.pyo
*.pyd
.Python
.Python
.env
@@ -1,5 +1,4 @@
FOUNDRY_PROJECT_ENDPOINT="..."
AZURE_AI_MODEL_DEPLOYMENT_NAME="..."
ENABLE_INSTRUMENTATION=true
ENABLE_SENSITIVE_DATA=true
APPLICATIONINSIGHTS_CONNECTION_STRING="..."
ENABLE_SENSITIVE_DATA=true
@@ -16,11 +16,9 @@ The agent is hosted using the [Agent Framework](https://github.com/microsoft/age
### Instrumentation
Agent Framework is [**natively instrumented**](https://learn.microsoft.com/en-us/agent-framework/agents/observability?pivots=programming-language-python) to capture diagnostics and telemetry for agent execution, but it's turned off by default. This sample demonstrates how to enable instrumentation via environment variables in `agent.manifest.yaml` and `anget.yaml`. The relevant environment variables are `ENABLE_INSTRUMENTATION` and `ENABLE_SENSITIVE_DATA`, which can be set to `true` to enable diagnostics and capture sensitive events respectively.
Agent Framework is [**natively instrumented**](https://learn.microsoft.com/en-us/agent-framework/agents/observability?pivots=programming-language-python) to capture diagnostics and telemetry for agent execution, but it's turned off by default. This sample demonstrates how to enable instrumentation via environment variables in `agent.manifest.yaml` and `agent.yaml`. The relevant environment variables are `ENABLE_INSTRUMENTATION` and `ENABLE_SENSITIVE_DATA`, which can be set to `true` to enable diagnostics and capture sensitive events respectively.
Foundry Hosted Agent has built-in observability thus you don't need to set up exporters manually to capture telemetry from your code. The traces, metrics, and logs generated by the agent are automatically collected and made available through Foundry's observability stack via Azure Monitor/Application Insights. The `APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable is injected when the agent is deployed to Foundry, however it is still required to be set in your local `.env` file or your environment if you want to run the agent host locally and have telemetry sent to Application Insights from your local environment.
> Setting `ENABLE_SENSITIVE_DATA` to `true` will automatically enable `ENABLE_INSTRUMENTATION` as well, since capturing sensitive events requires that instrumentation be enabled.
Foundry Hosted Agent has built-in observability thus you don't need to set up exporters manually to capture telemetry from your code. The traces, metrics, and logs generated by the agent are automatically collected and made available through Foundry's observability stack via Azure Monitor/Application Insights. The `APPLICATIONINSIGHTS_CONNECTION_STRING` environment variable is injected when the agent is deployed to Foundry, however it is still required to be set in your environment if you want to run the agent host locally and have telemetry sent to Application Insights from your local environment.
## Running the Agent Host
@@ -28,12 +26,10 @@ Follow the instructions in the [Running the Agent Host Locally](../../README.md#
## Interacting with the agent
> Depending on how you run the agent host, you can invoke the agent using `curl` (`Invoke-WebRequest` in PowerShell) or `azd`. Please refer to the [parent README](../../README.md) for more details. Use this README for sample queries you can send to the agent.
Send a POST request to the server with a JSON body containing an `"input"` field to interact with the agent. For example:
> Because the observability exporters are managed by Foundry, this sample must be run using `azd ai agent run`. Run this sample using `python main.py` will not send telemetry to Application Insights.
```bash
curl -X POST http://localhost:8088/responses -H "Content-Type: application/json" -d '{"input": "What is the current weather?"}'
azd ai agent run --local "What is the current weather?"
```
A couple of spans will be created for this request from Agent Framework's instrumentation, representing the generation of the response by the agent:
@@ -16,9 +16,9 @@ from pydantic import Field
load_dotenv()
@tool(approval_mode="never_require")
@tool(approval_mode="never_require", description="Get the current location of the user.")
def get_current_location() -> str:
"""Get the current working directory."""
"""Get the current location of the agent."""
locations = ["New York", "London", "Paris", "Tokyo"]
return locations[randint(0, len(locations) - 1)]