123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180includeTypesmoduleA=Atomic_moduleCollector=CollectormoduleMeta_map=Meta_mapmoduleLevel=Leveltypecollector=(moduleCollector.S)(* ## globals ## *)(** Global collector. *)letcollector:collectoroptionA.t=A.makeNone(* default level for spans without a level *)letdefault_level_=A.makeLevel.Traceletcurrent_level_=A.makeLevel.Trace(* ## implementation ## *)letdata_empty_build_()=[]let[@inline]enabled()=matchA.getcollectorwith|None->false|Some_->truelet[@inline]get_default_level()=A.getdefault_level_let[@inline]set_default_levell=A.setdefault_level_llet[@inline]set_current_levell=A.setcurrent_level_llet[@inline]get_current_level()=A.getcurrent_level_let[@inline]check_level?(level=A.getdefault_level_)():bool=Level.leqlevel(A.getcurrent_level_)letwith_span_collector_(moduleC:Collector.S)?__FUNCTION__~__FILE__~__LINE__?(data=data_empty_build_)namef=letdata=data()inC.with_span~__FUNCTION__~__FILE__~__LINE__~datanameflet[@inline]with_span?level?__FUNCTION__~__FILE__~__LINE__?datanamef=matchA.getcollectorwith|Somecollectorwhencheck_level?level()->with_span_collector_collector?__FUNCTION__~__FILE__~__LINE__?datanamef|_->(* fast path: no collector, no span *)fCollector.dummy_spanlet[@inline]enter_span?level?__FUNCTION__~__FILE__~__LINE__?(data=data_empty_build_)name:span=matchA.getcollectorwith|Some(moduleC)whencheck_level?level()->letdata=data()inC.enter_span~__FUNCTION__~__FILE__~__LINE__~dataname|_->Collector.dummy_spanlet[@inline]exit_spansp:unit=matchA.getcollectorwith|None->()|Some(moduleC)->C.exit_spanspletenter_explicit_span_collector_(moduleC:Collector.S)~parent~flavor?__FUNCTION__~__FILE__~__LINE__?(data=data_empty_build_)name:explicit_span=letdata=data()inC.enter_manual_span~parent~flavor~__FUNCTION__~__FILE__~__LINE__~datanamelet[@inline]enter_manual_sub_span~parent?flavor?level?__FUNCTION__~__FILE__~__LINE__?dataname:explicit_span=matchA.getcollectorwith|Somecollwhencheck_level?level()->enter_explicit_span_collector_coll~parent:(Someparent)~flavor?__FUNCTION__~__FILE__~__LINE__?dataname|_->Collector.dummy_explicit_spanlet[@inline]enter_manual_toplevel_span?flavor?level?__FUNCTION__~__FILE__~__LINE__?dataname:explicit_span=matchA.getcollectorwith|Somecollwhencheck_level?level()->enter_explicit_span_collector_coll~parent:None~flavor?__FUNCTION__~__FILE__~__LINE__?dataname|_->Collector.dummy_explicit_spanlet[@inline]exit_manual_spanespan:unit=ifespan!=Collector.dummy_explicit_spanthen(matchA.getcollectorwith|None->()|Some(moduleC)->C.exit_manual_spanespan)let[@inline]add_data_to_spanspdata:unit=ifsp!=Collector.dummy_span&&data<>[]then(matchA.getcollectorwith|None->()|Some(moduleC)->C.add_data_to_spanspdata)let[@inline]add_data_to_manual_spanespdata:unit=ifesp!=Collector.dummy_explicit_span&&data<>[]then(matchA.getcollectorwith|None->()|Some(moduleC)->C.add_data_to_manual_spanespdata)letmessage_collector_(moduleC:Collector.S)?span?(data=data_empty_build_)msg:unit=letdata=data()inC.message?span~datamsglet[@inline]message?level?span?datamsg:unit=matchA.getcollectorwith|Somecollwhencheck_level?level()->message_collector_coll?span?datamsg|_->()letmessagef?level?span?datak=matchA.getcollectorwith|Some(moduleC)whencheck_level?level()->k(funfmt->Format.kasprintf(funstr->letdata=matchdatawith|None->[]|Somef->f()inC.message?span~datastr)fmt)|_->()letcounter_int?level?(data=data_empty_build_)namen:unit=matchA.getcollectorwith|Some(moduleC)whencheck_level?level()->letdata=data()inC.counter_int~datanamen|_->()letcounter_float?level?(data=data_empty_build_)namef:unit=matchA.getcollectorwith|Some(moduleC)whencheck_level?level()->letdata=data()inC.counter_float~datanamef|_->()letset_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()typeextension_event=Types.extension_event=..let[@inline]extension_eventev=matchA.getcollectorwith|None->()|Some(moduleC)->C.extension_eventevmoduleInternal_=structmoduleAtomic_=Atomic_end