-
Notifications
You must be signed in to change notification settings - Fork 8
Use Agent365ExporterOptions for exporter and create AgenticTokenCache… #46
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 4 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
996b5e7
use Agent365ExporterOptions for exporter and create AgenticTokenCache…
jsl517 9c50c72
tests
jsl517 51b4d86
copilot comment
jsl517 a0de073
configure batch span processor
jsl517 88605eb
copilot comment
jsl517 ca17b96
checkpoint to use cached context and authorization to exchange token.
jsl517 1b89510
only do refresh token in message handler, unit tests
jsl517 fa95349
sample update
jsl517 1c3940e
comments
jsl517 36c5966
comments
jsl517 3d174b3
observability always use prod
jsl517 9ca9f6a
Merge branch 'main' into users/pefan/exportoption
jsl517 7271de5
should be lowercase
jsl517 ea0cfc6
Revert "observability always use prod"
jsl517 5221582
Merge branch 'main' into users/pefan/exportoption
jsl517 64728ca
default to prod
jsl517 f1d9e61
expose Agent365ExporterOptions
jsl517 e07318b
expose Agent365ExporterOptions
jsl517 057aae7
move azure token cache to its own package
jsl517 20133be
readme update
jsl517 d322096
Merge branch 'main' into users/pefan/exportoption
jsl517 6058c84
fix package.json error
jsl517 1149e09
fix logging
jsl517 5e3d93b
lint,jest config
jsl517 55b5536
cleanup
jsl517 cf31254
comment
jsl517 142ec28
rename
jsl517 54ddd3e
lint
jsl517 5303929
comment
jsl517 0b11ffa
Merge branch 'main' into users/pefan/exportoption
fpfp100 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
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
49 changes: 49 additions & 0 deletions
49
packages/agents-a365-observability/src/tracing/exporter/Agent365ExporterOptions.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,49 @@ | ||
| // ------------------------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
| // ------------------------------------------------------------------------------ | ||
|
|
||
| import { ClusterCategory } from '@microsoft/agents-a365-runtime'; | ||
| import { TokenResolver } from './Agent365Exporter'; | ||
|
|
||
| /** | ||
|
fpfp100 marked this conversation as resolved.
Outdated
|
||
| * Configuration for Agent365Exporter. | ||
| * Only ClusterCategory and TokenResolver are required for core operation. | ||
| */ | ||
| export class Agent365ExporterOptions { | ||
| /** | ||
| * Environment / cluster category | ||
| */ | ||
| public clusterCategory: ClusterCategory | string = 'preprod'; | ||
|
|
||
| /** | ||
| * Resolver used to resolve the auth token. Optional - falls back to AgenticTokenCache when not provided. | ||
| */ | ||
| public tokenResolver?: TokenResolver; | ||
|
|
||
| /** | ||
| * When true, uses the service-to-service (S2S) endpoint path: /maven/agent365/service/agents/{agentId}/traces | ||
| * When false (default), uses the standard endpoint path: /maven/agent365/agents/{agentId}/traces | ||
| */ | ||
| public useS2SEndpoint: boolean = false; | ||
|
fpfp100 marked this conversation as resolved.
Outdated
|
||
|
|
||
| /** | ||
| * Maximum queue size for the batch processor. | ||
| */ | ||
| public maxQueueSize: number = 2048; | ||
|
|
||
| /** | ||
| * Delay in milliseconds between export batches. | ||
| */ | ||
| public scheduledDelayMilliseconds: number = 5000; | ||
|
|
||
| /** | ||
| * Timeout in milliseconds for the export operation. | ||
| */ | ||
| public exporterTimeoutMilliseconds: number = 30000; | ||
|
|
||
| /** | ||
| * Maximum batch size for export operations. | ||
| */ | ||
|
fpfp100 marked this conversation as resolved.
Outdated
|
||
| public maxExportBatchSize: number = 512; | ||
| } | ||
68 changes: 68 additions & 0 deletions
68
packages/agents-a365-observability/src/utils/AgenticTokenCache.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,68 @@ | ||
| // ------------------------------------------------------------------------------ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // ------------------------------------------------------------------------------ | ||
|
fpfp100 marked this conversation as resolved.
Outdated
|
||
|
|
||
| /** | ||
| * Options for configuring the AgenticTokenCache. | ||
| */ | ||
| export interface AgenticTokenCacheOptions { | ||
| /** Default time-to-live in milliseconds applied when set() is called without an explicit ttl. */ | ||
| defaultTtlMs?: number; | ||
| } | ||
|
|
||
| interface CacheEntry { | ||
| token: string; | ||
| /** Expiration timestamp in epoch milliseconds. */ | ||
| expiresAt: number; | ||
| /** Creation timestamp. */ | ||
| createdAt: number; | ||
| } | ||
|
|
||
| /** | ||
| * Lightweight in-memory TTL cache for agent tokens. | ||
| * Minimal parity with C# version: set/get with expiration and cache key helper. | ||
| */ | ||
| export class AgenticTokenCache { | ||
| private readonly options: Required<AgenticTokenCacheOptions>; | ||
| private readonly store: Map<string, CacheEntry> = new Map(); | ||
|
|
||
| constructor(options?: AgenticTokenCacheOptions) { | ||
| this.options = { | ||
| defaultTtlMs: options?.defaultTtlMs ?? 50 * 60 * 1000 | ||
| }; | ||
| } | ||
|
|
||
| /** Create a cache key from agent/tenant identifiers. */ | ||
| createCacheKey(agentId: string, tenantId?: string): string { | ||
| return tenantId ? `${agentId}:${tenantId}` : agentId; | ||
| } | ||
|
|
||
| /** Set a token value with optional TTL override. */ | ||
| set(key: string, token: string, ttlMs?: number): void { | ||
| const now = Date.now(); | ||
| const ttl = ttlMs ?? this.options.defaultTtlMs; | ||
| const expiresAt = now + Math.max(0, ttl); | ||
|
|
||
| this.store.set(key, { token, expiresAt, createdAt: now }); | ||
| } | ||
|
|
||
| /** Retrieve a token if present and not expired; otherwise returns null. */ | ||
| get(key: string): string | null { | ||
| const entry = this.store.get(key); | ||
| if (!entry) { | ||
| return null; | ||
| } | ||
| if (entry.expiresAt <= Date.now()) { | ||
| this.store.delete(key); | ||
| return null; | ||
| } | ||
| return entry.token; | ||
| } | ||
|
|
||
| /** Clear all cache entries (primarily for test isolation). */ | ||
| clear(): void { | ||
| this.store.clear(); | ||
| } | ||
| } | ||
|
|
||
| export const AgenticTokenCacheInstance = new AgenticTokenCache(); | ||
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.