123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115includeTypesmoduleA=Atomic_moduleCollector=Collectortypecollector=(moduleCollector.S)(** Global collector. *)letcollector:collectoroptionA.t=A.makeNonelet[@inline]enabled()=matchA.getcollectorwith|None->false|Some_->trueletenter_span_collector_(moduleC:Collector.S)?__FUNCTION__~__FILE__~__LINE__?(data=fun()->[])name:span=letdata=data()inC.enter_span?__FUNCTION__~__FILE__~__LINE__~datanamelet[@inline]enter_span?__FUNCTION__~__FILE__~__LINE__?dataname:span=matchA.getcollectorwith|None->Collector.dummy_span|Somecoll->enter_span_collector_coll?__FUNCTION__~__FILE__~__LINE__?datanamelet[@inline]exit_spanspan:unit=matchA.getcollectorwith|None->()|Some(moduleC)->C.exit_spanspanletwith_span_collector_(moduleC:Collector.S)?__FUNCTION__~__FILE__~__LINE__?(data=fun()->[])namef=letdata=data()inletsp=C.enter_span?__FUNCTION__~__FILE__~__LINE__~datanameinmatchfspwith|x->C.exit_spansp;x|exceptionexn->letbt=Printexc.get_raw_backtrace()inC.exit_spansp;Printexc.raise_with_backtraceexnbtlet[@inline]with_span?__FUNCTION__~__FILE__~__LINE__?datanamef=matchA.getcollectorwith|None->(* fast path: no collector, no span *)fCollector.dummy_span|Somecollector->with_span_collector_collector?__FUNCTION__~__FILE__~__LINE__?datanamefletmessage_collector_(moduleC:Collector.S)?span?(data=fun()->[])msg:unit=letdata=data()inC.message?span~datamsglet[@inline]message?span?datamsg:unit=matchA.getcollectorwith|None->()|Somecoll->message_collector_coll?span?datamsgletmessagef?span?datak=matchA.getcollectorwith|None->()|Some(moduleC)->k(funfmt->Format.kasprintf(funstr->letdata=matchdatawith|None->[]|Somef->f()inC.message?span~datastr)fmt)letcounter_intnamen:unit=matchA.getcollectorwith|None->()|Some(moduleC)->C.counter_intnamenletcounter_floatnamef:unit=matchA.getcollectorwith|None->()|Some(moduleC)->C.counter_floatnamefletset_thread_namename:unit=matchA.getcollectorwith|None->()|Some(moduleC)->C.name_threadnameletset_process_namename:unit=matchA.getcollectorwith|None->()|Some(moduleC)->C.name_processnameletsetup_collectorc:unit=whileletcur=A.getcollectorinmatchcurwith|Some_->invalid_arg"trace: collector already present"|None->not(A.compare_and_setcollectorcur(Somec))do()doneletshutdown()=matchA.exchangecollectorNonewith|None->()|Some(moduleC)->C.shutdown()moduleInternal_=structmoduleAtomic_=Atomic_end