-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Description
What happened?
When setting ENABLE_SENSITIVE_DATA=true in a .env file and using load_dotenv() before calling configure_otel_providers() or enable_instrumentation(), sensitive data logging remains disabled (enable_sensitive_data stays False).
What did you expect to happen?
ENABLE_SENSITIVE_DATA=true should be respected regardless of whether it was set before or after the module was imported, since load_dotenv() populates os.environ before the user calls configure_otel_providers().
Steps to reproduce:
- Create a
.envfile withENABLE_SENSITIVE_DATA=true - In your script:
import agent_framework, then callload_dotenv(), then callconfigure_otel_providers() - Check
OBSERVABILITY_SETTINGS.enable_sensitive_data— it isFalse
Code Sample
from dotenv import load_dotenv
load_dotenv() # populates os.environ with ENABLE_SENSITIVE_DATA=true
from agent_framework.observability import configure_otel_providers, OBSERVABILITY_SETTINGS
configure_otel_providers()
print(OBSERVABILITY_SETTINGS.enable_sensitive_data) # False — should be TrueRoot Cause
OBSERVABILITY_SETTINGS = ObservabilitySettings() is constructed at module import time (line 884 of observability.py). At that point, os.environ does not yet contain the .env values because load_dotenv() hasn't been called. The cached enable_sensitive_data=False is never refreshed.
configure_otel_providers() and enable_instrumentation() force enable_instrumentation=True but do not re-read ENABLE_SENSITIVE_DATA from os.environ when the parameter is None.
The same timing issue affects VS_CODE_EXTENSION_PORT in configure_otel_providers().
Package Versions
agent-framework-core: latest (main branch)
Python Version
Python 3.13
Additional Context
This is the standard usage pattern shown in samples — load_dotenv() is called after imports but before configure_otel_providers(). The env_file_path branch of configure_otel_providers() works correctly because it constructs a fresh ObservabilitySettings(**settings_kwargs), but the common else branch (no env_file_path) does not.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status