{"record":{"id":"35b31684145f4a1a","repo":"thanos-io/thanos","slug":"error-decoding-remote-write-request","errorCode":null,"errorMessage":"Error decoding remote write request","messagePattern":"Error decoding remote write request","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"pkg/receive/handler_otlp.go","lineNumber":72,"sourceCode":"\n\t// Fail request fully if tenant has exceeded set limit.\n\tif !under {\n\t\thttp.Error(w, \"tenant is above active series limit\", http.StatusTooManyRequests)\n\t\treturn\n\t}\n\n\trequestLimiter := h.Limiter.RequestLimiter()\n\tif r.ContentLength >= 0 {\n\t\tif !requestLimiter.AllowSizeBytes(tenant, r.ContentLength) {\n\t\t\thttp.Error(w, \"write request too large\", http.StatusRequestEntityTooLarge)\n\t\t\treturn\n\t\t}\n\t}\n\n\treq, err := remote.DecodeOTLPWriteRequest(r)\n\tif err != nil {\n\t\tlevel.Error(h.logger).Log(\"msg\", \"Error decoding remote write request\", \"err\", err.Error())\n\t\thttp.Error(w, err.Error(), http.StatusBadRequest)\n\t\treturn\n\t}\n\n\tmetrics, _, err := h.convertToPrometheusFormat(ctx, req.Metrics())\n\tif err != nil {\n\t\thttp.Error(w, err.Error(), http.StatusBadRequest)\n\t\treturn\n\t}\n\n\ttotalSamples := 0\n\tfor _, ts := range metrics {\n\t\ttotalSamples += len(ts.Samples)\n\t}\n\n\tif !requestLimiter.AllowSeries(tenant, int64(len(metrics))) {\n\t\thttp.Error(w, \"too many timeseries\", http.StatusRequestEntityTooLarge)\n\t\treturn\n\t}","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/receive/handler_otlp.go#L54-L90","documentation":"This log message accompanies an HTTP 400 returned when remote.DecodeOTLPWriteRequest fails to parse the incoming OTLP/HTTP payload. The handler logs the decode error server-side and returns the raw error text to the client. It means the request body is not a valid protobuf-encoded ExportMetricsServiceRequest (with allowed content-type/encoding).","triggerScenarios":"POSTing a body to /api/v1/otlp/v1/metrics that is not valid OTLP protobuf (wrong content-type, e.g. JSON when protobuf expected, or gzipped body without Content-Encoding: gzip, truncated body, wrong proto version).","commonSituations":"Client using OTLP/HTTP JSON instead of protobuf; double-compression or missing gzip header; network proxy rewriting the body; mismatched OTLP protocol versions between client and receive.","solutions":["Ensure the client sends Content-Type: application/x-protobuf with a valid protobuf-encoded OTLP ExportMetricsServiceRequest.","If sending JSON, configure the client for OTLP/HTTP JSON and verify receive accepts that content type.","Check Content-Encoding: gzip is set correctly and the body is compressed exactly once.","Read the returned error text in the 400 response; it names the exact decode failure.","Upgrade/downgrade the OTLP client library to match the receiver's prometheus/thanos OTLP support."],"exampleFix":"// before: JSON body without proper content type\nreq.Header.Set(\"Content-Type\", \"application/json\")\n// after\nreq.Header.Set(\"Content-Type\", \"application/x-protobuf\")\nreq.Header.Set(\"Content-Encoding\", \"gzip\")","handlingStrategy":"validation","validationCode":"// client side: ensure protobuf encoding\nreq.Header.Set(\"Content-Type\", \"application/x-protobuf\")\n// optionally verify body parses before send\nproto.Unmarshal(payload, &colmetricpb.ExportMetricsServiceRequest{})","typeGuard":null,"tryCatchPattern":"if resp.StatusCode == 400 { log.Fatalf(\"OTLP decode rejected: %s\", resp.Body) }","preventionTips":["Use a maintained OTLP client library, never hand-serialize protobuf","Keep Content-Type/Content-Encoding headers correct","Integration-test against the real receive endpoint"],"tags":["http","protobuf","otlp","decoding"],"backgroundTag":"protobuf-unmarshal-failed","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}