A plugin marketplace for GitHub Copilot and other AI agents that provides Power Platform development plugins, including reusable skills, agents, and commands for building and deploying solutions.
JavaScript claude-code-pluginclaude-code-skillscode-appsgithub-copilot-pluginpower-appspower-pagespower-platform
Enforce cross-plugin telemetry iKey uniqueness (#230)
amitjoshi43875586114097b
diff --git a/.github/workflows/validate-repository-metadata.yml b/.github/workflows/validate-repository-metadata.ymlindex 15bedab8a..07067911b 100644--- a/.github/workflows/validate-repository-metadata.yml+++ b/.github/workflows/validate-repository-metadata.yml@@ -27,3 +27,6 @@ jobs:- name: validate-skill-descriptionsrun: node scripts/validate-skill-descriptions.js++ - name: validate-telemetry-ikeys+ run: node scripts/validate-telemetry-ikeys.jsdiff --git a/AGENTS.md b/AGENTS.mdindex d51265c6f..d1eb8b03b 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -73,6 +73,10 @@ This keeps the skill discoverable in each plugin while preserving install-time pEdit `shared/telemetry/` first, then refresh every adopting plugin's copied `scripts/lib/telemetry/lib` directory in the same change so the canonical source and bundled plugin content stay in sync.+**Never reuse another plugin's instrumentation key or event stream.** When adopting telemetry in a new plugin, copy only the routing-agnostic library (`shared/telemetry/lib` → `plugins/<plugin>/scripts/lib/telemetry/lib`) — do **not** copy an existing adopter's real `ikey.json` (or its `resolver.js`). Each plugin's `ikey.json` carries that plugin's own instrumentation key(s), collector routing, and `event_stream_name`; start from the placeholder `shared/telemetry/ikey.json` (every region key is `PLACEHOLDER_REPLACE_BEFORE_SHIPPING` and it ships `disabled: true`) and provision a fresh, plugin-specific key before shipping. Copying a key already committed to another plugin (e.g. lifting `power-pages`'s `ikey.json` wholesale) mis-attributes the new plugin's events to the other plugin's Kusto stream and pollutes it — the copy step must bring over library code only, never another plugin's provisioned `ikey.json`/`resolver.js`.++This invariant is CI-enforced: `node scripts/validate-telemetry-ikeys.js` (wired into the `validate-repository-metadata` workflow) scans every `plugins/*/**/ikey.json`, ignores placeholder/empty values, and fails if the same instrumentation key or `event_stream_name` appears under two different plugins. A single plugin reusing one key across regions is allowed; only cross-plugin reuse fails. Run it locally after touching any plugin's `ikey.json`.+Per-plugin iKey/collector routing is pluggable via a `resolver.js` placed next to the plugin's `ikey.json` (implementing the `resolve`/`isProvisioned` contract); the shared library ships only that contract plus a static-key fallback, not any routing logic. A per-plugin opt-out env var `POWER_PLATFORM_SKILLS_TELEMETRY_<PLUGIN>_OPTOUT` (derived as the uppercased plugin name with non-alphanumerics collapsed to `_`, suffixed `_OPTOUT`) disables transmission for automation when set to `1`/`true` (dotnet `*_TELEMETRY_OPTOUT` convention); it has the **highest precedence**, overriding both the persisted `config.json` choice and `/<plugin>:telemetry on`.### CI must opt out of telemetry transmissiondiff --git a/scripts/validate-telemetry-ikeys.js b/scripts/validate-telemetry-ikeys.jsnew file mode 100644index 000000000..165349292--- /dev/null+++ b/scripts/validate-telemetry-ikeys.js@@ -0,0 +1,191 @@+#!/usr/bin/env node++/**+ * Validates that no two plugins share a telemetry instrumentation key or+ * event_stream_name.+ *+ * WHY: Plugins adopt the shared 1DS telemetry by copying the routing-agnostic+ * library, but each plugin must provision its OWN ikey.json (its own+ * instrumentation key(s), collector routing, and event_stream_name). The most+ * common adoption mistake is lifting an existing adopter's ikey.json wholesale+ * (e.g. copying power-pages' file), which silently mis-attributes the new+ * plugin's events to the other plugin's Kusto stream and pollutes it. Docs warn+ * against this (see the root AGENTS.md "Shared Telemetry" section), but only a+ * deterministic CI check can actually prevent the copy-paste collision. This+ * script turns that prose invariant into an enforced one: a PR that reuses+ * another plugin's key or stream name fails.+ *+ * ikey.json comes in two shapes, both of which are inspected here:+ * Tier 1 (flat): { "instrumentationKey": "...", "collector_url": "...", "event_stream_name": "..." }+ * Tier 2 (regions): { "regions": { "us": { "instrumentation_key": "...", "collector_url": "..." }, ... }, "event_stream_name": "..." }+ * A single plugin legitimately reuses one key across regions (power-pages shares+ * one key for us/eu), so keys are de-duplicated PER PLUGIN — only reuse across+ * two different plugins is an error.+ */++const fs = require('fs');+const path = require('path');++const ROOT = path.resolve(__dirname, '..');+const PLUGINS_DIR = path.join(ROOT, 'plugins');++// Directories that never contain a real, provisioned plugin ikey.json and would+// only slow the walk (installed deps, VCS internals).+const SKIP_DIRS = new Set(['node_modules', '.git']);++// Placeholder values shipped by the shared template (shared/telemetry/ikey.json):+// every region key is "PLACEHOLDER_REPLACE_BEFORE_SHIPPING" and the stream name+// is "PluginEventStreamPlaceholder". A freshly-adopted, not-yet-provisioned+// plugin legitimately still carries these, so they must never count as a+// cross-plugin collision. Empty strings are also unprovisioned placeholders.+//+// Match ONLY the known template sentinels (and angle-bracket template strings+// like "<your 1DS instrumentation key>" from the README's Tier 1 example), not+// any string merely containing the substring "placeholder". A broad substring+// test would silently skip a legitimate key or event_stream_name that happened+// to include that word, letting a real cross-plugin collision slip through.+const TEMPLATE_SENTINELS = new Set([+ 'PLACEHOLDER_REPLACE_BEFORE_SHIPPING', // shared/telemetry/ikey.json region keys+ 'PluginEventStreamPlaceholder', // shared/telemetry/ikey.json event_stream_name+]);++function isPlaceholder(value) {+ if (typeof value !== 'string') return true;+ const trimmed = value.trim();+ if (trimmed === '') return true;+ if (TEMPLATE_SENTINELS.has(trimmed)) return true;+ // Angle-bracket template strings copied verbatim from the docs, e.g.+ // "<your 1DS instrumentation key>" or "<region>".+ if (trimmed.startsWith('<') && trimmed.endsWith('>')) return true;+ return false;+}++function toPosix(relativePath) {+ return relativePath.replace(/\\/g, '/');+}++// Recursively collect every file named `ikey.json` under plugins/. A recursive+// walk (rather than probing only the canonical+// plugins/<plugin>/scripts/lib/telemetry/ikey.json path) is defense-in-depth:+// it also catches a stray ikey.json dropped anywhere in a plugin tree by an+// over-broad copy of another plugin's telemetry directory.+function findIkeyFiles(dir) {+ const results = [];+ if (!fs.existsSync(dir)) return results;++ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {+ if (entry.isDirectory()) {+ if (SKIP_DIRS.has(entry.name)) continue;+ results.push(...findIkeyFiles(path.join(dir, entry.name)));+ } else if (entry.isFile() && entry.name === 'ikey.json') {+ results.push(path.join(dir, entry.name));+ }+ }+ return results;+}++// The plugin a file belongs to is the first path segment under plugins/, e.g.+// plugins/power-pages/scripts/lib/telemetry/ikey.json -> "power-pages".+function pluginNameForFile(filePath) {+ const rel = toPosix(path.relative(PLUGINS_DIR, filePath));+ return rel.split('/')[0];+}++// Pull every provisioned instrumentation key out of one parsed ikey.json,+// tagging each with a human-readable context so collision output can point at+// the exact region ("regions.us") or the flat key ("instrumentationKey").+function extractKeys(config) {+ const keys = [];++ if (typeof config.instrumentationKey === 'string') {+ keys.push({ value: config.instrumentationKey, context: 'instrumentationKey' });+ }++ if (config.regions && typeof config.regions === 'object') {+ for (const [region, entry] of Object.entries(config.regions)) {+ if (entry && typeof entry.instrumentation_key === 'string') {+ keys.push({ value: entry.instrumentation_key, context: `regions.${region}` });+ }+ }+ }++ return keys.filter((k) => !isPlaceholder(k.value));+}++const errors = [];++// key/stream value -> Map<pluginName, Set<"relativePath (context)">>. Using a+// Map keyed by plugin lets us treat intra-plugin reuse (same key across regions)+// as fine while flagging the same value appearing under two different plugins.+const keyOwners = new Map();+const streamOwners = new Map();++function record(owners, value, pluginName, location) {+ if (!owners.has(value)) owners.set(value, new Map());+ const byPlugin = owners.get(value);+ if (!byPlugin.has(pluginName)) byPlugin.set(pluginName, new Set());+ byPlugin.get(pluginName).add(location);+}++for (const filePath of findIkeyFiles(PLUGINS_DIR)) {+ const relPath = toPosix(path.relative(ROOT, filePath));+ const pluginName = pluginNameForFile(filePath);++ let config;+ try {+ config = JSON.parse(fs.readFileSync(filePath, 'utf8'));+ } catch (err) {+ // A malformed ikey.json is itself a shippable defect (it would break the+ // dispatcher at runtime), so fail deterministically rather than skip it.+ errors.push(`${relPath}: could not parse JSON (${err.message})`);+ continue;+ }++ for (const { value, context } of extractKeys(config)) {+ record(keyOwners, value, pluginName, `${relPath} (${context})`);+ }++ if (!isPlaceholder(config.event_stream_name)) {+ record(streamOwners, config.event_stream_name, pluginName, `${relPath} (event_stream_name)`);+ }+}++function collectCollisions(owners, label, redact) {+ for (const [value, byPlugin] of owners) {+ if (byPlugin.size < 2) continue; // reused within a single plugin is allowed++ const locations = [];+ for (const [pluginName, where] of byPlugin) {+ locations.push(` ${pluginName}: ${[...where].sort().join(', ')}`);+ }+ const shown = redact ? redact(value) : value;+ errors.push(+ `${label} '${shown}' is shared across ${byPlugin.size} plugins:\n` ++ locations.sort().join('\n')+ );+ }+}++// Redact the instrumentation key in output. It is a committed value (not a+// secret per se), but there is no reason to reprint the full key in CI logs when+// a stable prefix already identifies which key collided.+function redactKey(value) {+ return value.length > 12 ? `${value.slice(0, 12)}...` : value;+}++collectCollisions(keyOwners, 'Instrumentation key', redactKey);+collectCollisions(streamOwners, 'event_stream_name', null);++if (errors.length > 0) {+ console.log('Telemetry ikey.json validation failed:');+ for (const error of errors) {+ console.log(`- ${error}`);+ }+ console.log(+ '\nEach plugin must provision its own instrumentation key(s) and event_stream_name. ' ++ 'Do not copy another plugin\'s ikey.json; start from the placeholder shared/telemetry/ikey.json.'+ );+ process.exit(1);+}++console.log('All plugin telemetry instrumentation keys and event stream names are unique.');diff --git a/shared/telemetry/README.md b/shared/telemetry/README.mdindex 02eebd04d..1acda0f14 100644--- a/shared/telemetry/README.md+++ b/shared/telemetry/README.md@@ -186,7 +186,22 @@ is never touched. (Power-pages is the reference example: see`plugins/power-pages/scripts/lib/telemetry/resolver.js` + `region/`.)**Ship with `disabled: true`** until the tenant-side annotation, Kusto table, and-FieldNameMappings are provisioned. The committed `ikey.json` must stay `disabled: true`.+FieldNameMappings are provisioned. Keep it `disabled: true` for as long as the plugin is+unprovisioned; once the tenant-side stream is live you flip it to `disabled: false` and the+committed `ikey.json` ships enabled (as `power-pages` does — see the CI opt-out guidance in+the repo-root `AGENTS.md`).++**Provision a fresh key — never copy another plugin's.** Your `ikey.json` must carry+this plugin's own instrumentation key(s) and `event_stream_name`. Do not lift another+adopter's `ikey.json` (e.g. power-pages') wholesale — that mis-attributes your events to+their Kusto stream. This is CI-enforced by `scripts/validate-telemetry-ikeys.js` (run in+the `validate-repository-metadata` workflow), which fails if the same key or+`event_stream_name` appears under two different plugins. Run it locally after editing+`ikey.json`:++```bash+node scripts/validate-telemetry-ikeys.js+```### 3. Register hooks