diff --git a/src/promptflow-devkit/CHANGELOG.md b/src/promptflow-devkit/CHANGELOG.md index a1983e82aef..b23171a1da8 100644 --- a/src/promptflow-devkit/CHANGELOG.md +++ b/src/promptflow-devkit/CHANGELOG.md @@ -1,5 +1,10 @@ # promptflow-devkit package +## v1.13.0 (Upcoming) + +### Bugs Fixed +- Fix incompatibility with `trace.NoOpTracerProvider` when set exporter to prompt flow service. + ## v1.12.0 (2024.06.11) ### Improvements diff --git a/src/promptflow-devkit/promptflow/_sdk/_tracing.py b/src/promptflow-devkit/promptflow/_sdk/_tracing.py index 5eeff36df49..6c1bb9b8ff3 100644 --- a/src/promptflow-devkit/promptflow/_sdk/_tracing.py +++ b/src/promptflow-devkit/promptflow/_sdk/_tracing.py @@ -550,6 +550,10 @@ def setup_exporter_to_pfs() -> None: tracer_provider: TracerProvider = trace.get_tracer_provider() if is_exporter_setup_skipped(): _logger.debug("exporter setup is skipped according to environment variable.") + elif isinstance(tracer_provider, trace.NoOpTracerProvider): + _logger.warning( + "tracer provider is set to NoOpTracerProvider, skip setting exporter to prompt flow service." + ) else: if not getattr(tracer_provider, TRACER_PROVIDER_PFS_EXPORTER_SET_ATTR, False): _logger.info("have not set exporter to prompt flow service, will set it...") diff --git a/src/promptflow-devkit/tests/sdk_cli_test/unittests/test_trace.py b/src/promptflow-devkit/tests/sdk_cli_test/unittests/test_trace.py index a1ac05f487e..d24e8a4c25e 100644 --- a/src/promptflow-devkit/tests/sdk_cli_test/unittests/test_trace.py +++ b/src/promptflow-devkit/tests/sdk_cli_test/unittests/test_trace.py @@ -33,7 +33,7 @@ TRACE_LIST_DEFAULT_LIMIT, ContextAttributeKey, ) -from promptflow._sdk._tracing import start_trace_with_devkit +from promptflow._sdk._tracing import setup_exporter_to_pfs, start_trace_with_devkit from promptflow._sdk._utilities.tracing_utils import WorkspaceKindLocalCache, append_conditions, parse_protobuf_span from promptflow.client import PFClient from promptflow.exceptions import UserErrorException @@ -196,6 +196,20 @@ def test_pfs_invocation_failed_in_start_trace(self): start_trace_with_devkit(collection=str(uuid.uuid4())) assert monitor_func.call_count == 0 + @pytest.mark.usefixtures("reset_tracer_provider") + def test_no_op_tracer_provider(self, monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture): + # logger with "promptflow." prefix cannot be captured by caplog, so patch the logger for this test + with patch("promptflow._sdk._tracing._logger", logging.getLogger(__name__)): + with caplog.at_level(level=logging.WARNING): + monkeypatch.setenv(OTEL_EXPORTER_OTLP_ENDPOINT, "http://dummy-endpoint") + trace.set_tracer_provider(trace.NoOpTracerProvider()) + setup_exporter_to_pfs() + monkeypatch.delenv(OTEL_EXPORTER_OTLP_ENDPOINT) + assert ( + "tracer provider is set to NoOpTracerProvider, skip setting exporter to prompt flow service." + in caplog.text + ) + @pytest.mark.unittest @pytest.mark.sdk_test diff --git a/src/promptflow/CHANGELOG.md b/src/promptflow/CHANGELOG.md index ea4ab49ff8e..09a5620d4d7 100644 --- a/src/promptflow/CHANGELOG.md +++ b/src/promptflow/CHANGELOG.md @@ -1,4 +1,10 @@ # Release History + +## v1.13.0 (Upcoming) + +### Bugs Fixed +- Fix incompatibility with `trace.NoOpTracerProvider` when set exporter to prompt flow service. + ## v1.12.0 (2024.06.11) ### Bugs fixed