diff --git a/MIGRATION_A365.md b/MIGRATION_A365.md index 4b477f9a..c7d57419 100644 --- a/MIGRATION_A365.md +++ b/MIGRATION_A365.md @@ -38,6 +38,20 @@ pip uninstall -y microsoft-agents-a365-observability-extensions-agent-framework pip install microsoft-opentelemetry ``` +> If you use the hosting middleware (`BaggageMiddleware`, +> `ObservabilityHostingManager`, etc.), install the `hosting` extra, +> which pulls in `microsoft-agents-activity` and +> `microsoft-agents-hosting-core`: +> +> ```bash +> pip install "microsoft-opentelemetry[hosting]" +> ``` +> +> If those packages are not installed, importing from +> `microsoft.opentelemetry.a365.hosting` logs an error with the install +> command but does not crash; the middleware will fail at runtime when +> invoked. + ## Step 2 — Rewrite Import Paths The old packages used `microsoft_agents_a365.*` namespace. diff --git a/dev_requirements.txt b/dev_requirements.txt index 37e0ebe1..09a15ff8 100644 --- a/dev_requirements.txt +++ b/dev_requirements.txt @@ -2,3 +2,5 @@ pytest>=8.0 pytest-asyncio>=0.23.0 pytest-cov>=5.0 black>=24.0 +microsoft-agents-activity +microsoft-agents-hosting-core diff --git a/pyproject.toml b/pyproject.toml index f8d7fa49..c95f63cc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,8 +42,6 @@ dependencies = [ "opentelemetry-resource-detector-azure<1.0.0,>=0.1.5", "wrapt>=1.0", "opentelemetry-util-genai==0.3b0", - "microsoft-agents-activity>=0.9.0", - "microsoft-agents-hosting-core>=0.9.0", "aiohttp>=3.8.0", "PyJWT", "requests" @@ -59,6 +57,10 @@ agent-framework = [ openai-agents = [ "openai-agents>=0.0.7", ] +hosting = [ + "microsoft-agents-activity>=0.9.0", + "microsoft-agents-hosting-core>=0.9.0", +] test = [ "pytest>=8.0", "pytest-cov>=5.0", diff --git a/src/microsoft/opentelemetry/a365/hosting/middleware/baggage_middleware.py b/src/microsoft/opentelemetry/a365/hosting/middleware/baggage_middleware.py index d2f469e8..c652de0e 100644 --- a/src/microsoft/opentelemetry/a365/hosting/middleware/baggage_middleware.py +++ b/src/microsoft/opentelemetry/a365/hosting/middleware/baggage_middleware.py @@ -5,10 +5,18 @@ from __future__ import annotations +import logging from collections.abc import Awaitable, Callable -from microsoft_agents.activity import ActivityEventNames, ActivityTypes -from microsoft_agents.hosting.core.turn_context import TurnContext +try: + from microsoft_agents.activity import ActivityEventNames, ActivityTypes + from microsoft_agents.hosting.core.turn_context import TurnContext +except ImportError: + logging.getLogger(__name__).error( + "microsoft.opentelemetry.a365.hosting requires the agents SDK. Install the " + "packages with `pip install microsoft-opentelemetry[hosting]`.", + ) + from microsoft.opentelemetry.a365.core.middleware.baggage_builder import BaggageBuilder from microsoft.opentelemetry.a365.hosting.scope_helpers.populate_baggage import populate diff --git a/src/microsoft/opentelemetry/a365/hosting/middleware/observability_hosting_manager.py b/src/microsoft/opentelemetry/a365/hosting/middleware/observability_hosting_manager.py index 0c8f9885..ce0be13c 100644 --- a/src/microsoft/opentelemetry/a365/hosting/middleware/observability_hosting_manager.py +++ b/src/microsoft/opentelemetry/a365/hosting/middleware/observability_hosting_manager.py @@ -8,7 +8,13 @@ import logging from dataclasses import dataclass -from microsoft_agents.hosting.core.middleware_set import MiddlewareSet +try: + from microsoft_agents.hosting.core.middleware_set import MiddlewareSet +except ImportError: + logging.getLogger(__name__).error( + "microsoft.opentelemetry.a365.hosting requires the agents SDK. Install the " + "packages with `pip install microsoft-opentelemetry[hosting]`.", + ) from microsoft.opentelemetry.a365.hosting.middleware.baggage_middleware import BaggageMiddleware from microsoft.opentelemetry.a365.hosting.middleware.output_logging_middleware import OutputLoggingMiddleware diff --git a/src/microsoft/opentelemetry/a365/hosting/middleware/output_logging_middleware.py b/src/microsoft/opentelemetry/a365/hosting/middleware/output_logging_middleware.py index b5381848..ed7e1c1c 100644 --- a/src/microsoft/opentelemetry/a365/hosting/middleware/output_logging_middleware.py +++ b/src/microsoft/opentelemetry/a365/hosting/middleware/output_logging_middleware.py @@ -8,8 +8,15 @@ import logging from collections.abc import Awaitable, Callable -from microsoft_agents.activity import Activity -from microsoft_agents.hosting.core.turn_context import TurnContext +try: + from microsoft_agents.activity import Activity + from microsoft_agents.hosting.core.turn_context import TurnContext +except ImportError: + logging.getLogger(__name__).error( + "microsoft.opentelemetry.a365.hosting requires the agents SDK. Install the " + "packages with `pip install microsoft-opentelemetry[hosting]`.", + ) + from microsoft.opentelemetry.a365.core.agent_details import AgentDetails from microsoft.opentelemetry.a365.constants import ( CHANNEL_LINK_KEY, diff --git a/src/microsoft/opentelemetry/a365/hosting/scope_helpers/populate_baggage.py b/src/microsoft/opentelemetry/a365/hosting/scope_helpers/populate_baggage.py index f0e95bf1..d579586e 100644 --- a/src/microsoft/opentelemetry/a365/hosting/scope_helpers/populate_baggage.py +++ b/src/microsoft/opentelemetry/a365/hosting/scope_helpers/populate_baggage.py @@ -3,10 +3,18 @@ from __future__ import annotations +import logging from collections.abc import Iterator from typing import Any -from microsoft_agents.hosting.core.turn_context import TurnContext +try: + from microsoft_agents.hosting.core.turn_context import TurnContext +except ImportError: + logging.getLogger(__name__).error( + "microsoft.opentelemetry.a365.hosting requires the agents SDK. Install the " + "packages with `pip install microsoft-opentelemetry[hosting]`.", + ) + from microsoft.opentelemetry.a365.core.middleware.baggage_builder import BaggageBuilder from microsoft.opentelemetry.a365.hosting.scope_helpers.utils import ( diff --git a/src/microsoft/opentelemetry/a365/hosting/scope_helpers/utils.py b/src/microsoft/opentelemetry/a365/hosting/scope_helpers/utils.py index b5ab7a77..87bd0ccb 100644 --- a/src/microsoft/opentelemetry/a365/hosting/scope_helpers/utils.py +++ b/src/microsoft/opentelemetry/a365/hosting/scope_helpers/utils.py @@ -1,11 +1,20 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. +from __future__ import annotations +import logging import json from collections.abc import Iterator from typing import Any -from microsoft_agents.activity import Activity +try: + from microsoft_agents.activity import Activity +except ImportError: + logging.getLogger(__name__).error( + "microsoft.opentelemetry.a365.hosting requires the agents SDK. Install the " + "packages with `pip install microsoft-opentelemetry[hosting]`.", + ) + from microsoft.opentelemetry.a365.constants import ( CHANNEL_LINK_KEY, CHANNEL_NAME_KEY, diff --git a/src/microsoft/opentelemetry/a365/hosting/token_cache_helpers/agent_token_cache.py b/src/microsoft/opentelemetry/a365/hosting/token_cache_helpers/agent_token_cache.py index 13ad2bae..a37a186f 100644 --- a/src/microsoft/opentelemetry/a365/hosting/token_cache_helpers/agent_token_cache.py +++ b/src/microsoft/opentelemetry/a365/hosting/token_cache_helpers/agent_token_cache.py @@ -11,8 +11,14 @@ from dataclasses import dataclass from threading import Lock -from microsoft_agents.hosting.core.app.oauth.authorization import Authorization -from microsoft_agents.hosting.core.turn_context import TurnContext +try: + from microsoft_agents.hosting.core.app.oauth.authorization import Authorization + from microsoft_agents.hosting.core.turn_context import TurnContext +except ImportError: + logging.getLogger(__name__).error( + "microsoft.opentelemetry.a365.hosting requires the agents SDK. Install the " + "packages with `pip install microsoft-opentelemetry[hosting]`.", + ) logger = logging.getLogger(__name__) diff --git a/tests/a365/hosting/middleware/test_baggage_middleware.py b/tests/a365/hosting/middleware/test_baggage_middleware.py index cd8dca1c..34be3acf 100644 --- a/tests/a365/hosting/middleware/test_baggage_middleware.py +++ b/tests/a365/hosting/middleware/test_baggage_middleware.py @@ -1,11 +1,16 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. +import pytest + +pytest.importorskip("microsoft_agents.activity") +pytest.importorskip("microsoft_agents.hosting.core") + +# pylint: disable=wrong-import-position import json from typing import Any from unittest.mock import MagicMock -import pytest from microsoft_agents.activity import ( Activity, ActivityEventNames, diff --git a/tests/a365/hosting/middleware/test_observability_hosting_manager.py b/tests/a365/hosting/middleware/test_observability_hosting_manager.py index 1c3c200e..422286ce 100644 --- a/tests/a365/hosting/middleware/test_observability_hosting_manager.py +++ b/tests/a365/hosting/middleware/test_observability_hosting_manager.py @@ -1,9 +1,14 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. +import pytest + +pytest.importorskip("microsoft_agents.activity") +pytest.importorskip("microsoft_agents.hosting.core") + +# pylint: disable=wrong-import-position from unittest.mock import MagicMock -import pytest from microsoft.opentelemetry.a365.hosting.middleware.baggage_middleware import ( BaggageMiddleware, ) diff --git a/tests/a365/hosting/middleware/test_output_logging_middleware.py b/tests/a365/hosting/middleware/test_output_logging_middleware.py index a17ac1ef..7b40bfbc 100644 --- a/tests/a365/hosting/middleware/test_output_logging_middleware.py +++ b/tests/a365/hosting/middleware/test_output_logging_middleware.py @@ -1,9 +1,14 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. +import pytest + +pytest.importorskip("microsoft_agents.activity") +pytest.importorskip("microsoft_agents.hosting.core") + +# pylint: disable=wrong-import-position from unittest.mock import AsyncMock, MagicMock, patch -import pytest from microsoft_agents.activity import ( Activity, ChannelAccount, diff --git a/tests/a365/hosting/scope_helpers/test_populate_baggage.py b/tests/a365/hosting/scope_helpers/test_populate_baggage.py index 4e90f0c4..d3ce5fc3 100644 --- a/tests/a365/hosting/scope_helpers/test_populate_baggage.py +++ b/tests/a365/hosting/scope_helpers/test_populate_baggage.py @@ -1,6 +1,12 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. +import pytest + +pytest.importorskip("microsoft_agents.activity") +pytest.importorskip("microsoft_agents.hosting.core") + +# pylint: disable=wrong-import-position from unittest.mock import MagicMock from microsoft_agents.activity import Activity, ChannelAccount, ConversationAccount diff --git a/tests/a365/hosting/scope_helpers/test_populate_invoke_agent_scope.py b/tests/a365/hosting/scope_helpers/test_populate_invoke_agent_scope.py index 102843cc..c50a7f6a 100644 --- a/tests/a365/hosting/scope_helpers/test_populate_invoke_agent_scope.py +++ b/tests/a365/hosting/scope_helpers/test_populate_invoke_agent_scope.py @@ -1,10 +1,15 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. +import pytest + +pytest.importorskip("microsoft_agents.activity") +pytest.importorskip("microsoft_agents.hosting.core") + +# pylint: disable=wrong-import-position import os from unittest.mock import MagicMock -import pytest from microsoft_agents.activity import Activity, ChannelAccount, ConversationAccount from microsoft_agents.hosting.core import TurnContext from microsoft.opentelemetry.a365.core.agent_details import AgentDetails diff --git a/tests/a365/hosting/scope_helpers/test_scope_helper_utils.py b/tests/a365/hosting/scope_helpers/test_scope_helper_utils.py index 8d0ee845..d4582aee 100644 --- a/tests/a365/hosting/scope_helpers/test_scope_helper_utils.py +++ b/tests/a365/hosting/scope_helpers/test_scope_helper_utils.py @@ -1,6 +1,11 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. +import pytest + +pytest.importorskip("microsoft_agents.activity") + +# pylint: disable=wrong-import-position from microsoft_agents.activity import Activity, ChannelAccount, ConversationAccount from microsoft.opentelemetry.a365.core.constants import ( CHANNEL_LINK_KEY, diff --git a/tests/a365/hosting/token_cache_helpers/test_agent_token_cache.py b/tests/a365/hosting/token_cache_helpers/test_agent_token_cache.py index 90130699..af0ac9a1 100644 --- a/tests/a365/hosting/token_cache_helpers/test_agent_token_cache.py +++ b/tests/a365/hosting/token_cache_helpers/test_agent_token_cache.py @@ -3,10 +3,14 @@ """Tests for AgenticTokenCache and AgenticTokenStruct.""" +import pytest + +pytest.importorskip("microsoft_agents.hosting.core") + +# pylint: disable=wrong-import-position import threading from unittest.mock import AsyncMock, MagicMock -import pytest from microsoft_agents.hosting.core.app.oauth.authorization import Authorization from microsoft_agents.hosting.core.turn_context import TurnContext from microsoft.opentelemetry.a365.hosting.token_cache_helpers import (