Skip to content

feat: add WIL-based TraceLogging ETW telemetry (experimental)#493

Draft
RamonArjona4 wants to merge 6 commits into
mainfrom
user/ramonarjona4/tracelogging
Draft

feat: add WIL-based TraceLogging ETW telemetry (experimental)#493
RamonArjona4 wants to merge 6 commits into
mainfrom
user/ramonarjona4/tracelogging

Conversation

@RamonArjona4
Copy link
Copy Markdown
Member

@RamonArjona4 RamonArjona4 commented Jun 4, 2026

Implements WIL-based TraceLogging ETW telemetry for MXC following the WinAppSDK pattern exactly:

  • New mxc_wil_telemetry crate: C++ shim using WIL TraceLoggingProvider with SRWLOCK-protected state, Part B common fields, and flat extern C FFI surface for safe Rust wrappers
  • WIL headers downloaded from NuGet at build time (header-only, MIT)
  • Private GUID substitution via MXC_TELEMETRY_CONFIG_OVERRIDE env var, mirroring WinAppSDK's UpdateTraceloggingConfig pipeline step
  • Pipeline integration: NuGet auth, restore, env var injection in Rust.Build.Job.yml (no continueOnError, matching WinAppSDK)
  • Deterministic NuGet restore via scoped nuget.config with
  • Sticky cache prevention: .public backup/restore of traceloggingconfig.h
  • Events: MXC.Execution and MXC.Error with sanitized error messages
  • FailurePhase-aware failure classification (InitError vs ProcessError)
  • Telemetry gated behind experimental.telemetry.enabled config flag
  • Comprehensive test suite: 12 FFI unit tests, E2E tests, build override validation script, ETW capture smoke test
  • Architecture documentation in docs/telemetry-wil-integration.md

📖 Description

This PR will add Tracelogging to the released npm package of mxc for Windows. Tracelogging on Linux or Mac systems is a no-op. Tracelogging is limited to simple usage and failure details of the MXC executable as built and distributed through npm.

🔗 References

#492

🔍 Validation

Built locally and ran unit tests

✅ Checklist

📋 Issue Type

  • Bug fix
  • [ x] Feature
  • Task

Microsoft reviewers: PR builds don't auto-run (ADO policy). Comment /azp run
to start MXC-PR-Build. See docs/pull-requests.md.

Microsoft Reviewers: Open in CodeFlow

Implements WIL-based TraceLogging ETW telemetry for MXC following the
WinAppSDK pattern exactly:

- New mxc_wil_telemetry crate: C++ shim using WIL TraceLoggingProvider
  with SRWLOCK-protected state, Part B common fields, and flat extern C
  FFI surface for safe Rust wrappers
- WIL headers downloaded from NuGet at build time (header-only, MIT)
- Private GUID substitution via MXC_TELEMETRY_CONFIG_OVERRIDE env var,
  mirroring WinAppSDK's UpdateTraceloggingConfig pipeline step
- Pipeline integration: NuGet auth, restore, env var injection in
  Rust.Build.Job.yml (no continueOnError, matching WinAppSDK)
- Deterministic NuGet restore via scoped nuget.config with <clear/>
- Sticky cache prevention: .public backup/restore of traceloggingconfig.h
- Events: MXC.Execution and MXC.Error with sanitized error messages
- FailurePhase-aware failure classification (InitError vs ProcessError)
- Telemetry gated behind experimental.telemetry.enabled config flag
- Comprehensive test suite: 12 FFI unit tests, E2E tests, build override
  validation script, ETW capture smoke test
- Architecture documentation in docs/telemetry-wil-integration.md

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 4, 2026 00:11
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds an experimental TraceLogging ETW telemetry pipeline to MXC, including a WIL-based C++ shim with Rust wrappers, config/schema plumbing (experimental.telemetry.enabled), internal-build GUID/license override hooks, and validation scripts/tests/docs.

