There are micromechanical accelerometers in 3D for attitude reference. The raw attitude needs to be integrated over longish time to even out random changes. In the similar way, there are etiher optical gyros or micromechanical rotation sensors. The magnetic heading is sensed with 3D Hall sensors and rotated to the sensed attitude to compensate for aircraft attitude and magnetic field tilt.
The main reason for integrating the attitude is that the sensed vertical differs from the real one in turns and sudden pitch changes.
The attitude gyro in conventional instruments is actually integrating the sensed vertical with a long time constant. The gyro units contain special valve systems to adjust the position in the long run.
The electronic sensors are currently available in packages of the size of a cigarette pack (AHRS), but they are not aircraft-certifiable.
In previous instruments, the magnetic heading was sensed with a flux valve, which is a saturable magnetic core. It gives out a 3 phase signal which goes to a synchro-based servo adjusting the heading master gyro. The output of the master gyro steers the main heading reference system.