-
Notifications
You must be signed in to change notification settings - Fork 10
Add OutputScope for output message tracing with parent span linking #164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
765af45
Initial plan
Copilot 482cb38
Add OutputScope for output message tracing
Copilot 53bd58d
Improve Response.messages field documentation
Copilot 9ddca17
Add parent_id parameter to OutputScope
Copilot 2274828
Add parent_id to base OpenTelemetryScope class
Copilot f1e7c5d
Make record_output_messages append messages instead of replacing
Copilot f902aad
Fix parent_id to set on span context instead of span attribute
Copilot b965b0f
Move parse_parent_id_to_context to utils.py
Copilot fb08009
Clean up test_output_scope.py - remove redundant tests and aggregate …
Copilot d36e3e8
Merge branch 'main' into copilot/extract-output-span-changes
nikhilNava 3901fa4
address PR comments
nikhilc-microsoft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
...gents-a365-observability-core/microsoft_agents_a365/observability/core/models/response.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| from dataclasses import dataclass | ||
|
|
||
|
|
||
| @dataclass | ||
| class Response: | ||
| """Response details from agent execution.""" | ||
|
|
||
| """The list of response messages from the agent.""" | ||
| messages: list[str] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
...a365-observability-core/microsoft_agents_a365/observability/core/spans_scopes/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. |
78 changes: 78 additions & 0 deletions
78
...-observability-core/microsoft_agents_a365/observability/core/spans_scopes/output_scope.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| from ..agent_details import AgentDetails | ||
| from ..constants import GEN_AI_OUTPUT_MESSAGES_KEY | ||
| from ..models.response import Response | ||
| from ..opentelemetry_scope import OpenTelemetryScope | ||
| from ..tenant_details import TenantDetails | ||
| from ..utils import safe_json_dumps | ||
|
|
||
| OUTPUT_OPERATION_NAME = "output_messages" | ||
|
|
||
|
|
||
nikhilNava marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| class OutputScope(OpenTelemetryScope): | ||
| """Provides OpenTelemetry tracing scope for output messages.""" | ||
|
|
||
| @staticmethod | ||
| def start( | ||
| agent_details: AgentDetails, | ||
| tenant_details: TenantDetails, | ||
| response: Response, | ||
| parent_id: str | None = None, | ||
| ) -> "OutputScope": | ||
| """Creates and starts a new scope for output tracing. | ||
|
|
||
| Args: | ||
| agent_details: The details of the agent | ||
| tenant_details: The details of the tenant | ||
| response: The response details from the agent | ||
| parent_id: Optional parent Activity ID used to link this span to an upstream | ||
| operation | ||
|
|
||
| Returns: | ||
| A new OutputScope instance | ||
| """ | ||
| return OutputScope(agent_details, tenant_details, response, parent_id) | ||
nikhilNava marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| def __init__( | ||
| self, | ||
| agent_details: AgentDetails, | ||
| tenant_details: TenantDetails, | ||
| response: Response, | ||
| parent_id: str | None = None, | ||
| ): | ||
| """Initialize the output scope. | ||
|
|
||
| Args: | ||
| agent_details: The details of the agent | ||
| tenant_details: The details of the tenant | ||
| response: The response details from the agent | ||
| parent_id: Optional parent Activity ID used to link this span to an upstream | ||
| operation | ||
| """ | ||
| super().__init__( | ||
| kind="Client", | ||
| operation_name=OUTPUT_OPERATION_NAME, | ||
| activity_name=(f"{OUTPUT_OPERATION_NAME} {agent_details.agent_id}"), | ||
| agent_details=agent_details, | ||
| tenant_details=tenant_details, | ||
| parent_id=parent_id, | ||
| ) | ||
|
|
||
| # Initialize accumulated messages list | ||
| self._output_messages: list[str] = list(response.messages) | ||
|
|
||
| # Set response messages | ||
| self.set_tag_maybe(GEN_AI_OUTPUT_MESSAGES_KEY, safe_json_dumps(self._output_messages)) | ||
|
|
||
| def record_output_messages(self, messages: list[str]) -> None: | ||
| """Records the output messages for telemetry tracking. | ||
|
|
||
| Appends the provided messages to the accumulated output messages list. | ||
|
|
||
| Args: | ||
| messages: List of output messages to append | ||
| """ | ||
| self._output_messages.extend(messages) | ||
| self.set_tag_maybe(GEN_AI_OUTPUT_MESSAGES_KEY, safe_json_dumps(self._output_messages)) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.