Remove the Blazor WebAssembly Service Defaults OTLP export workaround after OpenTelemetry supports async export
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
### Description
The Blazor WebAssembly Service Defaults template currently uses `BackgroundExportHandler` to work around synchronous OTLP export on single-threaded WebAssembly.
OpenTelemetry's OTLP exporter calls:
```csharp
HttpClient.SendAsync(...).GetAwaiter().GetResult()
```
This can stall when the HTTP pipeline performs asynchronous work. The template handler avoids that stall by capturing the request, immediately returning a synthetic successful response, and sending the real request asynchronously through a Polly resilience pipeline.
OpenTelemetry added task-based batch and metric workers for single-threaded WebAssembly in open-telemetry/opentelemetry-dotnet#6379, but the worker still invokes the synchronous exporter contract. The remaining limitation is tracked by open-telemetry/opentelemetry-dotnet#7708.
Once that issue is resolved and the fix is available in a stable OpenTelemetry release, remove the template workaround and use the standard OTLP exporter implementation.
### Proposed changes
- Update the Blazor WebAssembly Service Defaults OpenTelemetry dependencies to a stable version containing the fix for open-telemetry/opentelemetry-dotnet#7708.
- Delete `BackgroundExportHandler.cs`.
- Remove the custom `IPostConfigureOptions` configuration that supplies `BackgroundExportHandler`.
- Remove the custom `ResiliencePipelineBuilder` configuration.
- Remove the `Microsoft.Extensions.Http.Resilience` dependency if it is no longer otherwise needed.
- Configure logs, traces, and metrics using the standard `AddOtlpExporter` APIs.
- Allow OTLP exporters to use the normal HTTP client integration without bypassing globally configured asynchronous handlers such as service discovery.
### Validation
Add or update browser integration coverage to verify that, in single-threaded Blazor WebAssembly:
- Logs, traces, and metrics are exported successfully over OTLP/HTTP.
- Export works when `IHttpClientFactory` includes an asynchronous delegating handler, including the globally configured service-discovery handler used by the template.
- Export requests are not reported as successful before the HTTP operation completes.
- Export failures are surfaced through normal OpenTelemetry diagnostics.
- Retry, timeout, flush, and shutdown behavior use OpenTelemetry's standard semantics without fire-and-forget requests.
- No provider must be manually resolved to initialize OpenTelemetry; normal `IHostedService` startup remains sufficient.
### Dependencies
Blocked by:
- open-telemetry/opentelemetry-dotnet#7708
Related:
- #64574
- #64890
- #67259
- #67267
Contributor guide
Research direction
First verify that a stable OpenTelemetry release resolves #7708, then inspect BackgroundExportHandler.cs and the Blazor WebAssembly Service Defaults OpenTelemetry configuration. Run or add browser integration coverage for logs, traces, and metrics over OTLP/HTTP with an asynchronous handler. Done means the workaround and unnecessary resilience dependency are removed, standard AddOtlpExporter APIs are used, and normal export, failure, retry, flush, and shutdown behavior is covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- frontend, observability-sre
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100