Skip to content

Fix MAUI OTLP dev tunnel endpoint resolution#18053

Open
jfversluis wants to merge 2 commits into
microsoft:mainfrom
jfversluis:jfversluis/fix-maui-otlp
Open

Fix MAUI OTLP dev tunnel endpoint resolution#18053
jfversluis wants to merge 2 commits into
microsoft:mainfrom
jfversluis:jfversluis/fix-maui-otlp

Conversation

@jfversluis

Copy link
Copy Markdown
Member

Description

Fixes MAUI OTLP dev tunnel endpoint resolution so mobile apps send telemetry to the actual Aspire dashboard OTLP endpoint when the dashboard uses dynamically allocated ports.

Previously, WithOtlpDevTunnel() resolved the tunnel target from configuration and could fall back to the default OTLP port (18889) when no static dashboard OTLP endpoint URL was configured. File-based AppHosts commonly use dynamic dashboard OTLP ports, so the MAUI app could receive a dev tunnel endpoint that targeted a stale/non-listening port and telemetry would not appear in the dashboard.

This change makes the MAUI OTLP dev tunnel:

  • use the actual dashboard OTLP endpoint from ResourceEndpointsAllocatedEvent when no explicit OTLP endpoint URL is configured
  • preserve configured/static OTLP endpoint URL behavior
  • fail fast with a clear error if no configured OTLP endpoint exists and the dashboard is disabled or lacks an allocated OTLP endpoint
  • share the canonical dashboard resource and OTLP endpoint names from src/Shared

User-facing usage

The documented MAUI pattern continues to work without custom fixed-port workarounds:

var mobile = builder.AddMauiProject("mobile", "./AspireWithMaui.Mobile/AspireWithMaui.Mobile.csproj");

mobile.AddiOSSimulator()
    .WithOtlpDevTunnel()
    .WithReference(apiService, publicDevTunnel);

mobile.AddAndroidEmulator()
    .WithOtlpDevTunnel()
    .WithReference(apiService, publicDevTunnel);

When the dashboard allocates OTLP/gRPC dynamically, the generated MAUI environment now points to a dev tunnel for that allocated port instead of the stale fallback 18889.

Validation:

dotnet test --project tests/Aspire.Hosting.Maui.Tests/Aspire.Hosting.Maui.Tests.csproj --no-launch-profile -- --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"

Result: 76 passed.

Manual validation was also performed in microsoft/aspire-samples with local packages: the MAUI iOS simulator used a dev tunnel for the dynamic dashboard OTLP/gRPC port and the dashboard showed logs, traces, and metrics for mobile-ios-simulator.

Fixes # (issue)

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No

Resolve MAUI OTLP dev tunnel targets from the actual dashboard OTLP endpoint allocation when no static OTLP endpoint is configured. Preserve configured endpoint behavior and add regression coverage for dynamic, configured, and fail-fast scenarios.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 9, 2026 16:55
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 18053

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 18053"

Copilot AI 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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds support for MAUI OTLP dev tunnel stub endpoints to start with an unallocated (dynamic) port and later adopt the Aspire Dashboard’s allocated OTLP endpoint, plus new tests covering the dynamic/configured/error paths.

Changes:

  • Update OtlpLoopbackResource to allow port to be nullable and to expose the created EndpointAnnotation.
  • Enhance WithOtlpDevTunnel infrastructure to allocate the stub endpoint from dashboard endpoint-allocation events or from configured OTLP endpoint URLs.
  • Add tests validating stub allocation behavior and error handling when dashboard/endpoint allocation is missing.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
tests/Aspire.Hosting.Maui.Tests/MauiPlatformExtensionsTests.cs Adds tests for dynamic dashboard OTLP allocation, configured OTLP endpoint allocation, and failure modes.
src/Aspire.Hosting.Maui/Otlp/OtlpLoopbackResource.cs Makes the OTLP stub endpoint optionally unallocated initially and exposes the endpoint annotation for later mutation.
src/Aspire.Hosting.Maui/MauiOtlpExtensions.cs Implements event-driven stub allocation from dashboard endpoints and adds fast-fail errors when allocation can’t happen.
src/Aspire.Hosting.Maui/Aspire.Hosting.Maui.csproj Links shared known endpoint/resource name constants needed by the new logic.

Comment thread src/Aspire.Hosting.Maui/MauiOtlpExtensions.cs
Comment thread tests/Aspire.Hosting.Maui.Tests/MauiPlatformExtensionsTests.cs
Validate configured OTLP endpoint URLs with clear errors and make dynamic-path tests independent of ambient OTLP configuration.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants