Skip to content

Commit e88a6dd

Browse files
CopilotnikhilNava
andcommitted
Address review comments: fix logic callback type, gate on is_agentic_request
- Fix `logic` type annotation from `Callable[[TurnContext], Awaitable]` to `Callable[[], Awaitable]` in both BaggageMiddleware and OutputLoggingMiddleware. At runtime, MiddlewareSet passes a zero-arg `call_next_middleware` closure, so the annotation now matches the callsite. - Gate `_derive_agent_details` on `activity.is_agentic_request()` to avoid emitting spans with empty agent_id for non-agentic requests. - Remove unused `logging`/`logger` from baggage_middleware.py. - Update test recipient role from "assistant" to "agenticAppInstance" to exercise the intended agentic code path. Co-authored-by: nikhilNava <211831449+nikhilNava@users.noreply.github.com>
1 parent 87c1c12 commit e88a6dd

3 files changed

Lines changed: 11 additions & 7 deletions

File tree

libraries/microsoft-agents-a365-observability-hosting/microsoft_agents_a365/observability/hosting/middleware/baggage_middleware.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
from __future__ import annotations
77

8-
import logging
98
from collections.abc import Awaitable, Callable
109

1110
from microsoft_agents.activity import ActivityEventNames, ActivityTypes
@@ -14,8 +13,6 @@
1413

1514
from ..scope_helpers.populate_baggage import populate
1615

17-
logger = logging.getLogger(__name__)
18-
1916

2017
class BaggageMiddleware:
2118
"""Middleware that propagates OpenTelemetry baggage context derived from TurnContext.
@@ -26,7 +23,7 @@ class BaggageMiddleware:
2623
async def on_turn(
2724
self,
2825
context: TurnContext,
29-
logic: Callable[[TurnContext], Awaitable],
26+
logic: Callable[[], Awaitable],
3027
) -> None:
3128
activity = context.activity
3229
is_async_reply = (

libraries/microsoft-agents-a365-observability-hosting/microsoft_agents_a365/observability/hosting/middleware/output_logging_middleware.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,15 @@
4242

4343

4444
def _derive_agent_details(context: TurnContext) -> AgentDetails | None:
45-
"""Derive target agent details from the activity recipient."""
45+
"""Derive target agent details from the activity recipient.
46+
47+
Returns ``None`` when the activity is not an agentic request or the
48+
recipient is missing, so callers can short-circuit without emitting
49+
spans with empty identifiers.
50+
"""
4651
activity = context.activity
52+
if not activity.is_agentic_request():
53+
return None
4754
recipient = getattr(activity, "recipient", None)
4855
if not recipient:
4956
return None
@@ -119,7 +126,7 @@ class OutputLoggingMiddleware:
119126
async def on_turn(
120127
self,
121128
context: TurnContext,
122-
logic: Callable[[TurnContext], Awaitable],
129+
logic: Callable[[], Awaitable],
123130
) -> None:
124131
agent_details = _derive_agent_details(context)
125132
tenant_details = _derive_tenant_details(context)

tests/observability/hosting/middleware/test_output_logging_middleware.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def _make_turn_context(
3636
),
3737
"recipient": ChannelAccount(
3838
tenant_id=recipient_tenant_id,
39-
role="assistant",
39+
role="agenticAppInstance",
4040
name="Agent One",
4141
agentic_app_id=recipient_agentic_app_id,
4242
aad_object_id="agent-auid",

0 commit comments

Comments
 (0)