Changes:

  • Introduces mxc_wil_telemetry (build-time WIL header acquisition + C++ TraceLogging provider shim + Rust FFI wrappers).
  • Adds wxc_common::telemetry module and wires telemetry init/emit/shutdown into wxc-exec and lxc-exec behind --experimental + config flag.
  • Adds schema/docs/examples/tests and ADO pipeline steps for internal GUID substitution + SDK license override.

Reviewed changes

Copilot reviewed 28 out of 30 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/scripts/run_telemetry_etw_smoke_test.ps1 Adds an admin-required ETW capture smoke test script for the public provider GUID.
tests/scripts/run_telemetry_build_override_test.ps1 Adds a validation script for MXC_TELEMETRY_CONFIG_OVERRIDE build behavior.
tests/examples/28_telemetry_enabled.json Adds an example config enabling experimental telemetry.
src/testing/wxc_e2e_tests/tests/e2e_windows.rs Adds ignored Windows E2E tests for telemetry enabled/disabled paths.
src/testing/wxc_e2e_tests/src/lib.rs Adds run_wxc_example() helper for running configs from tests/examples/.
src/mxc_wil_telemetry/src/lib.rs Implements Rust-safe wrappers around the C++ telemetry shim (no-op on non-Windows).
src/mxc_wil_telemetry/shim/mxc_telemetry_shim.h Declares the extern “C” surface for Rust FFI.
src/mxc_wil_telemetry/shim/mxc_telemetry_shim.cpp Implements WIL TraceLogging provider + Part B fields + event emission.
src/mxc_wil_telemetry/Cargo.toml Adds the new crate with build dependencies for download/extract/compile.
src/mxc_wil_telemetry/build.rs Downloads/extracts WIL headers, applies override, compiles shim (Windows-only).
src/core/wxc/src/main.rs Initializes telemetry from config and emits execution/error events on completion.
src/core/wxc_common/src/telemetry/mod.rs Adds telemetry module entrypoint: enablement logic + init/shutdown.
src/core/wxc_common/src/telemetry/events.rs Defines telemetry event types, sanitization, and emit wrappers.
src/core/wxc_common/src/models.rs Adds experimental.telemetry config model (TelemetryConfig).
src/core/wxc_common/src/lib.rs Exposes telemetry module from wxc_common.
src/core/wxc_common/src/config_parser.rs Parses experimental.telemetry.enabled into TelemetryConfig + tests.
src/core/wxc_common/Cargo.toml Links wxc_common against the new mxc_wil_telemetry crate.
src/core/lxc/src/main.rs Mirrors telemetry init/emit wiring for the Linux executor (no-op behavior).
src/Cargo.toml Adds mxc_wil_telemetry to the Rust workspace + workspace deps.
src/Cargo.lock Updates lockfile for new crate + added build dependencies.
sdk/src/types.ts Adds TypeScript TelemetryConfig and experimental.telemetry typing.
scripts/apply-license-override.ps1 Adds script for internal license override injection/restoration.
schemas/dev/mxc-config.schema.0.7.0-dev.json Extends dev schema with experimental.telemetry.enabled.
README.md Documents experimental telemetry behavior and adds doc link.
docs/telemetry-wil-integration.md Adds detailed architecture and internal-build override documentation.
docs/schema.md Updates schema docs to include experimental.telemetry.
build/telemetry/packages.config Adds private NuGet package manifest for internal telemetry group GUID header.
build/telemetry/nuget.config Adds scoped nuget.config with <clear/> for deterministic internal restore.
.gitignore Ignores restored private telemetry package artifacts and license backup.
.azure-pipelines/templates/Rust.Build.Job.yml Adds official-build steps for internal NuGet restore + env var injection + license override.

