Skip to content

Commit 86d1eae

Browse files
fixes Python: Add env_file_path parameter to setup_observability() similar to AzureOpenAIChatClient
Fixes microsoft#2186
1 parent 0413f42 commit 86d1eae

2 files changed

Lines changed: 3667 additions & 3639 deletions

File tree

‎python/packages/core/agent_framework/observability.py‎

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -662,12 +662,15 @@ def get_meter(
662662

663663

664664
def setup_observability(
665+
*,
665666
enable_sensitive_data: bool | None = None,
666667
otlp_endpoint: str | list[str] | None = None,
667668
applicationinsights_connection_string: str | list[str] | None = None,
668669
credential: "TokenCredential | None" = None,
669670
exporters: list["LogRecordExporter | SpanExporter | MetricExporter"] | None = None,
670671
vs_code_extension_port: int | None = None,
672+
env_file_path: str | None = None,
673+
env_file_encoding: str | None = None,
671674
) -> None:
672675
"""Setup observability for the application with OpenTelemetry.
673676
@@ -682,7 +685,7 @@ def setup_observability(
682685
have any effect. The reverse is also true - if you call this method first,
683686
subsequent provider configurations will not take effect.
684687
685-
Args:
688+
Keyword Args:
686689
enable_sensitive_data: Enable OpenTelemetry sensitive events. Overrides
687690
the environment variable if set. Default is None.
688691
otlp_endpoint: The OpenTelemetry Protocol (OTLP) endpoint. Will be used
@@ -698,6 +701,10 @@ def setup_observability(
698701
extensions are listening on. When set, additional OTEL exporters will be
699702
created with endpoint `http://localhost:{vs_code_extension_port}` unless
700703
already configured. Overrides the environment variable if set. Default is None.
704+
env_file_path: An optional path to a .env file to load environment variables from.
705+
Default is None.
706+
env_file_encoding: The encoding to use when loading the .env file. Default is None
707+
which uses the system default encoding.
701708
702709
Examples:
703710
.. code-block:: python
@@ -740,12 +747,23 @@ def setup_observability(
740747
)
741748
"""
742749
global OBSERVABILITY_SETTINGS
743-
# Update the observability settings with the provided values
744-
OBSERVABILITY_SETTINGS.enable_otel = True
745-
if enable_sensitive_data is not None:
746-
OBSERVABILITY_SETTINGS.enable_sensitive_data = enable_sensitive_data
747-
if vs_code_extension_port is not None:
748-
OBSERVABILITY_SETTINGS.vs_code_extension_port = vs_code_extension_port
750+
if env_file_path:
751+
OBSERVABILITY_SETTINGS = ObservabilitySettings(
752+
enable_otel=True,
753+
enable_sensitive_data=enable_sensitive_data,
754+
otlp_endpoint=otlp_endpoint,
755+
applicationinsights_connection_string=applicationinsights_connection_string,
756+
vs_code_extension_port=vs_code_extension_port,
757+
env_file_path=env_file_path,
758+
env_file_encoding=env_file_encoding,
759+
)
760+
else:
761+
# Update the observability settings with the provided values
762+
OBSERVABILITY_SETTINGS.enable_otel = True
763+
if enable_sensitive_data is not None:
764+
OBSERVABILITY_SETTINGS.enable_sensitive_data = enable_sensitive_data
765+
if vs_code_extension_port is not None:
766+
OBSERVABILITY_SETTINGS.vs_code_extension_port = vs_code_extension_port
749767

750768
# Create exporters, after checking if they are already configured through the env.
751769
new_exporters: list["LogRecordExporter | SpanExporter | MetricExporter"] = exporters or []

0 commit comments

Comments
 (0)