-
Notifications
You must be signed in to change notification settings - Fork 86
Instrument Proactive #399
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
Rodrigo Brandão (rodrigobr-msft)
merged 8 commits into
main
from
users/robrandao/instrument-proactive
May 19, 2026
Merged
Instrument Proactive #399
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bc56a76
Adding proactive instrumentation
rodrigobr-msft 5f2437b
Instrumenting proactive scenarios and testing that functionality
rodrigobr-msft 08f788e
removing unnecessary import
rodrigobr-msft e7ed505
Revising attribute names
rodrigobr-msft 294b018
Potential fix for pull request finding
rodrigobr-msft 5e63de1
Edit to comment
rodrigobr-msft 7fd9346
Merge branch 'main' of https://github.com/microsoft/Agents-for-python…
rodrigobr-msft 32f1835
Fixing conflict
rodrigobr-msft 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
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
Empty file.
9 changes: 9 additions & 0 deletions
9
...ft-agents-hosting-core/microsoft_agents/hosting/core/app/proactive/telemetry/constants.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,9 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| SPAN_STORE_CONVERSATION = "agents.proactive.store_conversation" | ||
| SPAN_GET_CONVERSATION = "agents.proactive.get_conversation" | ||
| SPAN_DELETE_CONVERSATION = "agents.proactive.delete_conversation" | ||
| SPAN_SEND_ACTIVITY = "agents.proactive.send_activity" | ||
| SPAN_CONTINUE_CONVERSATION = "agents.proactive.continue_conversation" | ||
| SPAN_CREATE_CONVERSATION = "agents.proactive.create_conversation" |
142 changes: 142 additions & 0 deletions
142
...rosoft-agents-hosting-core/microsoft_agents/hosting/core/app/proactive/telemetry/spans.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,142 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from microsoft_agents.activity import Activity | ||
| from microsoft_agents.hosting.core.telemetry import ( | ||
| AttributeMap, | ||
| attributes, | ||
| SimpleSpanWrapper, | ||
| ) | ||
| from . import constants | ||
| from ..create_conversation_options import CreateConversationOptions | ||
|
|
||
|
|
||
| class ProactiveStoreConversation(SimpleSpanWrapper): | ||
| """Span for storing a conversation reference in proactive scenarios, starting from when the store operation is initiated until it is completed. This span can be used to correlate telemetry related to storing conversation references in proactive scenarios.""" | ||
|
|
||
| def __init__(self, conversation_id: str): | ||
| """Initializes the ProactiveStoreConversation SpanWrapper. | ||
|
|
||
| :param conversation_id: The ID of the conversation being stored, used to extract attributes for the span | ||
| """ | ||
| super().__init__(constants.SPAN_STORE_CONVERSATION) | ||
| self._conversation_id = conversation_id | ||
|
|
||
| def _get_attributes(self) -> AttributeMap: | ||
| return { | ||
| attributes.CONVERSATION_ID: self._conversation_id or attributes.UNKNOWN, | ||
| } | ||
|
|
||
|
|
||
| class ProactiveGetConversation(SimpleSpanWrapper): | ||
| """Span for getting a conversation reference in proactive scenarios.""" | ||
|
|
||
| def __init__(self, conversation_id: str): | ||
| """Initializes the ProactiveGetConversation SpanWrapper. | ||
|
|
||
| :param conversation_id: The ID of the conversation being retrieved, used to extract attributes for the span | ||
| """ | ||
| super().__init__(constants.SPAN_GET_CONVERSATION) | ||
| self._conversation_id = conversation_id | ||
| self._found: bool | None = None | ||
|
|
||
| def _get_attributes(self) -> AttributeMap: | ||
| return { | ||
| attributes.CONVERSATION_ID: self._conversation_id or attributes.UNKNOWN, | ||
| attributes.CONVERSATION_FOUND: ( | ||
| self._found if self._found is not None else attributes.UNKNOWN | ||
| ), | ||
| } | ||
|
|
||
| def share(self, found: bool) -> None: | ||
| """Records to the span whether the conversation being retrieved was found. | ||
|
|
||
| :param found: Whether the conversation being retrieved was found | ||
| """ | ||
| self._found = found | ||
|
|
||
|
|
||
| class ProactiveDeleteConversation(SimpleSpanWrapper): | ||
| """Span for deleting a conversation reference in proactive scenarios, starting from when the delete operation is initiated until it is completed. This span can be used to correlate telemetry related to deleting conversation references in proactive scenarios.""" | ||
|
|
||
| def __init__(self, conversation_id: str): | ||
| """Initializes the ProactiveDeleteConversation SpanWrapper. | ||
|
|
||
| :param conversation_id: The ID of the conversation being deleted, used to extract attributes for the span | ||
| """ | ||
| super().__init__(constants.SPAN_DELETE_CONVERSATION) | ||
| self._conversation_id = conversation_id | ||
|
|
||
| def _get_attributes(self) -> AttributeMap: | ||
| return { | ||
| attributes.CONVERSATION_ID: self._conversation_id or attributes.UNKNOWN, | ||
| } | ||
|
|
||
|
|
||
| class ProactiveSendActivity(SimpleSpanWrapper): | ||
| """Span for sending an activity in proactive scenarios, starting from when the send operation is initiated until it is completed. This span can be used to correlate telemetry related to sending activities in proactive scenarios.""" | ||
|
|
||
| def __init__(self, conversation_id: str, activity: Activity): | ||
| """Initializes the ProactiveSendActivity SpanWrapper. | ||
|
|
||
| :param conversation_id: The ID of the conversation the activity is being sent to, used to extract attributes for the span | ||
| :param activity: The activity being sent, used to extract attributes for the span | ||
| """ | ||
| super().__init__(constants.SPAN_SEND_ACTIVITY) | ||
| self._conversation_id = conversation_id | ||
| self._activity = activity | ||
|
|
||
| def _get_attributes(self) -> AttributeMap: | ||
| return { | ||
| attributes.CONVERSATION_ID: self._conversation_id or attributes.UNKNOWN, | ||
| attributes.ACTIVITY_TYPE: self._activity.type or attributes.UNKNOWN, | ||
| attributes.ACTIVITY_CHANNEL_ID: self._activity.channel_id | ||
| or attributes.UNKNOWN, | ||
| } | ||
|
|
||
|
|
||
| class ProactiveContinueConversation(SimpleSpanWrapper): | ||
| """Span for continuing a conversation in proactive scenarios, starting from when the continue operation is initiated until it is completed. This span can be used to correlate telemetry related to continuing conversations in proactive scenarios.""" | ||
|
|
||
| def __init__(self, conversation_id: str, activity: Activity): | ||
| """Initializes the ProactiveContinueConversation SpanWrapper. | ||
|
|
||
| :param conversation_id: The ID of the conversation being continued, used to extract attributes for the span | ||
| :param activity: The activity being sent, used to extract attributes for the span | ||
| """ | ||
| super().__init__(constants.SPAN_CONTINUE_CONVERSATION) | ||
| self._conversation_id = conversation_id | ||
| self._activity = activity | ||
|
|
||
| def _get_attributes(self) -> AttributeMap: | ||
| return { | ||
| attributes.CONVERSATION_ID: self._conversation_id or attributes.UNKNOWN, | ||
| attributes.ACTIVITY_TYPE: self._activity.type or attributes.UNKNOWN, | ||
| attributes.ACTIVITY_CHANNEL_ID: self._activity.channel_id | ||
| or attributes.UNKNOWN, | ||
| } | ||
|
|
||
|
|
||
| class ProactiveCreateConversation(SimpleSpanWrapper): | ||
| """Span for creating a conversation in proactive scenarios, starting from when the create operation is initiated until it is completed. This span can be used to correlate telemetry related to creating conversations in proactive scenarios.""" | ||
|
|
||
| def __init__(self, options: CreateConversationOptions): | ||
| """Initializes the ProactiveCreateConversation SpanWrapper. | ||
|
|
||
| :param options: The options used to create the conversation, used to extract attributes for the span | ||
| """ | ||
| super().__init__(constants.SPAN_CREATE_CONVERSATION) | ||
| self._channel_id = options.channel_id | ||
| self._members_count: str | int = ( | ||
| len(options.parameters.members) | ||
| if options.parameters and options.parameters.members | ||
|
rodrigobr-msft marked this conversation as resolved.
|
||
| else attributes.UNKNOWN | ||
| ) | ||
|
|
||
| def _get_attributes(self) -> AttributeMap: | ||
| return { | ||
| attributes.ACTIVITY_CHANNEL_ID: self._channel_id, | ||
| attributes.MEMBERS_COUNT: self._members_count, | ||
| } | ||
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
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.
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.