Skip to content

fix(telemetry): Re-enable XAML generator telemetry - #25846

Merged
rajamatt merged 3 commits into
masterfrom
dev/mara/xaml-generator-telemetry
Oct 30, 2026
Merged

rajamatt merged 3 commits into
masterfrom
dev/mara/xaml-generator-telemetry

Conversation

@rajamatt

@rajamatt rajamatt commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

GitHub Issue: related to unoplatform/uno-private#2477 (kept open until the release/stable/6.7 backport ships)

PR Type:

🐞 Bugfix

What changed? 🚀

Since 6.7, the XAML generator sends no build telemetry (uno/generation/generate-xaml, -done, -failed), whether or not the build opted out. 93e435f put the client behind isTelemetryOptout() is true. But Uno.DevTools.Telemetry reads enabledProvider as the opt-out flag (Enabled = !enabledProvider()). So an opted-out build got a disabled client, and every other build got none.

The generator now creates a client only when IsTelemetryDisabled is false. It returns true in five cases:

  • The build opts out: UnoPlatformTelemetryOptOut is 1 or true. This is the root-cause fix.
  • The environment opts out: UNO_PLATFORM_TELEMETRY_OPTOUT is 1 or true, read through the build as a CompilerVisibleProperty.
    • The library parses the variable with bool.TryParse, so only true worked, and 6.6 sent telemetry for users who had set 1.
    • A reused compiler server can also predate the variable.
  • It's a design-time build. _isDesignTimeBuild used to be read before it was set, so every design-time build, 6.6 included, started an enabled client, even though the Track* methods then skipped sending. It's now set first.
  • It's a hot-reload build: UnoIsHotReloadHost. The dev server's hot-reload workspace already evaluates as design-time, because MSBuildWorkspace defaults to DesignTimeBuild=true and BuildingProject=false. The explicit check keeps hot reload silent if that changes.
  • The generator itself runs in a browser. This is defensive hardening for single-threaded WebAssembly hosts.
    • With an enabled client, Flush blocks on Task.Wait, which most likely broke the in-browser build that 93e435f fixed.
    • That host has opted out by MSBuild property since February. This check is a second layer and easy to drop.

The generator test assembly sets UNO_PLATFORM_TELEMETRY_OPTOUT=true in an [AssemblyInitialize]. The test harness doesn't pass that variable as a build property, so the generator's own check never sees it. The clients these tests create stay disabled through the library instead.

Builds that haven't opted out send the same events as 6.6. Because an opted-out build has no client, UNO_PLATFORM_TELEMETRY_OPTOUT=false can no longer re-enable a build that set UnoPlatformTelemetryOptOut.

Reviewer's guide

  • XamlCodeGeneration.Telemetry.cs: the gate (InitTelemetry, IsTelemetryDisabled).
  • XamlCodeGeneration.cs: _isDesignTimeBuild moved ahead of InitTelemetry.
  • Uno.UI.SourceGenerators.props: two new CompilerVisibleProperty entries.
  • Given_XamlTelemetry holds the tests. AssemlyInfo.cs holds the test-run opt-out.

Validation

  • Runtime (unit tests): Given_XamlTelemetry covers IsTelemetryDisabled, not how InitTelemetry wires it up.
    • Disabled: opt-outs by the property (true, True, 1), opt-outs by the variable (true, TRUE, 1, including with the property set to false), design-time builds and hot-reload builds.
    • Enabled: "", false or 0 in either place, and UnoIsHotReloadHost=False.
    • Results: 34 of 34 pass.
    • Mutation checks: inverting the predicate fails all 15 new tests. Removing the variable check fails 4. Removing the design-time or hot-reload check fails 1 each.
  • Build wiring: a probe project importing Uno.UI.SourceGenerators.props gets build_property.UNO_PLATFORM_TELEMETRY_OPTOUT and build_property.UnoIsHotReloadHost. A design-time compile writes DesignTimeBuild = true and BuildingProject = false into the generator's config.
  • Full Uno.UI.SourceGenerators.Tests run: 222 passed, 7 skipped, 403 failed, all with Unable to find Uno.UI.dll because Uno.UI wasn't built. That run was on the first commit and hasn't been repeated, and it was built against net10.0 locally because I don't have a .NET 11 SDK. CI runs the full suite.
  • Not validated: an in-browser build, events arriving in Application Insights, and build time against a blocked telemetry endpoint.

Open questions before merge or backport

  • Confirmation from 93e435f's author that skipping the client for opted-out builds was the intent, and team agreement that a 6.7 servicing release resumes collection.
  • Uno's own CI builds don't opt out. Do the dashboards filter them?

