Skip to content

Break Blazor WASM OTLP DI cycle with lazy logger resolution - #67267

Merged
javiercn merged 1 commit into
mainfrom
copilot/fix-circular-di-dependency
Jun 19, 2026
Merged

javiercn merged 1 commit into
mainfrom
copilot/fix-circular-di-dependency

Conversation

Copilot AI commented Jun 17, 2026 •

Copy link
Copy Markdown
Contributor
  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Defer OTLP logger creation to runtime in WASM service defaults

Description

blazorwasm-servicedefaults had a circular dependency in OTLP exporter option post-configuration by resolving ILoggerFactory during singleton construction. This change defers logger resolution to export-time failure paths, removing the startup DI cycle while keeping real warning logs.

  • Problem

    • IPostConfigureOptions<OtlpExporterOptions> eagerly resolved ILoggerFactory, which could trigger OpenTelemetry logger provider creation and recurse back into OtlpExporterOptions construction.
  • Template changes

    • BackgroundExportHandler now takes IServiceProvider instead of ILogger.
    • Logger creation moved to a lazy property (ILoggerFactory resolved only on first log write).
    • Extensions.cs no longer resolves ILoggerFactory inside the IPostConfigureOptions<OtlpExporterOptions> registration; it passes sp into BackgroundExportHandler.
  • Behavioral note

    • Exporter HttpClientFactory is still set centrally via PostConfigureOptions; only logger creation timing changed.
private ILogger? _logger;
private ILogger Logger => _logger ??= serviceProvider
    .GetRequiredService<ILoggerFactory>()
    .CreateLogger("Aspire.OtlpExport");

Copilot AI changed the title [WIP] Fix circular DI dependency in BlazorWasmServiceDefaults template Break Blazor WASM OTLP DI cycle with lazy logger resolution Jun 17, 2026
Copilot AI requested a review from javiercn June 17, 2026 13:05
@javiercn
javiercn marked this pull request as ready for review June 17, 2026 14:27
Copilot AI review requested due to automatic review settings June 17, 2026 14:27

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

This PR updates the blazorwasm-servicedefaults template to avoid a DI circular dependency during startup by deferring OTLP logger creation until it’s actually needed (failure-path logging during export).

Changes:

  • Stop resolving ILoggerFactory during IPostConfigureOptions<OtlpExporterOptions> registration.
  • Change BackgroundExportHandler to accept IServiceProvider and lazily resolve an ILogger on first use.
  • Update OTLP HttpClientFactory wiring to pass the service provider to BackgroundExportHandler.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWasmServiceDefaults-CSharp/Extensions.cs Removes eager logger creation in OTLP post-config and passes IServiceProvider to the handler.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWasmServiceDefaults-CSharp/BackgroundExportHandler.cs Adds lazy logger resolution via IServiceProvider and updates warning logging to use the lazily created logger.


// Send the real request with retries in the background.
_ = SendWithRetryAsync(snapshot, cancellationToken);
_ = SendWithRetryAsync(snapshot, CancellationToken.None);
@javiercn
javiercn force-pushed the copilot/fix-circular-di-dependency branch from 15a88df to b9bea0e Compare June 17, 2026 15:07
@javiercn
javiercn requested a review from a team as a code owner June 17, 2026 19:42
@javiercn
javiercn force-pushed the copilot/fix-circular-di-dependency branch 3 times, most recently from c1260e4 to 88ed277 Compare June 17, 2026 22:07
@javiercn
javiercn requested review from a team, BrennanConroy, halter73 and wtgodbe as code owners June 17, 2026 22:07
@javiercn
javiercn force-pushed the copilot/fix-circular-di-dependency branch 2 times, most recently from 25dae6c to e3c0993 Compare June 17, 2026 22:45
@javiercn
javiercn enabled auto-merge (squash) June 18, 2026 14:19
@javiercn

Copy link
Copy Markdown
Member

/ba-g

- Fix circular DI in BlazorWasmServiceDefaults template (defer logger resolution)
- Fix AddOpenTelemetry API call (overload removed in newer OTel SDK)
- Add StandaloneAppTelemetryFixture with fake OTLP collector, weather API, and proxy
- Add ServiceDiscoveryFetchData.razor page for telemetry E2E tests
- Link template CS/JS source files into StandaloneApp to keep in sync

Co-authored-by: Copilot <[email protected]>
@javiercn
javiercn force-pushed the copilot/fix-circular-di-dependency branch from aa8361e to 00e52df Compare June 19, 2026 07:11
@javiercn

Copy link
Copy Markdown
Member

/ba-g MAC OS issues

@javiercn
javiercn merged commit 108d6b5 into main Jun 19, 2026
17 of 25 checks passed
@javiercn
javiercn deleted the copilot/fix-circular-di-dependency branch June 19, 2026 10:02
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone Jun 23, 2026
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.

5 participants