A borehole apparatus for analyzing the composition of a formation fluid is disclosed and generally comprises a testing chamber, a means for directing a sample of fluid into the chamber, a light source which emits at least near infrared rays, a spectral detector, a data base means, and a processing means. The light source is preferably an incandescent lamp and the testing chamber includes a window which is substantially optically transparent to at least one near infrared light, and preferably also the near ultraviolet and visible light of the source. The light source is directed at least partly towards the window in the chamber either via collimation or fiber optics. The spectral detector means is preferably a spectrometer which detects and measures the spectra of the light which has been transmitted through and the light which is backscattered by the fluid sample. The preferred data base means stores the spectra at different pressures and temperatures of water, gas, and a plurality of oils. A determination of the composition of the fluid sample is made by the processing means by obtaining the spectrum of the source, and at least one of the transmitted light or backscattered light spectra, and by fitting the plurality of spectra in the data base to the obtained spectral information. A determination of a transition of the obtained fluid samples from mud filtrate to formation fluids is made by monitoring the visible light and/or near ultraviolet spectrum for changes in large molecule components.