{"record":{"id":"f69c68e10f28f23d","repo":"elsa-workflows/elsa-core","slug":"requestbodytoolargeexception","errorCode":null,"errorMessage":"RequestBodyTooLargeException","messagePattern":"RequestBodyTooLargeException","errorType":"http","errorClass":"RequestBodyTooLargeException","httpStatus":413,"severity":"error","filePath":"src/modules/Elsa.Diagnostics.OpenTelemetry/Extensions/EndpointRouteBuilderExtensions.cs","lineNumber":100,"sourceCode":"        {\n            return Results.BadRequest();\n        }\n    }\n\n    private static async Task<ReadOnlyMemory<byte>> ReadBodyAsync(HttpContext httpContext, long maxBodySize, CancellationToken cancellationToken)\n    {\n        using var stream = new MemoryStream();\n        var buffer = ArrayPool<byte>.Shared.Rent(81920);\n        var totalBytes = 0L;\n\n        try\n        {\n            int read;\n            while ((read = await httpContext.Request.Body.ReadAsync(buffer.AsMemory(0, buffer.Length), cancellationToken)) > 0)\n            {\n                totalBytes += read;\n                if (totalBytes > maxBodySize)\n                    throw new RequestBodyTooLargeException();\n\n                stream.Write(buffer, 0, read);\n            }\n        }\n        finally\n        {\n            ArrayPool<byte>.Shared.Return(buffer);\n        }\n\n        return stream.ToArray();\n    }\n\n    private sealed class RequestBodyTooLargeException : Exception;\n}\n","sourceCodeStart":82,"sourceCodeEnd":115,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Diagnostics.OpenTelemetry/Extensions/EndpointRouteBuilderExtensions.cs#L82-L115","documentation":"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.","triggerScenarios":"POSTing an OTLP protobuf export request whose body exceeds the configured max body size (OpenTelemetryDiagnosticsOptions max body size / MaxRequestBodySize) to the ingestion endpoint.","commonSituations":"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.","solutions":["Reduce the exporter's batch size / send delay so each request stays under the limit.","Raise the configured max body size for the OpenTelemetry diagnostics ingestion options if the payloads are legitimately sized.","Shrink payload content (trim resource attributes, lower sampling rate) before export."],"exampleFix":"// before\nconfig.BatchExportOptions.MaxExportBatchSize = 10_000;\n\n// after\nconfig.BatchExportOptions.MaxExportBatchSize = 512; // keep bodies under the ingestion max","handlingStrategy":"try-catch","validationCode":"if (request.Content is not null && request.Content.Headers.ContentLength is long len && len > maxBodySize)\n    throw new InvalidOperationException(\"Batch would exceed ingestion max body size; reduce batch size.\");","typeGuard":null,"tryCatchPattern":"try { await exporter.ExportAsync(batch); }\ncatch (RequestBodyTooLargeException) { await exporter.ExportAsync(SplitBatch(batch)); }","preventionTips":["Size exporter batches conservatively relative to the server's max body size.","Cap resource attribute counts and payload size in the emitting SDK."],"tags":["opentelemetry","http","payload-size","limits"],"backgroundTag":"payload-too-large","analyzedSha":"fe9217bdfa0e27f0e09e45006eb6898f616e513d","analyzedAt":"2026-09-13T20:32:34.702Z","contentChangedAt":"2026-09-13T20:32:34.702Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}