{"record":{"id":"a43aeb52ece4db56","repo":"microsoft/aspire","slug":"the-request-body-was-larger-than-the-max-allowed-of","errorCode":null,"errorMessage":"The request body was larger than the max allowed of {MaxRequestSize} bytes.","messagePattern":"The request body was larger than the max allowed of (.+?) bytes\\.","errorType":"http","errorClass":"BadHttpRequestException","httpStatus":400,"severity":"error","filePath":"src/Aspire.Dashboard/Otlp/Http/OtlpHttpEndpointsBuilder.cs","lineNumber":269,"sourceCode":"    {\n        const int MaxRequestSize = 1024 * 1024 * 4; // 4 MB. Matches default gRPC request limit.\n\n        ReadResult result = default;\n        try\n        {\n            do\n            {\n                result = await httpContext.Request.BodyReader.ReadAsync().ConfigureAwait(false);\n\n                if (result.IsCanceled)\n                {\n                    throw new OperationCanceledException(\"Read call was canceled.\");\n                }\n\n                if (result.Buffer.Length > MaxRequestSize)\n                {\n                    // Too big!\n                    throw new BadHttpRequestException(\n                        $\"The request body was larger than the max allowed of {MaxRequestSize} bytes.\",\n                        StatusCodes.Status400BadRequest);\n                }\n\n                if (result.IsCompleted)\n                {\n                    break;\n                }\n                else\n                {\n                    httpContext.Request.BodyReader.AdvanceTo(result.Buffer.Start, result.Buffer.End);\n                }\n            } while (true);\n\n            return exporter(result.Buffer);\n        }\n        finally\n        {","sourceCodeStart":251,"sourceCodeEnd":287,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Dashboard/Otlp/Http/OtlpHttpEndpointsBuilder.cs#L251-L287","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Reduce the exporter's batch/max batch size so each OTLP request stays under MaxRequestSize","Increase the dashboard's max OTLP request size configuration if your workload legitimately needs larger payloads","Enable compression on the exporter (gzip) so large batches fit within the limit","Check for exporter retry loops amplifying payload sizes and cap queue/backlog sizes"],"exampleFix":"// before\nbuilder.Services.Configure<OtlpExporterOptions>(o => { }); // default large batches\n// after\nbuilder.Services.Configure<BatchExportActivityProcessorOptions>(o =>\n{\n    o.MaxExportBatchSize = 512; // keep each request under the dashboard's MaxRequestSize\n    o.QueueCapacity = 2048;\n});","handlingStrategy":"validation","validationCode":"// Before exporting:\nif (serializedRequestBytes.Length > maxRequestSize)\n    batch = batch.Take(batchSize / 2).ToList(); // shrink batch and re-export","typeGuard":null,"tryCatchPattern":"try { await exporter.ExportAsync(batch, ct); }\ncatch (HttpRequestException ex) when (ex.StatusCode == HttpStatusCode.BadRequest)\n{\n    logger.LogWarning(\"OTLP export rejected (payload too large); splitting batch.\");\n    await ExportInChunksAsync(batch, ct);\n}","preventionTips":["Cap exporter MaxExportBatchSize well below the dashboard's MaxRequestSize","Enable gzip compression on OTLP HTTP exports","Bound the exporter queue so retry backlogs don't create giant batches"],"tags":["http","payload-size","otlp","telemetry"],"backgroundTag":"payload-too-large","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}