diff --git a/src/appConfigurationImpl.ts b/src/appConfigurationImpl.ts index 5d89508..e3d0722 100644 --- a/src/appConfigurationImpl.ts +++ b/src/appConfigurationImpl.ts @@ -43,7 +43,7 @@ import { CONDITIONS_KEY_NAME, CLIENT_FILTERS_KEY_NAME } from "./featureManagement/constants.js"; -import { FM_PACKAGE_NAME, AI_MIME_PROFILE, AI_CHAT_COMPLETION_MIME_PROFILE } from "./requestTracing/constants.js"; +import { FM_PACKAGE_NAME, AI_MIME_PROFILE, AI_CHAT_COMPLETION_MIME_PROFILE, AZURE_AI_PACKAGE_NAMES } from "./requestTracing/constants.js"; import { parseContentType, isJsonContentType, isFeatureFlagContentType, isSecretReferenceContentType } from "./common/contentType.js"; import { AzureKeyVaultKeyValueAdapter } from "./keyvault/keyVaultKeyValueAdapter.js"; import { RefreshTimer } from "./refresh/refreshTimer.js"; @@ -86,6 +86,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration { #fmVersion: string | undefined; #aiConfigurationTracing: AIConfigurationTracingOptions | undefined; #useSnapshotReference: boolean = false; + #useAzureAI: boolean = false; // Refresh #refreshInProgress: boolean = false; @@ -218,7 +219,8 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration { featureFlagTracing: this.#featureFlagTracing, fmVersion: this.#fmVersion, aiConfigurationTracing: this.#aiConfigurationTracing, - useSnapshotReference: this.#useSnapshotReference + useSnapshotReference: this.#useSnapshotReference, + usesAISdk: this.#useAzureAI }; } @@ -384,6 +386,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration { async #initializeWithRetryPolicy(abortSignal: AbortSignal): Promise { if (!this.#isInitialLoadCompleted) { await this.#inspectFmPackage(); + await this.#inspectAzureAIPackages(); const startTimestamp = Date.now(); let postAttempts = 0; do { // at least try to load once @@ -437,6 +440,23 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration { } } + /** + * Inspects whether Azure AI packages are installed. + */ + async #inspectAzureAIPackages() { + if (this.#requestTracingEnabled && !this.#useAzureAI) { + for (const packageName of AZURE_AI_PACKAGE_NAMES) { + try { + await import(/* @vite-ignore */packageName); + this.#useAzureAI = true; + break; // Found one package, no need to check others + } catch { + // Package not installed, continue checking + } + } + } + } + async #refreshTasks(): Promise { const refreshTasks: Promise[] = []; if (this.#refreshEnabled || this.#secretRefreshEnabled) { diff --git a/src/requestTracing/constants.ts b/src/requestTracing/constants.ts index 2695d0b..41b3385 100644 --- a/src/requestTracing/constants.ts +++ b/src/requestTracing/constants.ts @@ -52,6 +52,7 @@ export const KEY_VAULT_CONFIGURED_TAG = "UsesKeyVault"; export const KEY_VAULT_REFRESH_CONFIGURED_TAG = "RefreshesKeyVault"; export const FAILOVER_REQUEST_TAG = "Failover"; export const SNAPSHOT_REFERENCE_TAG = "SnapshotRef"; +export const AI_SDK_TAG = "UsesAISdk"; // Compact feature tags export const FEATURES_KEY = "Features"; @@ -79,4 +80,7 @@ export const AI_CHAT_COMPLETION_CONFIGURATION_TAG = "AICC"; export const AI_MIME_PROFILE = "https://azconfig.io/mime-profiles/ai"; export const AI_CHAT_COMPLETION_MIME_PROFILE = "https://azconfig.io/mime-profiles/ai/chat-completion"; +// Azure AI SDK tracing +export const AZURE_AI_PACKAGE_NAMES = ["@azure/ai-agents", "@azure/ai-projects", "@azure/openai", "@azure-rest/ai-inference"]; + export const DELIMITER = "+"; diff --git a/src/requestTracing/utils.ts b/src/requestTracing/utils.ts index 3b1337e..2a2022a 100644 --- a/src/requestTracing/utils.ts +++ b/src/requestTracing/utils.ts @@ -42,7 +42,8 @@ import { DELIMITER, AI_CONFIGURATION_TAG, AI_CHAT_COMPLETION_CONFIGURATION_TAG, - SNAPSHOT_REFERENCE_TAG + SNAPSHOT_REFERENCE_TAG, + AI_SDK_TAG } from "./constants.js"; export interface RequestTracingOptions { @@ -55,6 +56,7 @@ export interface RequestTracingOptions { fmVersion: string | undefined; aiConfigurationTracing: AIConfigurationTracingOptions | undefined; useSnapshotReference: boolean; + usesAISdk: boolean; } // Utils @@ -152,6 +154,9 @@ function createCorrelationContextHeader(requestTracingOptions: RequestTracingOpt if (requestTracingOptions.isFailoverRequest) { tags.push(FAILOVER_REQUEST_TAG); } + if (requestTracingOptions.usesAISdk) { + tags.push(AI_SDK_TAG); + } if (requestTracingOptions.replicaCount > 0) { keyValues.set(REPLICA_COUNT_KEY, requestTracingOptions.replicaCount.toString()); }