Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions src/appConfigurationImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
};
}

Expand Down Expand Up @@ -384,6 +386,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
async #initializeWithRetryPolicy(abortSignal: AbortSignal): Promise<void> {
if (!this.#isInitialLoadCompleted) {
await this.#inspectFmPackage();
await this.#inspectAzureAIPackages();
const startTimestamp = Date.now();
let postAttempts = 0;
do { // at least try to load once
Expand Down Expand Up @@ -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<void> {
const refreshTasks: Promise<boolean>[] = [];
if (this.#refreshEnabled || this.#secretRefreshEnabled) {
Expand Down
4 changes: 4 additions & 0 deletions src/requestTracing/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 = "+";
7 changes: 6 additions & 1 deletion src/requestTracing/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -55,6 +56,7 @@ export interface RequestTracingOptions {
fmVersion: string | undefined;
aiConfigurationTracing: AIConfigurationTracingOptions | undefined;
useSnapshotReference: boolean;
usesAISdk: boolean;
}

// Utils
Expand Down Expand Up @@ -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());
}
Expand Down
Loading