Comment thread tests/examples/28_telemetry_enabled.json Outdated
Comment thread src/mxc_wil_telemetry/build.rs Outdated
Comment thread src/mxc_wil_telemetry/build.rs Outdated
Comment thread src/core/wxc_common/src/telemetry/events.rs
Comment thread src/core/wxc_common/src/models.rs
RamonArjona4 and others added 5 commits June 3, 2026 17:25
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@RamonArjona4 RamonArjona4 requested a review from MythiliMur June 4, 2026 23:21
- task: NuGetAuthenticate@1
displayName: 'NuGet authenticate for telemetry config'
inputs:
nuGetServiceConnections: 'TelemetryInternal'
Copy link
Copy Markdown
Collaborator

@bbonaby bbonaby Jun 5, 2026

Choose a reason for hiding this comment

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

issue: so this pipeline is run in the Dart ADO project https://microsoft.visualstudio.com/Dart/_build?definitionId=190018. In there I don't see a service connection for TelemetryInternal so I don't think this would work. That said, we should talk about what you want to do in the pipeline offline as there might be a simpler way to do this.

FYI we have our own nuget feed in there as well https://microsoft.visualstudio.com/Dart/_artifacts/feed/Mxc-Azure-Feed where we can add internal packages which can be retrieved during build time.

condition: and(succeeded(), eq('${{ item.os }}', 'windows'))

# --- SDK license override (mirrors telemetry GUID substitution) ---
# For internal npm publishes, the public MIT-only LICENSE.md is replaced
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

question: "internal npm publishes" what do you mean by this? We only publish to the public npm repository. See my comment above about chatting about what you want to see happen in the pipelines/release package. It's probably better to handle this part in a follow up PR.

Comment on lines +26 to +46
┌──────────────────────────────────────────────────────┐
│ C++ shim (mxc_telemetry_shim.cpp) │
│ Compiled by cc crate in build.rs │
│ │
│ MxcTelemetryProvider : wil::TraceLoggingProvider │
│ ├── IMPLEMENT_TRACELOGGING_CLASS(...) │
│ ├── TraceLoggingOptionMicrosoftTelemetry() │
│ └── _MXC_GENERIC_PARTB_FIELDS on every event │
│ ├── Version │
│ ├── Channel ("dev" / "release") │
│ ├── IsDebugging │
│ └── UTCReplace_AppSessionGuid = true │
└───────────────┬──────────────────────────────────────┘
│ Links against WIL headers (header-only)
┌──────────────────────────────────────────────────────┐
│ WIL (Microsoft.Windows.ImplementationLibrary) │
│ Downloaded from NuGet at build time │
│ MIT licensed, header-only │
│ Version: 1.0.260126.7 │
└──────────────────────────────────────────────────────┘
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

issue: Is there a reason you moved away form using the traceloggigng and now using cpp shims? does WIL have something very specific that the rust crate doesn't have?

Comment on lines +78 to +79
This follows the WinAppSDK pattern described in the WinAppSDK Telemetry
spec (per guidance from Mythilli Srinivasan).
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

issue: can remove since this is the integration guide

2. scripts/apply-license-override.ps1 runs:
├── MXC_LICENSE_OVERRIDE is set:
│ ├── Back up sdk/LICENSE.md → sdk/LICENSE.md.public
│ └── Copy private EULA over sdk/LICENSE.md
Copy link
Copy Markdown
Collaborator

@bbonaby bbonaby Jun 5, 2026

Choose a reason for hiding this comment

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

issue: we need the license to stay MIT in the npm package, unless you spoke to CELA about this?

@@ -0,0 +1,185 @@
// Copyright (c) Microsoft Corporation.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

issue: see questions above. I still don't see why we can't use the tracelogging crate for this.

@@ -0,0 +1,10 @@
{
"$schema": "../../schemas/dev/mxc-config.schema.0.7.0-dev.json",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

issue: bad character at the end by the looks of it

@microsoft-github-policy-service microsoft-github-policy-service Bot added the Needs-Author-Feedback Issue needs attention from issue or PR author label Jun 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs-Author-Feedback Issue needs attention from issue or PR author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants