Skip to content

Commit d6609a2

Browse files
committed
azure ai usage tracing
1 parent dcc0540 commit d6609a2

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

src/appConfigurationImpl.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import {
4343
CONDITIONS_KEY_NAME,
4444
CLIENT_FILTERS_KEY_NAME
4545
} from "./featureManagement/constants.js";
46-
import { FM_PACKAGE_NAME, AI_MIME_PROFILE, AI_CHAT_COMPLETION_MIME_PROFILE } from "./requestTracing/constants.js";
46+
import { FM_PACKAGE_NAME, AI_MIME_PROFILE, AI_CHAT_COMPLETION_MIME_PROFILE, AZURE_AI_PACKAGE_NAMES } from "./requestTracing/constants.js";
4747
import { parseContentType, isJsonContentType, isFeatureFlagContentType, isSecretReferenceContentType } from "./common/contentType.js";
4848
import { AzureKeyVaultKeyValueAdapter } from "./keyvault/keyVaultKeyValueAdapter.js";
4949
import { RefreshTimer } from "./refresh/refreshTimer.js";
@@ -86,6 +86,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
8686
#fmVersion: string | undefined;
8787
#aiConfigurationTracing: AIConfigurationTracingOptions | undefined;
8888
#useSnapshotReference: boolean = false;
89+
#useAzureAI: boolean = false;
8990

9091
// Refresh
9192
#refreshInProgress: boolean = false;
@@ -218,7 +219,8 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
218219
featureFlagTracing: this.#featureFlagTracing,
219220
fmVersion: this.#fmVersion,
220221
aiConfigurationTracing: this.#aiConfigurationTracing,
221-
useSnapshotReference: this.#useSnapshotReference
222+
useSnapshotReference: this.#useSnapshotReference,
223+
useAzureAI: this.#useAzureAI
222224
};
223225
}
224226

@@ -384,6 +386,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
384386
async #initializeWithRetryPolicy(abortSignal: AbortSignal): Promise<void> {
385387
if (!this.#isInitialLoadCompleted) {
386388
await this.#inspectFmPackage();
389+
await this.#inspectAzureAIPackages();
387390
const startTimestamp = Date.now();
388391
let postAttempts = 0;
389392
do { // at least try to load once
@@ -437,6 +440,23 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
437440
}
438441
}
439442

443+
/**
444+
* Inspects whether Azure AI packages are installed.
445+
*/
446+
async #inspectAzureAIPackages() {
447+
if (this.#requestTracingEnabled && !this.#useAzureAI) {
448+
for (const packageName of AZURE_AI_PACKAGE_NAMES) {
449+
try {
450+
await import(/* @vite-ignore */packageName);
451+
this.#useAzureAI = true;
452+
break; // Found one package, no need to check others
453+
} catch {
454+
// Package not installed, continue checking
455+
}
456+
}
457+
}
458+
}
459+
440460
async #refreshTasks(): Promise<void> {
441461
const refreshTasks: Promise<boolean>[] = [];
442462
if (this.#refreshEnabled || this.#secretRefreshEnabled) {

src/requestTracing/constants.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export const SNAPSHOT_REFERENCE_TAG = "SnapshotRef";
5656
// Compact feature tags
5757
export const FEATURES_KEY = "Features";
5858
export const LOAD_BALANCE_CONFIGURED_TAG = "LB";
59+
export const AZURE_AI_SDK_TAG = "AzureAI";
5960

6061
// Feature management package
6162
export const FM_PACKAGE_NAME = "@microsoft/feature-management";
@@ -79,4 +80,7 @@ export const AI_CHAT_COMPLETION_CONFIGURATION_TAG = "AICC";
7980
export const AI_MIME_PROFILE = "https://azconfig.io/mime-profiles/ai";
8081
export const AI_CHAT_COMPLETION_MIME_PROFILE = "https://azconfig.io/mime-profiles/ai/chat-completion";
8182

83+
// Azure AI SDK tracing
84+
export const AZURE_AI_PACKAGE_NAMES = ["@azure/ai-agents", "@azure/ai-projects", "@azure/openai", "@azure-rest/ai-inference"];
85+
8286
export const DELIMITER = "+";

src/requestTracing/utils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ import {
4242
DELIMITER,
4343
AI_CONFIGURATION_TAG,
4444
AI_CHAT_COMPLETION_CONFIGURATION_TAG,
45-
SNAPSHOT_REFERENCE_TAG
45+
SNAPSHOT_REFERENCE_TAG,
46+
AZURE_AI_SDK_TAG
4647
} from "./constants.js";
4748

4849
export interface RequestTracingOptions {
@@ -55,6 +56,7 @@ export interface RequestTracingOptions {
5556
fmVersion: string | undefined;
5657
aiConfigurationTracing: AIConfigurationTracingOptions | undefined;
5758
useSnapshotReference: boolean;
59+
useAzureAI: boolean;
5860
}
5961

6062
// Utils
@@ -200,6 +202,9 @@ function createFeaturesString(requestTracingOptions: RequestTracingOptions): str
200202
if (requestTracingOptions.useSnapshotReference) {
201203
tags.push(SNAPSHOT_REFERENCE_TAG);
202204
}
205+
if (requestTracingOptions.useAzureAI) {
206+
tags.push(AZURE_AI_SDK_TAG);
207+
}
203208
return tags.join(DELIMITER);
204209
}
205210

0 commit comments

Comments
 (0)