Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import dts from "rollup-plugin-dts";

export default [
{
external: ["@azure/app-configuration", "@azure/keyvault-secrets", "@azure/core-rest-pipeline", "crypto", "dns/promises"],
external: ["@azure/app-configuration", "@azure/keyvault-secrets", "@azure/core-rest-pipeline", "crypto", "dns/promises", "@microsoft/feature-management"],
input: "src/index.ts",
output: [
{
Expand Down
22 changes: 21 additions & 1 deletion src/AzureAppConfigurationImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
CONDITIONS_KEY_NAME,
CLIENT_FILTERS_KEY_NAME
} from "./featureManagement/constants.js";
import { FM_PACKAGE_NAME } from "./requestTracing/constants.js";
import { AzureKeyVaultKeyValueAdapter } from "./keyvault/AzureKeyVaultKeyValueAdapter.js";
import { RefreshTimer } from "./refresh/RefreshTimer.js";
import { RequestTracingOptions, getConfigurationSettingWithTrace, listConfigurationSettingsWithTrace, requestTracingEnabled } from "./requestTracing/utils.js";
Expand Down Expand Up @@ -66,6 +67,9 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
#isFailoverRequest: boolean = false;
#featureFlagTracing: FeatureFlagTracingOptions | undefined;

#isPackageInspected: boolean = false;
#fmVersion: string | undefined;

// Refresh
#refreshInProgress: boolean = false;

Expand Down Expand Up @@ -184,7 +188,8 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
initialLoadCompleted: this.#isInitialLoadCompleted,
replicaCount: this.#clientManager.getReplicaCount(),
isFailoverRequest: this.#isFailoverRequest,
featureFlagTracing: this.#featureFlagTracing
featureFlagTracing: this.#featureFlagTracing,
fmVersion: this.#fmVersion
};
}

Expand Down Expand Up @@ -226,6 +231,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
* Loads the configuration store for the first time.
*/
async load() {
await this.#ensurePackageInspected();
await this.#loadSelectedAndWatchedKeyValues();
if (this.#featureFlagEnabled) {
await this.#loadFeatureFlags();
Expand Down Expand Up @@ -281,6 +287,7 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
* Refreshes the configuration.
*/
async refresh(): Promise<void> {
await this.#ensurePackageInspected();
if (!this.#refreshEnabled && !this.#featureFlagRefreshEnabled) {
throw new Error("Refresh is not enabled for key-values or feature flags.");
}
Expand Down Expand Up @@ -316,6 +323,19 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
return new Disposable(remove);
}

async #ensurePackageInspected() {
if (!this.#isPackageInspected) {
this.#isPackageInspected = true;
try {
// get feature management package version
const fmPackage = await import(FM_PACKAGE_NAME);
this.#fmVersion = fmPackage?.VERSION;
} catch (error) {
// ignore the error
}
}
}

async #refreshTasks(): Promise<void> {
const refreshTasks: Promise<boolean>[] = [];
if (this.#refreshEnabled) {
Expand Down
3 changes: 3 additions & 0 deletions src/ConfigurationClientManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ export class ConfigurationClientManager {
this.#isFailoverable = false;
return;
}
if (this.#dns) {
return;
}

try {
this.#dns = await import("dns/promises");
Expand Down
4 changes: 4 additions & 0 deletions src/requestTracing/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export const FAILOVER_REQUEST_TAG = "Failover";
export const FEATURES_KEY = "Features";
export const LOAD_BALANCE_CONFIGURED_TAG = "LB";

// Feature management package
export const FM_PACKAGE_NAME = "@microsoft/feature-management";
export const FM_VERSION_KEY = "FMJsVer";

// Feature flag usage tracing
export const FEATURE_FILTER_TYPE_KEY = "Filter";
export const CUSTOM_FILTER_KEY = "CSTM";
Expand Down
7 changes: 6 additions & 1 deletion src/requestTracing/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import {
REPLICA_COUNT_KEY,
FAILOVER_REQUEST_TAG,
FEATURES_KEY,
LOAD_BALANCE_CONFIGURED_TAG
LOAD_BALANCE_CONFIGURED_TAG,
FM_VERSION_KEY
} from "./constants";

export interface RequestTracingOptions {
Expand All @@ -37,6 +38,7 @@ export interface RequestTracingOptions {
replicaCount: number;
isFailoverRequest: boolean;
featureFlagTracing: FeatureFlagTracingOptions | undefined;
fmVersion: string | undefined;
}

// Utils
Expand Down Expand Up @@ -119,6 +121,9 @@ export function createCorrelationContextHeader(requestTracingOptions: RequestTra
if (requestTracingOptions.replicaCount > 0) {
keyValues.set(REPLICA_COUNT_KEY, requestTracingOptions.replicaCount.toString());
}
if (requestTracingOptions.fmVersion) {
keyValues.set(FM_VERSION_KEY, requestTracingOptions.fmVersion);
}

// Compact tags: Features=LB+...
if (appConfigOptions?.loadBalancingEnabled) {
Expand Down
Loading