{"record":{"id":"768792a9461857a5","repo":"SigNoz/signoz","slug":"couldn-t-unmarshal-metric-labels-json-w","errorCode":null,"errorMessage":"couldn't unmarshal metric labels json: %w","messagePattern":"couldn't unmarshal metric labels json: %w","errorType":"exception","errorClass":"model.InternalError","httpStatus":500,"severity":"error","filePath":"pkg/query-service/app/clickhouseReader/reader.go","lineNumber":3430,"sourceCode":"\tif rows.Next() {\n\n\t\tresult = &model.MetricStatus{}\n\t\tvar labelsJson string\n\n\t\terr := rows.Scan(\n\t\t\t&result.MetricName,\n\t\t\t&labelsJson,\n\t\t\t&result.LastReceivedTsMillis,\n\t\t)\n\t\tif err != nil {\n\t\t\treturn nil, model.InternalError(fmt.Errorf(\n\t\t\t\t\"couldn't scan metric status row: %w\", err,\n\t\t\t))\n\t\t}\n\n\t\terr = json.Unmarshal([]byte(labelsJson), &result.LastReceivedLabels)\n\t\tif err != nil {\n\t\t\treturn nil, model.InternalError(fmt.Errorf(\n\t\t\t\t\"couldn't unmarshal metric labels json: %w\", err,\n\t\t\t))\n\t\t}\n\t}\n\n\treturn result, nil\n}\n\nfunc isColumn(tableStatement, attrType, field, datType string) bool {\n\tname := fmt.Sprintf(\"`%s`\", utils.GetClickhouseColumnNameV2(attrType, datType, field))\n\treturn strings.Contains(tableStatement, fmt.Sprintf(\"%s \", name))\n}\n\nfunc (r *ClickHouseReader) GetLogAggregateAttributes(ctx context.Context, req *v3.AggregateAttributeRequest) (*v3.AggregateAttributeResponse, error) {\n\n\tctx = ctxtypes.NewContextWithCommentVals(ctx, map[string]string{\n\t\tinstrumentationtypes.TelemetrySignal:  telemetrytypes.SignalLogs.StringValue(),\n\t\tinstrumentationtypes.CodeNamespace:    \"clickhouse-reader\",","sourceCodeStart":3412,"sourceCodeEnd":3448,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/query-service/app/clickhouseReader/reader.go#L3412-L3448","documentation":"Internal error when the labels JSON string scanned from the time_series row cannot be unmarshalled into the label-map type. The stored last_received_labels value is malformed or not valid JSON.","triggerScenarios":"Corrupted label JSON in ClickHouse (truncated write, wrong encoding), or a schema change where the column contains a non-JSON value (e.g. empty string or array format).","commonSituations":"Data corruption from interrupted ingester writes; older SigNoz versions storing labels differently; manual edits to the table.","solutions":["Select last_received_labels for the affected metric manually and inspect the value","If data is corrupt, delete/re-ingest the affected series or guard unmarshal per-row","Verify query-service and schema versions match","Add a fallback that tolerates empty/invalid label JSON"],"exampleFix":"// before\nerr = json.Unmarshal([]byte(labelsJson), &result.LastReceivedLabels)\nif err != nil { return nil, model.InternalError(...) }\n\n// after\nif labelsJson != \"\" {\n    if err := json.Unmarshal([]byte(labelsJson), &result.LastReceivedLabels); err != nil {\n        r.logger.Error(\"bad labels json\", errorsV2.Attr(err))\n    }\n}","handlingStrategy":"try-catch","validationCode":"if !json.Valid([]byte(labelsJson)) {\n    log.Warn(\"invalid labels json; ignoring\")\n    continue\n}","typeGuard":"func isValidLabelsJSON(s string) bool { return s == \"\" || json.Valid([]byte(s)) }","tryCatchPattern":"if err := json.Unmarshal(data, &v); err != nil {\n    log.Warn(\"bad labels json\", err); v = nil // degrade, don't fail request\n}","preventionTips":["Validate JSON before unmarshal","Investigate writes producing corrupt label JSON"],"tags":["signoz","json","unmarshal","corrupt-data"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}