Follow-up

  • Backport to release/stable/6.7 after merge. That branch uses Uno.DevTools.Telemetry 1.3.3 and has no Given_XamlTelemetry, so the backport needs adapting. servicing/6.8 has the same check.
  • In Uno.DevTools.Telemetry:
    • accept 1 and 0 for the variable;
    • cap Dispose's drain, which can block a build for up to about 100s on a network that silently drops traffic (as in 6.6);
    • fix the init/Dispose race that leaves a channel undisposed in long-lived processes;
    • note in TelemetryEnvironment's docs that a host may opt out before creating a client.

PR Checklist ✅

  • 🧪 Added Runtime tests, UI tests, or a manual test sample (for bug fixes / features, if applicable): unit tests in Given_XamlTelemetry
  • 📚 Docs have been added/updated following the documentation template (for bug fixes / features): not needed. doc/articles/uno-toolchain-telemetry.md already documents 1 or true, and the generator now matches it
  • 🖼️ Validated PR Screenshots Compare Test Run results.
  • ❗ Contains NO breaking changes
  • 👀 Reviewed 2 other open pull requests (optional but appreciated!)

🤖 Generated with Claude Code

Since 6.7 the generator created its telemetry client only when the
build had opted out, so no build sent generate-xaml events. It now
creates one only when the build hasn't opted out, isn't a design-time
build and isn't running in the browser.

InitTelemetry runs before _isDesignTimeBuild is set, so the design-time
check now reads the context directly.

The generator tests opt out through UNO_PLATFORM_TELEMETRY_OPTOUT, so
running them doesn't send build telemetry.

Related to unoplatform/uno-private#2477

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rajamatt rajamatt self-assigned this Oct 30, 2026
@github-actions github-actions Bot added the area/code-generation Categorizes an issue or PR as relevant to code generation label Oct 30, 2026
The documented UNO_PLATFORM_TELEMETRY_OPTOUT=1 didn't stop the
generator: the telemetry library parses the variable with
bool.TryParse, so only "true" worked, and a reused compiler server can
predate the variable. The generator now reads it through the build and
creates no client when it's "1" or "true".

An MSBuild opt-out also wins over UNO_PLATFORM_TELEMETRY_OPTOUT=false
now, since an opted-out build has no client to enable.

Related to unoplatform/uno-private#2477

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rajamatt
rajamatt marked this pull request as ready for review October 30, 2026 16:31
@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@Xiaoy312 Xiaoy312 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diagnosis checks out: the library treats the provider's result as an opt-out flag, and InitTelemetry ran before _isDesignTimeBuild was set. The new gate is correct for what it claims, and the browser check is worth keeping, since Flush's task.Wait is a hazard on single-threaded WebAssembly.

Before merging, I'd want two things settled: the 93e435f intent question you raised, and opting hot reload out (inline). The rest are suggestions.

FYI: TelemetryEnvironment in the library documents an explicit UNO_PLATFORM_TELEMETRY_OPTOUT=false as forcing telemetry on over the provider. With this PR the generator no longer honours that when UnoPlatformTelemetryOptOut is set. That's the more privacy-friendly direction and you call it out, but the library's docs will now disagree with the generator.

- The dev server's hot-reload workspace flags its builds with
  UnoIsHotReloadHost; the generator now creates no client for them.
  That workspace already evaluates as a design-time build, so this
  keeps hot reload silent if that ever changes.
- Replace the CreateTelemetry factory with an IsTelemetryDisabled
  predicate.
- Set _isDesignTimeBuild before InitTelemetry, and drop the Track*
  checks that a design-time build no longer reaches.
- Comment the environment-variable property and the test hook.

Related to unoplatform/uno-private#2477

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Xiaoy312

Copy link
Copy Markdown
Contributor

@Mergifyio backport release/stable/6.7

@mergify

mergify Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

backport release/stable/6.7

✅ Backports have been created

Details

Cherry-pick of 9d47558 has failed:

On branch mergify/bp/release/stable/6.7/pr-25846
Your branch is up to date with 'origin/release/stable/6.7'.

You are currently cherry-picking commit 9d47558.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   src/SourceGenerators/Uno.UI.SourceGenerators.Tests/AssemlyInfo.cs
	modified:   src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlCodeGeneration.Telemetry.cs

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
	deleted by us:   src/SourceGenerators/Uno.UI.SourceGenerators.Tests/XamlCodeGeneratorTests/Given_XamlTelemetry.cs

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

@rajamatt
rajamatt enabled auto-merge October 30, 2026 18:29
@mergify

mergify Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again.

@rajamatt
rajamatt merged commit 1f2fc30 into master Oct 30, 2026
55 checks passed
@rajamatt
rajamatt deleted the dev/mara/xaml-generator-telemetry branch October 30, 2026 18:52
agneszitte added a commit that referenced this pull request Nov 2, 2026
…6.7/pr-25846

fix(telemetry): Re-enable XAML generator telemetry (backport #25846)
agneszitte added a commit that referenced this pull request Nov 3, 2026
…r-25850

fix(telemetry): Re-enable XAML generator telemetry (backport #25846) (backport #25850)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/code-generation Categorizes an issue or PR as relevant to code generation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants