From d6609a203dee453cf8dd45781ea2ae754f51f4b7 Mon Sep 17 00:00:00 2001 From: "Lingling Ye (from Dev Box)" Date: Thu, 22 Jan 2026 16:19:58 +0800 Subject: [PATCH 1/2] azure ai usage tracing --- src/appConfigurationImpl.ts | 24 ++++++++++++++++++++++-- src/requestTracing/constants.ts | 4 ++++ src/requestTracing/utils.ts | 7 ++++++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/appConfigurationImpl.ts b/src/appConfigurationImpl.ts index 5d89508..c3934d4 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, + useAzureAI: 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..7c68974 100644 --- a/src/requestTracing/constants.ts +++ b/src/requestTracing/constants.ts @@ -56,6 +56,7 @@ export const SNAPSHOT_REFERENCE_TAG = "SnapshotRef"; // Compact feature tags export const FEATURES_KEY = "Features"; export const LOAD_BALANCE_CONFIGURED_TAG = "LB"; +export const AZURE_AI_SDK_TAG = "AzureAI"; // Feature management package export const FM_PACKAGE_NAME = "@microsoft/feature-management"; @@ -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..429f697 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, + AZURE_AI_SDK_TAG } from "./constants.js"; export interface RequestTracingOptions { @@ -55,6 +56,7 @@ export interface RequestTracingOptions { fmVersion: string | undefined; aiConfigurationTracing: AIConfigurationTracingOptions | undefined; useSnapshotReference: boolean; + useAzureAI: boolean; } // Utils @@ -200,6 +202,9 @@ function createFeaturesString(requestTracingOptions: RequestTracingOptions): str if (requestTracingOptions.useSnapshotReference) { tags.push(SNAPSHOT_REFERENCE_TAG); } + if (requestTracingOptions.useAzureAI) { + tags.push(AZURE_AI_SDK_TAG); + } return tags.join(DELIMITER); } From 0754cb52cfa702ae24889694010af6ea5bb09b57 Mon Sep 17 00:00:00 2001 From: "Lingling Ye (from Dev Box)" Date: Tue, 27 Jan 2026 15:23:18 +0800 Subject: [PATCH 2/2] update ai tracing tag --- src/appConfigurationImpl.ts | 2 +- src/requestTracing/constants.ts | 2 +- src/requestTracing/utils.ts | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/appConfigurationImpl.ts b/src/appConfigurationImpl.ts index c3934d4..e3d0722 100644 --- a/src/appConfigurationImpl.ts +++ b/src/appConfigurationImpl.ts @@ -220,7 +220,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration { fmVersion: this.#fmVersion, aiConfigurationTracing: this.#aiConfigurationTracing, useSnapshotReference: this.#useSnapshotReference, - useAzureAI: this.#useAzureAI + usesAISdk: this.#useAzureAI }; } diff --git a/src/requestTracing/constants.ts b/src/requestTracing/constants.ts index 7c68974..41b3385 100644 --- a/src/requestTracing/constants.ts +++ b/src/requestTracing/constants.ts @@ -52,11 +52,11 @@ 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"; export const LOAD_BALANCE_CONFIGURED_TAG = "LB"; -export const AZURE_AI_SDK_TAG = "AzureAI"; // Feature management package export const FM_PACKAGE_NAME = "@microsoft/feature-management"; diff --git a/src/requestTracing/utils.ts b/src/requestTracing/utils.ts index 429f697..2a2022a 100644 --- a/src/requestTracing/utils.ts +++ b/src/requestTracing/utils.ts @@ -43,7 +43,7 @@ import { AI_CONFIGURATION_TAG, AI_CHAT_COMPLETION_CONFIGURATION_TAG, SNAPSHOT_REFERENCE_TAG, - AZURE_AI_SDK_TAG + AI_SDK_TAG } from "./constants.js"; export interface RequestTracingOptions { @@ -56,7 +56,7 @@ export interface RequestTracingOptions { fmVersion: string | undefined; aiConfigurationTracing: AIConfigurationTracingOptions | undefined; useSnapshotReference: boolean; - useAzureAI: boolean; + usesAISdk: boolean; } // Utils @@ -154,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()); } @@ -202,9 +205,6 @@ function createFeaturesString(requestTracingOptions: RequestTracingOptions): str if (requestTracingOptions.useSnapshotReference) { tags.push(SNAPSHOT_REFERENCE_TAG); } - if (requestTracingOptions.useAzureAI) { - tags.push(AZURE_AI_SDK_TAG); - } return tags.join(DELIMITER); }