{"record":{"id":"41dfe2dbbfb76e8d","repo":"kubernetes/kops","slug":"converting-to-proto-w","errorCode":null,"errorMessage":"converting to proto: %w","messagePattern":"converting to proto: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/otel/otlptracefile/writer.go","lineNumber":117,"sourceCode":"\tw.typeCodes[typeName] = TypeCode(typeCode)\n}\n\n// writeObject appends an object to the file\nfunc (w *writer) writeObject(ctx context.Context, obj proto.Message) error {\n\ttypeCode, err := w.codeForType(ctx, obj)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\treturn w.writeObjectWithTypeCode(ctx, typeCode, obj)\n}\n\n// writeObjectWithTypeCode is the key function here.  We encode and write the object.\n// We include a header that identifies the object using the provided typeCode.\nfunc (w *writer) writeObjectWithTypeCode(ctx context.Context, typeCode TypeCode, obj proto.Message) error {\n\tbuf, err := proto.Marshal(obj)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"converting to proto: %w\", err)\n\t}\n\n\tcrc32q := crc32.MakeTable(crc32.Castagnoli)\n\tchecksum := crc32.Checksum(buf, crc32q)\n\n\tflags := uint32(0)\n\n\tw.fileMutex.Lock()\n\tdefer w.fileMutex.Unlock()\n\n\tif w.f == nil {\n\t\treturn fmt.Errorf(\"already closed\")\n\t}\n\n\t// write the object with a header.\n\theader := make([]byte, 16)\n\tbinary.BigEndian.PutUint32(header[0:4], uint32(len(buf)))\n\tbinary.BigEndian.PutUint32(header[4:8], checksum)","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/otel/otlptracefile/writer.go#L99-L135","documentation":"writeObjectWithTypeCode serializes each trace object with proto.Marshal before framing it in the file. If the proto message cannot be marshaled (invalid message, unset required-ish data, corrupted internal state), the error is wrapped as \"converting to proto: %w\".","triggerScenarios":"Writing a trace span/resource message whose underlying protobuf has an invalid field (e.g. NaN/unencodable value in a value, nil-required submessage) during codeForType/writeObject.","commonSituations":"Span attributes containing exotic types from instrumentation libraries; corrupted resource data from a buggy SDK version.","solutions":["Upgrade the OTel SDK / instrumentation libraries producing the malformed spans.","Identify the offending span via surrounding logs and sanitize its attributes before export.","Report the issue upstream with the wrapped proto error message if it persists."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := w.writeObject(ctx, obj); err != nil {\n    if strings.Contains(err.Error(), \"converting to proto\") {\n        // drop/skip the malformed object and continue, log the wrapped cause\n        return nil\n    }\n    return err\n}","preventionTips":["Keep OTel SDK and proto libraries on compatible versions","Sanitize span attributes from third-party instrumentation","Log the wrapped cause to identify the offending message type"],"tags":["opentelemetry","protobuf","serialization"],"backgroundTag":"proto-marshal-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}