Skip to content

Remove FeatureFlagId from telemetry #183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2025
Merged
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
52 changes: 0 additions & 52 deletions src/AzureAppConfigurationImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
ENABLED_KEY_NAME,
METADATA_KEY_NAME,
ETAG_KEY_NAME,
FEATURE_FLAG_ID_KEY_NAME,
FEATURE_FLAG_REFERENCE_KEY_NAME,
ALLOCATION_KEY_NAME,
SEED_KEY_NAME,
Expand Down Expand Up @@ -671,7 +670,6 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
const metadata = featureFlag[TELEMETRY_KEY_NAME][METADATA_KEY_NAME];
featureFlag[TELEMETRY_KEY_NAME][METADATA_KEY_NAME] = {
[ETAG_KEY_NAME]: setting.etag,
[FEATURE_FLAG_ID_KEY_NAME]: await this.#calculateFeatureFlagId(setting),
[FEATURE_FLAG_REFERENCE_KEY_NAME]: this.#createFeatureFlagReference(setting),
...(metadata || {})
};
Expand Down Expand Up @@ -699,56 +697,6 @@ export class AzureAppConfigurationImpl implements AzureAppConfiguration {
return featureFlag;
}

async #calculateFeatureFlagId(setting: ConfigurationSetting<string>): Promise<string> {
let crypto;

// Check for browser environment
if (typeof window !== "undefined" && window.crypto && window.crypto.subtle) {
crypto = window.crypto;
}
// Check for Node.js environment
else if (typeof global !== "undefined" && global.crypto) {
crypto = global.crypto;
}
// Fallback to native Node.js crypto module
else {
try {
if (typeof module !== "undefined" && module.exports) {
crypto = require("crypto");
}
else {
crypto = await import("crypto");
}
} catch (error) {
console.error("Failed to load the crypto module:", error.message);
throw error;
}
}

let baseString = `${setting.key}\n`;
if (setting.label && setting.label.trim().length !== 0) {
baseString += `${setting.label}`;
}

// Convert to UTF-8 encoded bytes
const data = new TextEncoder().encode(baseString);

// In the browser, use crypto.subtle.digest
if (crypto.subtle) {
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
const hashArray = new Uint8Array(hashBuffer);
// btoa/atob is also available in Node.js 18+
const base64String = btoa(String.fromCharCode(...hashArray));
const base64urlString = base64String.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
return base64urlString;
}
// In Node.js, use the crypto module's hash function
else {
const hash = crypto.createHash("sha256").update(data).digest();
return hash.toString("base64url");
}
}

#createFeatureFlagReference(setting: ConfigurationSetting<string>): string {
let featureFlagReference = `${this.#clientManager.endpoint.origin}/kv/${setting.key}`;
if (setting.label && setting.label.trim().length !== 0) {
Expand Down
1 change: 0 additions & 1 deletion src/featureManagement/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export const TELEMETRY_KEY_NAME = "telemetry";
export const ENABLED_KEY_NAME = "enabled";
export const METADATA_KEY_NAME = "metadata";
export const ETAG_KEY_NAME = "ETag";
export const FEATURE_FLAG_ID_KEY_NAME = "FeatureFlagId";
export const FEATURE_FLAG_REFERENCE_KEY_NAME = "FeatureFlagReference";
export const ALLOCATION_KEY_NAME = "allocation";
export const DEFAULT_WHEN_ENABLED_KEY_NAME = "default_when_enabled";
Expand Down
2 changes: 0 additions & 2 deletions test/featureFlag.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@ describe("feature flags", function () {
expect(featureFlag.telemetry).not.undefined;
expect(featureFlag.telemetry.enabled).equals(true);
expect(featureFlag.telemetry.metadata.ETag).equals("ETag");
expect(featureFlag.telemetry.metadata.FeatureFlagId).equals("krkOsu9dVV9huwbQDPR6gkV_2T0buWxOCS-nNsj5-6g");
expect(featureFlag.telemetry.metadata.FeatureFlagReference).equals(`${createMockedEndpoint()}/kv/.appconfig.featureflag/Telemetry_1`);

featureFlag = featureFlags[1];
Expand All @@ -336,7 +335,6 @@ describe("feature flags", function () {
expect(featureFlag.telemetry).not.undefined;
expect(featureFlag.telemetry.enabled).equals(true);
expect(featureFlag.telemetry.metadata.ETag).equals("ETag");
expect(featureFlag.telemetry.metadata.FeatureFlagId).equals("Rc8Am7HIGDT7HC5Ovs3wKN_aGaaK_Uz1mH2e11gaK0o");
expect(featureFlag.telemetry.metadata.FeatureFlagReference).equals(`${createMockedEndpoint()}/kv/.appconfig.featureflag/Telemetry_2?label=Test`);
});
});