elsa-workflows/elsa-core · error · RequestBodyTooLargeException

RequestBodyTooLargeException

Error message

RequestBodyTooLargeException

What it means

The OTLP HTTP ingestion endpoint streams the request body into memory and enforces a configured maximum body size. ReadBodyAsync throws RequestBodyTooLargeException as soon as the accumulated byte count exceeds that limit, protecting the process from unbounded memory use from large OTLP payloads.

Solutions

  1. Reduce the exporter's batch size / send delay so each request stays under the limit.
  2. Raise the configured max body size for the OpenTelemetry diagnostics ingestion options if the payloads are legitimately sized.
  3. Shrink payload content (trim resource attributes, lower sampling rate) before export.

Example fix

// before
config.BatchExportOptions.MaxExportBatchSize = 10_000;

// after
config.BatchExportOptions.MaxExportBatchSize = 512; // keep bodies under the ingestion max
Defensive patterns

Strategy: try-catch

Validate before calling

if (request.Content is not null && request.Content.Headers.ContentLength is long len && len > maxBodySize)
    throw new InvalidOperationException("Batch would exceed ingestion max body size; reduce batch size.");

Try / catch

try { await exporter.ExportAsync(batch); }
catch (RequestBodyTooLargeException) { await exporter.ExportAsync(SplitBatch(batch)); }

Prevention

When it happens

Trigger: POSTing an OTLP protobuf export request whose body exceeds the configured max body size (OpenTelemetryDiagnosticsOptions max body size / MaxRequestBodySize) to the ingestion endpoint.

Common situations: A batch exporter configured with a large batch size or queue size sends big trace/log batches; an OTLP exporter retries with an even larger merged batch; high-cardinality resource attributes inflate the payload.

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 elsa-workflows/elsa-core@fe9217bdfa (2026-09-13). Data as JSON: /api/errors/f69c68e10f28f23d. Report an issue: GitHub.

Appendix: source

Thrown at src/modules/Elsa.Diagnostics.OpenTelemetry/Extensions/EndpointRouteBuilderExtensions.cs:100

        {
            return Results.BadRequest();
        }
    }

    private static async Task<ReadOnlyMemory<byte>> ReadBodyAsync(HttpContext httpContext, long maxBodySize, CancellationToken cancellationToken)
    {
        using var stream = new MemoryStream();
        var buffer = ArrayPool<byte>.Shared.Rent(81920);
        var totalBytes = 0L;

        try
        {
            int read;
            while ((read = await httpContext.Request.Body.ReadAsync(buffer.AsMemory(0, buffer.Length), cancellationToken)) > 0)
            {
                totalBytes += read;
                if (totalBytes > maxBodySize)
                    throw new RequestBodyTooLargeException();

                stream.Write(buffer, 0, read);
            }
        }
        finally
        {
            ArrayPool<byte>.Shared.Return(buffer);
        }

        return stream.ToArray();
    }

    private sealed class RequestBodyTooLargeException : Exception;
}

View on GitHub (pinned to fe9217bdfa)