Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
)
from ..models.operation_source import OperationSource
from ..utils import deprecated, validate_and_normalize_ip
from .turn_context_baggage import from_turn_context

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -232,14 +231,6 @@ def channel_links(self, value: str | None) -> "BaggageBuilder":
self._set(GEN_AI_EXECUTION_SOURCE_DESCRIPTION_KEY, value)
return self

def from_turn_context(self, turn_context: Any) -> "BaggageBuilder":
"""
Populate baggage from a turn_context (duck-typed).
Delegates to baggage_turn_context.from_turn_context.
"""

return self.set_pairs(from_turn_context(turn_context))

def set_pairs(self, pairs: Any) -> "BaggageBuilder":
"""
Accept dict or iterable of (k,v).
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Microsoft Agent 365 Observability Hosting Library

This library provides hosting components for Agent 365 observability.

## Installation

```bash
pip install microsoft-agents-a365-observability-hosting
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

"""
Microsoft Agent 365 Observability Hosting Library.
"""
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from __future__ import annotations

from collections.abc import Iterator
from typing import Any

from microsoft_agents.hosting.core.turn_context import TurnContext
from microsoft_agents_a365.observability.core.middleware.baggage_builder import BaggageBuilder

from .utils import (
get_caller_pairs,
get_conversation_pairs,
get_execution_type_pair,
get_source_metadata_pairs,
get_target_agent_pairs,
get_tenant_id_pair,
)


def _iter_all_pairs(turn_context: TurnContext) -> Iterator[tuple[str, Any]]:
activity = turn_context.activity
if not activity:
return
yield from get_caller_pairs(activity)
yield from get_execution_type_pair(activity)
yield from get_target_agent_pairs(activity)
yield from get_tenant_id_pair(activity)
yield from get_source_metadata_pairs(activity)
yield from get_conversation_pairs(activity)


def populate(builder: BaggageBuilder, turn_context: TurnContext) -> BaggageBuilder:
"""Populate BaggageBuilder with baggage values extracted from a turn context.

Args:
builder: The BaggageBuilder instance to populate
turn_context: The TurnContext containing activity information

Returns:
The updated BaggageBuilder instance (for method chaining)
"""
builder.set_pairs(_iter_all_pairs(turn_context))
return builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from microsoft_agents_a365.observability.core.invoke_agent_scope import InvokeAgentScope

from .utils import (
get_caller_pairs,
get_conversation_pairs,
get_execution_type_pair,
get_source_metadata_pairs,
get_target_agent_pairs,
get_tenant_id_pair,
)

if TYPE_CHECKING:
from microsoft_agents.hosting.core.turn_context import TurnContext


def populate(scope: InvokeAgentScope, turn_context: TurnContext) -> InvokeAgentScope:
"""
Populate all supported InvokeAgentScope tags from the provided TurnContext.
:param scope: The InvokeAgentScope instance to populate.
:param turn_context: The TurnContext containing activity information.
:return: The updated InvokeAgentScope instance.
"""
if not turn_context:
raise ValueError("turn_context is required")

if not turn_context.activity:
return scope

activity = turn_context.activity

scope.record_attributes(get_caller_pairs(activity))
scope.record_attributes(get_execution_type_pair(activity))
scope.record_attributes(get_target_agent_pairs(activity))
scope.record_attributes(get_tenant_id_pair(activity))
scope.record_attributes(get_source_metadata_pairs(activity))
scope.record_attributes(get_conversation_pairs(activity))

if activity.text:
scope.record_input_messages([activity.text])

return scope
Loading
Loading