-
Notifications
You must be signed in to change notification settings - Fork 8
Refactor existing context population code to support other scope types #119
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 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2d3ac3b
refactor existing context population code to support other scope types
jsl517 721db6c
new way to build scope using context by leverage existing start method.
jsl517 1068b20
lint
jsl517 7a4520d
Merge branch 'main' into users/pefan/contextpopulationrefactor
fpfp100 638e218
comments
jsl517 2374a11
Merge branch 'main' into users/pefan/contextpopulationrefactor
jsl517 51bc689
Merge branch 'main' into users/pefan/contextpopulationrefactor
jsl517 cc77f20
Merge branch 'users/pefan/contextpopulationrefactor' of https://githu…
jsl517 c24ff3d
comment
jsl517 1c5f913
comment
jsl517 3180957
comment
jsl517 155ccb4
Update packages/agents-a365-observability-hosting/src/utils/ScopeUtil…
fpfp100 555d41d
Update packages/agents-a365-observability-hosting/src/utils/ScopeUtil…
fpfp100 95cb6ba
Update packages/agents-a365-observability-hosting/src/utils/ScopeUtil…
fpfp100 7148d8c
more test coverages
jsl517 a1badcf
Resolve merge conflicts by keeping current (ours) changes
jsl517 830ca89
add test coverage for error scenario
jsl517 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
Some comments aren't visible on the classic Files Changed page.
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
119 changes: 0 additions & 119 deletions
119
packages/agents-a365-observability-hosting/src/utils/InvokeAgentScopeUtils.ts
This file was deleted.
Oops, something went wrong.
126 changes: 126 additions & 0 deletions
126
packages/agents-a365-observability-hosting/src/utils/ScopeUtils.ts
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,126 @@ | ||
| // ------------------------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
| // ------------------------------------------------------------------------------ | ||
|
|
||
| import { TurnContext } from '@microsoft/agents-hosting'; | ||
| import { | ||
| OpenTelemetryScope, | ||
| InvokeAgentScope, | ||
| InferenceScope, | ||
| ExecuteToolScope | ||
| } from '@microsoft/agents-a365-observability'; | ||
| import { OpenTelemetryConstants } from '@microsoft/agents-a365-observability'; | ||
| import { | ||
| getTenantIdPair, | ||
| getSourceMetadataBaggagePairs, | ||
| getConversationIdAndItemLinkPairs, | ||
| getCallerBaggagePairs, | ||
| getExecutionTypePair, | ||
| getTargetAgentBaggagePairs | ||
| } from './TurnContextUtils'; | ||
|
|
||
| /** | ||
| * Unified utilities to populate scope tags from a TurnContext. | ||
| * Provides common tag population and scope-specific helpers. | ||
| */ | ||
| export class ScopeUtils { | ||
| /** Populate common tags on any OpenTelemetryScope: tenant.id, source metadata, conversation.id */ | ||
| private static populateCommon(scope: OpenTelemetryScope, turnContext: TurnContext): void { | ||
| if (!turnContext) throw new Error('turnContext is required'); | ||
| this.setTenantIdTags(scope, turnContext); | ||
| this.setTargetAgentTags(scope, turnContext); | ||
| this.setSourceMetadataTags(scope, turnContext); | ||
| this.setConversationIdTag(scope, turnContext); | ||
| } | ||
|
|
||
| // ---------------------- | ||
| // InvokeAgent-specific setters | ||
| // ---------------------- | ||
| /** | ||
| * Sets the caller-related attribute values from the TurnContext. | ||
| */ | ||
| static setCallerTags(scope: InvokeAgentScope, turnContext: TurnContext): InvokeAgentScope { | ||
| scope.recordAttributes(getCallerBaggagePairs(turnContext)); | ||
| return scope; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the execution type tag based on caller and recipient agentic status. | ||
| */ | ||
| static setExecutionTypeTags(scope: InvokeAgentScope, turnContext: TurnContext): InvokeAgentScope { | ||
| scope.recordAttributes(getExecutionTypePair(turnContext)); | ||
| return scope; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the input message tag from the TurnContext. | ||
| */ | ||
| static setInputMessageTags(scope: InvokeAgentScope | InferenceScope, turnContext: TurnContext): InvokeAgentScope | InferenceScope { | ||
| if (turnContext?.activity?.text) { | ||
| scope.recordInputMessages([turnContext.activity.text]); | ||
| } | ||
| return scope; | ||
| } | ||
|
|
||
| // ---------------------- | ||
| // Common setters | ||
| // ---------------------- | ||
| /** | ||
| * Sets the tenant ID tag (tenant.id) from TurnContext. | ||
| */ | ||
| static setTenantIdTags(scope: OpenTelemetryScope, turnContext: TurnContext): OpenTelemetryScope { | ||
| scope.recordAttributes(getTenantIdPair(turnContext)); | ||
| return scope; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the target agent-related tags from the TurnContext. | ||
| */ | ||
| static setTargetAgentTags(scope: OpenTelemetryScope, turnContext: TurnContext): OpenTelemetryScope { | ||
| scope.recordAttributes(getTargetAgentBaggagePairs(turnContext)); | ||
| return scope; | ||
| } | ||
|
|
||
| /** | ||
| * Sets source metadata tags (channel name/description) from TurnContext. | ||
| */ | ||
| static setSourceMetadataTags(scope: OpenTelemetryScope, turnContext: TurnContext): OpenTelemetryScope { | ||
| scope.recordAttributes(getSourceMetadataBaggagePairs(turnContext)); | ||
| return scope; | ||
| } | ||
|
|
||
| /** | ||
| * Sets only the conversation id tag from TurnContext (common subset). | ||
| */ | ||
| static setConversationIdTag(scope: OpenTelemetryScope, turnContext: TurnContext): OpenTelemetryScope { | ||
| const pairs = getConversationIdAndItemLinkPairs(turnContext).filter(([key]) => key === OpenTelemetryConstants.GEN_AI_CONVERSATION_ID_KEY); | ||
| scope.recordAttributes(pairs); | ||
| return scope; | ||
| } | ||
|
|
||
| // Overloads provide precise return type based on scope subtype | ||
| static populateFromTurnContext(scope: InferenceScope, turnContext: TurnContext): InferenceScope; | ||
| static populateFromTurnContext(scope: InvokeAgentScope, turnContext: TurnContext): InvokeAgentScope; | ||
| static populateFromTurnContext(scope: ExecuteToolScope, turnContext: TurnContext): ExecuteToolScope; | ||
| static populateFromTurnContext<T extends OpenTelemetryScope>(scope: T, turnContext: TurnContext): T; | ||
|
|
||
| static populateFromTurnContext(scope: OpenTelemetryScope, turnContext: TurnContext): OpenTelemetryScope { | ||
| this.populateCommon(scope, turnContext); | ||
|
|
||
| if (scope instanceof InferenceScope) { | ||
| this.setInputMessageTags(scope, turnContext); | ||
| return scope; | ||
| } | ||
|
|
||
| if (scope instanceof InvokeAgentScope) { | ||
| this.setCallerTags(scope, turnContext); | ||
| this.setExecutionTypeTags(scope, turnContext); | ||
| this.setInputMessageTags(scope, turnContext); | ||
| return scope; | ||
| } | ||
|
|
||
| // ExecuteToolScope: only common tags | ||
| return scope; | ||
| } | ||
| } | ||
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
76 changes: 0 additions & 76 deletions
76
tests/observability/extension/hosting/InvokeAgentScopeUtils.test.ts
This file was deleted.
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.