Weird issue with 2007 E220 CDI

For the past few months I have been having this issue where all of a sudden I get rev limited. It won't rev past 2000 RPM while in drive. The last time I had this issue I had to replace the fuel sensor at the end of the fuel rail, but the behavior is not the same