{"record":{"id":"bd7bc6fc90161ddb","repo":"thanos-io/thanos","slug":"marshal-exemplars","errorCode":null,"errorMessage":"marshal exemplars","messagePattern":"marshal exemplars","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/receive/writecapnp/marshal.go","lineNumber":93,"sourceCode":"\t}\n\tfor i, ts := range tsreq {\n\t\ttsc := series.At(i)\n\n\t\tlblsc, err := tsc.NewLabels(int32(len(ts.Labels)))\n\t\tif err != nil {\n\t\t\treturn errors.Wrap(err, \"new labels\")\n\t\t}\n\t\tif err := marshalLabels(lblsc, ts.Labels, builder); err != nil {\n\t\t\treturn errors.Wrap(err, \"marshal labels\")\n\t\t}\n\t\tif err := marshalSamples(tsc, ts.Samples); err != nil {\n\t\t\treturn errors.Wrap(err, \"marshal samples\")\n\t\t}\n\t\tif err := marshalHistograms(tsc, ts.Histograms); err != nil {\n\t\t\treturn errors.Wrap(err, \"marshal histograms\")\n\t\t}\n\t\tif err := marshalExemplars(tsc, ts.Exemplars, builder); err != nil {\n\t\t\treturn errors.Wrap(err, \"marshal exemplars\")\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc BuildIntoSingleTenantWriteRequest(wr WriteRequest, tenant string, tsreq []prompb.TimeSeries) error {\n\tif err := wr.SetTenant(tenant); err != nil {\n\t\treturn errors.Wrap(err, \"set tenant\")\n\t}\n\n\tseries, err := wr.NewTimeSeries(int32(len(tsreq)))\n\tif err != nil {\n\t\treturn err\n\t}\n\tbuilder := symboltable.NewBuilder()\n\tfor i, ts := range tsreq {\n\t\ttsc := series.At(i)","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/receive/writecapnp/marshal.go#L75-L111","documentation":"In BuildInto (writecapnp marshal), marshalExemplars failed while copying a timeseries' exemplars into the capnproto replication message — typically a capnproto list/allocation error (e.g. message capacity exhausted for very large exemplar sets) — so the whole WriteRequest replication payload cannot be built.","triggerScenarios":"marshalExemplars fails during exemplar list allocation or while writing exemplar label strings — typically arena exhaustion or invalid exemplar label data.","commonSituations":"Exemplar-heavy workloads (traces attached to many samples); very long trace_id span_id label values; batches near capnp size limits.","solutions":["Limit the number of exemplars per series before marshaling","Truncate/sanitize exemplar label values (e.g. long trace ids)","Chunk the WriteRequest into smaller batches","Check capnp library version for text-field size constraints"],"exampleFix":"// before\nexemplars := ts.Exemplars\n// after\nif len(ts.Exemplars) > maxExemplars {\n    ts.Exemplars = ts.Exemplars[:maxExemplars]\n}\nerr := marshalExemplars(tsc, ts.Exemplars, builder)","handlingStrategy":"validation","validationCode":"if len(ts.Exemplars) > maxExemplarsPerSeries {\n    return errors.New(\"too many exemplars per series\")\n}\nfor _, e := range ts.Exemplars {\n    for _, l := range e.GetLabels() { if len(l.GetValue()) > 4096 { return errors.New(\"exemplar label too long\") } }\n}","typeGuard":null,"tryCatchPattern":"if err := BuildInto(tuple, tenant, tsreq, builder); err != nil && strings.Contains(err.Error(), \"marshal exemplars\") {\n    // retry with exemplars stripped\n    return rebuildWithoutExemplars(tsreq)\n}","preventionTips":["Limit exemplars per series","Truncate long trace/span id values","Use the shared symboltable builder to deduplicate strings"],"tags":["capnp","serialization","exemplars"],"backgroundTag":"schema-validation-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"}