microsoft/aspire · error · BadHttpRequestException

The request body was larger than the max allowed of

Error message

The request body was larger than the max allowed of {MaxRequestSize} bytes.

What it means

OtlpHttpEndpointsBuilder.ReadOtlpData streams the HTTP request body through PipeReader and enforces a maximum request size (MaxRequestSize). If a buffered chunk exceeds that limit it throws BadHttpRequestException with HTTP 400 status, protecting the dashboard process from unbounded memory usage from huge OTLP payloads.

Solutions

  1. Reduce the exporter's batch/max batch size so each OTLP request stays under MaxRequestSize
  2. Increase the dashboard's max OTLP request size configuration if your workload legitimately needs larger payloads
  3. Enable compression on the exporter (gzip) so large batches fit within the limit
  4. Check for exporter retry loops amplifying payload sizes and cap queue/backlog sizes

Example fix

// before
builder.Services.Configure<OtlpExporterOptions>(o => { }); // default large batches
// after
builder.Services.Configure<BatchExportActivityProcessorOptions>(o =>
{
    o.MaxExportBatchSize = 512; // keep each request under the dashboard's MaxRequestSize
    o.QueueCapacity = 2048;
});
Defensive patterns

Strategy: validation

Validate before calling

// Before exporting:
if (serializedRequestBytes.Length > maxRequestSize)
    batch = batch.Take(batchSize / 2).ToList(); // shrink batch and re-export

Try / catch

try { await exporter.ExportAsync(batch, ct); }
catch (HttpRequestException ex) when (ex.StatusCode == HttpStatusCode.BadRequest)
{
    logger.LogWarning("OTLP export rejected (payload too large); splitting batch.");
    await ExportInChunksAsync(batch, ct);
}

Prevention

When it happens

Trigger: Posting OTLP protobuf/JSON export requests whose body exceeds MaxRequestSize — e.g. a batch with tens of thousands of spans/logs/metrics or very large attribute values sent to the dashboard's OTLP HTTP endpoint.

Common situations: Applications exporting large telemetry batches with high cardinality; misconfigured batch processors accumulating oversized payloads; load tests flooding the OTLP endpoint; SDK retry logic resending an accumulated backlog after downtime.

Understand the failure class

Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/a43aeb52ece4db56. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Dashboard/Otlp/Http/OtlpHttpEndpointsBuilder.cs:269

    {
        const int MaxRequestSize = 1024 * 1024 * 4; // 4 MB. Matches default gRPC request limit.

        ReadResult result = default;
        try
        {
            do
            {
                result = await httpContext.Request.BodyReader.ReadAsync().ConfigureAwait(false);

                if (result.IsCanceled)
                {
                    throw new OperationCanceledException("Read call was canceled.");
                }

                if (result.Buffer.Length > MaxRequestSize)
                {
                    // Too big!
                    throw new BadHttpRequestException(
                        $"The request body was larger than the max allowed of {MaxRequestSize} bytes.",
                        StatusCodes.Status400BadRequest);
                }

                if (result.IsCompleted)
                {
                    break;
                }
                else
                {
                    httpContext.Request.BodyReader.AdvanceTo(result.Buffer.Start, result.Buffer.End);
                }
            } while (true);

            return exporter(result.Buffer);
        }
        finally
        {

View on GitHub (pinned to 25830f84bd)