Repository navigation
Add Node.js and .NET telemetry SDKs #822
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
RamonArjona4
merged 1 commit into
main
from
user/ramonarjona4/telemetry-05-language-sdks
Sep 10, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,240 @@ | ||
| #!/usr/bin/env node | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| const { readFileSync } = require("fs"); | ||
| const { join } = require("path"); | ||
|
|
||
| const root = join(__dirname, ".."); | ||
| const protocol = readFileSync( | ||
| join(root, "src", "core", "wxc_common", "src", "telemetry", "consent_protocol.rs"), | ||
| "utf8" | ||
| ); | ||
| const policy = readFileSync( | ||
| join(root, "src", "core", "wxc_common", "src", "telemetry", "policy.rs"), | ||
| "utf8" | ||
| ); | ||
| const csharp = readFileSync( | ||
| join(root, "sdk", "dotnet", "Microsoft.Mxc.Sdk", "MxcTelemetry.cs"), | ||
| "utf8" | ||
| ); | ||
| const rustSdk = readFileSync( | ||
| join(root, "src", "core", "mxc-sdk", "src", "telemetry.rs"), | ||
| "utf8" | ||
| ); | ||
| const typescript = readFileSync( | ||
| join(root, "sdk", "node", "src", "telemetry.ts"), | ||
| "utf8" | ||
| ); | ||
| const errors = []; | ||
|
|
||
| function requiredMatch(source, expression, label) { | ||
| const match = source.match(expression); | ||
| if (!match) { | ||
| console.error(`ERROR: could not parse ${label}`); | ||
| process.exit(1); | ||
| } | ||
| return match; | ||
| } | ||
|
|
||
| function rustWireName(variant, rename) { | ||
| const kebab = variant.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(); | ||
| return rename === "camelCase" | ||
| ? kebab.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase()) | ||
| : kebab; | ||
| } | ||
|
|
||
| function rustEnum(name) { | ||
| const match = requiredMatch( | ||
| protocol, | ||
| new RegExp( | ||
| `#\\[serde\\(rename_all = "([^"]+)"(?:,[^\\]]*)?\\)\\]\\s*` + | ||
| `pub\\(super\\)\\s+enum\\s+${name}\\s*\\{([\\s\\S]*?)\\n\\}` | ||
| ), | ||
| `Rust enum ${name}` | ||
| ); | ||
| if (!["camelCase", "kebab-case"].includes(match[1])) { | ||
| console.error(`ERROR: unsupported serde rename '${match[1]}' on ${name}`); | ||
| process.exit(1); | ||
| } | ||
| return new Set( | ||
| [...match[2].matchAll(/^\s*([A-Z][A-Za-z0-9_]*)\s*,/gm)] | ||
| .map((item) => rustWireName(item[1], match[1])) | ||
| ); | ||
| } | ||
|
|
||
| // The C# binding consumes the FFI, whose results come from the Rust SDK enum, | ||
| // not from the executor's private CLI protocol. | ||
| function rustSdkConsentResults() { | ||
| const body = requiredMatch( | ||
| rustSdk, | ||
| /impl ConsentActionResult \{[\s\S]*?match self \{([\s\S]*?)\n\s*\}/, | ||
| "Rust SDK ConsentActionResult::as_str" | ||
| )[1]; | ||
| return new Set([...body.matchAll(/Self::\w+\s*=>\s*"([^"]+)"/g)].map((item) => item[1])); | ||
| } | ||
|
|
||
| function policyStates() { | ||
| const body = requiredMatch( | ||
| policy, | ||
| /fn as_str\(&self\)\s*->\s*&'static str\s*\{[\s\S]*?match self \{([\s\S]*?)\n\s*\}/, | ||
| "PolicyState::as_str" | ||
| )[1]; | ||
| return new Map( | ||
| [...body.matchAll(/PolicyState::(\w+)\s*=>\s*"([^"]+)"/g)] | ||
| .map((item) => [item[2], item[1]]) | ||
| ); | ||
| } | ||
|
|
||
| function typescriptValues(name) { | ||
| const body = requiredMatch( | ||
| typescript, | ||
| new RegExp(`const ${name}\\s*=\\s*\\[([\\s\\S]*?)\\]\\s*as const`), | ||
| `TypeScript literal set ${name}` | ||
| )[1]; | ||
| return new Set([...body.matchAll(/["']([^"']+)["']/g)].map((item) => item[1])); | ||
| } | ||
|
|
||
| function csharpSwitch(functionName, enumName) { | ||
| const body = requiredMatch( | ||
| csharp, | ||
| new RegExp( | ||
| `private\\s+static\\s+[\\w?<>]+\\s+${functionName}\\s*\\([^)]*\\)[\\s\\S]*?` + | ||
| `(?:=>\\s*value|return\\s+value\\.GetString\\(\\))\\s+switch\\s*\\{([\\s\\S]*?)\\};` | ||
| ), | ||
| `C# ${functionName}` | ||
| )[1]; | ||
| return new Map( | ||
| [...body.matchAll(new RegExp(`"([^"]+)"\\s*=>\\s*${enumName}\\.(\\w+)`, "g"))] | ||
| .map((item) => [item[1], item[2]]) | ||
| ); | ||
| } | ||
|
|
||
| function csharpStatusReasons() { | ||
| const body = requiredMatch( | ||
| csharp, | ||
| /private\s+static\s+bool\s+IsKnownConsentStatusReason\s*\([^)]*\)[\s\S]*?return\s+value\.GetString\(\)\s+switch\s*\{([\s\S]*?)\};/, | ||
| "C# IsKnownConsentStatusReason" | ||
| )[1]; | ||
| return new Set([...body.matchAll(/"([^"]+)"/g)].map((item) => item[1])); | ||
| } | ||
|
|
||
| function functionBody(name) { | ||
| const start = requiredMatch( | ||
| csharp, | ||
| new RegExp(`private\\s+static\\s+[\\w?<>]+\\s+${name}\\s*\\(`), | ||
| `C# ${name}` | ||
| ).index; | ||
| const end = csharp.indexOf("\n private static ", start + 1); | ||
| return csharp.slice(start, end < 0 ? undefined : end); | ||
| } | ||
|
|
||
| function compareSets(label, expected, actual) { | ||
| for (const value of expected) { | ||
| if (!actual.has(value)) errors.push(`${label} is missing '${value}'`); | ||
| } | ||
| for (const value of actual) { | ||
| if (!expected.has(value)) errors.push(`${label} has unexpected '${value}'`); | ||
| } | ||
| } | ||
|
|
||
| function expectedVariant(wire) { | ||
| return wire | ||
| .replace(/-([a-z])/g, (_, letter) => letter.toUpperCase()) | ||
| .replace(/^./, (letter) => letter.toUpperCase()); | ||
| } | ||
|
|
||
| function compareMappings(label, expected, actual) { | ||
| for (const wire of expected) { | ||
| const variant = actual.get(wire); | ||
| if (variant === undefined) { | ||
| errors.push(`${label} does not handle '${wire}'`); | ||
| } else if (variant !== expectedVariant(wire)) { | ||
| errors.push(`${label} maps '${wire}' to ${variant}`); | ||
| } | ||
| } | ||
| for (const wire of actual.keys()) { | ||
| if (!expected.has(wire)) errors.push(`${label} handles unexpected '${wire}'`); | ||
| } | ||
| } | ||
|
|
||
| const runtimePolicy = policyStates(); | ||
| const protocolPolicy = rustEnum("PolicyState"); | ||
| compareMappings("Rust PolicyState::as_str", protocolPolicy, runtimePolicy); | ||
| compareSets("TypeScript policy", protocolPolicy, typescriptValues("TELEMETRY_POLICY_STATES")); | ||
| compareMappings( | ||
| "C# ParsePolicyState", | ||
| protocolPolicy, | ||
| csharpSwitch("ParseKnownPolicyState", "TelemetryPolicyState") | ||
| ); | ||
|
|
||
| const consentStates = rustEnum("ConsentState"); | ||
| compareSets("TypeScript consent state", consentStates, typescriptValues("TELEMETRY_CONSENT_STATES")); | ||
| compareMappings( | ||
| "C# ParseConsentState", | ||
| consentStates, | ||
| csharpSwitch("ParseKnownConsentState", "TelemetryConsentState") | ||
| ); | ||
|
|
||
| const bindingResults = rustSdkConsentResults(); | ||
| const protocolResults = rustEnum("ConsentResult"); | ||
| for (const value of bindingResults) { | ||
| if (!protocolResults.has(value)) { | ||
| errors.push(`Rust SDK consent result '${value}' is missing from the CLI protocol`); | ||
| } | ||
| } | ||
| const protocolOnlyResults = new Set( | ||
| [...protocolResults].filter((value) => | ||
| value === "status" || value === "presentationRequired" | ||
| ) | ||
| ); | ||
| const terminalResults = new Set( | ||
| [...protocolResults].filter((value) => !protocolOnlyResults.has(value)) | ||
| ); | ||
| compareSets( | ||
| "TypeScript private protocol result", | ||
| protocolOnlyResults, | ||
| typescriptValues("CONSENT_PROTOCOL_ONLY_RESULTS") | ||
| ); | ||
| compareSets( | ||
| "TypeScript consent result", | ||
| terminalResults, | ||
| typescriptValues("TELEMETRY_CONSENT_RESULTS") | ||
| ); | ||
| compareMappings( | ||
| "C# ParseConsentActionResult", | ||
| bindingResults, | ||
| csharpSwitch("ParseConsentActionResult", "TelemetryConsentActionResult") | ||
| ); | ||
|
|
||
| const statusReasons = rustEnum("StatusReason"); | ||
| compareSets( | ||
| "TypeScript private status reason", | ||
| statusReasons, | ||
| typescriptValues("CONSENT_STATUS_REASONS") | ||
| ); | ||
| compareSets("C# private status reason", statusReasons, csharpStatusReasons()); | ||
|
|
||
| for (const [name, sentinel] of [ | ||
| ["UnrecognizedConsentState", "return TelemetryConsentState.Undetermined;"], | ||
| ["UnrecognizedConsentActionResult", "return TelemetryConsentActionResult.Unknown;"], | ||
| ["ReportUnrecognizedConsentStatusReason", "return false;"], | ||
| ["UnrecognizedPolicyState", "return TelemetryPolicyState.Blocked;"], | ||
| ]) { | ||
| if (!functionBody(name).includes(sentinel)) { | ||
| errors.push(`C# ${name} must contain '${sentinel}'`); | ||
| } | ||
| } | ||
|
|
||
| if (errors.length > 0) { | ||
| console.error("ERROR: telemetry wire parity check failed:"); | ||
| for (const error of errors) console.error(` - ${error}`); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| console.log( | ||
| `Telemetry wire parity OK: ${protocolPolicy.size} policy states, ` + | ||
| `${consentStates.size} consent states, ${terminalResults.size} terminal results, ` + | ||
| `${protocolOnlyResults.size} private protocol results, ` + | ||
| `and ${statusReasons.size} private status reasons match` | ||
| ); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.