![Search icon](https://hackernoon.imgix.net/search-new.png?w=19&h=19)
Esikhathini esidlule, lapho sikhuluma nge-backend, sasivame ukubhekisela kuhlelo lokusebenza olulodwa olukhulu olune-database eyodwa, enkulu, futhi ukugawula kwakwanele ukuqapha. Manje, ngenxa yobuchwepheshe obufana ne -Kubernetes , ama-microservices aseyindinganiso. Izinhlelo zokusebenza ziningi kakhulu futhi zisatshalalisiwe, futhi ukuloga okujwayelekile akusanele ukulungisa amaphutha nokuxilonga izinkinga ezinhlelweni zethu.
Isixazululo esihle kakhulu sokuhlela ukuqapha i-OpenTelemetry — ikhithi yamathuluzi yesimanje engasetshenziselwa ukulungisa iphutha nokuhlaziya ukusebenza kwamasistimu asabalalisiwe.
Le ndatshana ihloselwe ochwepheshe be-IT abafuna ukwandisa ulwazi lwabo ekwenzeni i-backend optimization. Ngezansi, sizocacisa ukuthi iyini i-OpenTelemetry, imiqondo yayo ebalulekile, kanye nezinkinga esiza ukuzixazulula. Uma unentshisekelo yokuthi i-OpenTelemetry ingashintsha kanjani indlela yakho yokuqapha kanye nokulungisa iphutha lezinhlelo ezingemuva, ezithuthukisa ukwethembeka nokusebenza kahle kwazo - qhubeka funda.
Izinkampani ezinkulu zobuchwepheshe ziqale zabhekana nenselelo yokugawulwa kwemithi nokulandela umkhondo ngasekupheleni kwawo-2000. Ngo-2010, i-Google yashicilela iphepha,
Ngo-2014, kwavela u-Kubernetes, okwenza kube lula kakhulu ukuthuthukiswa kwama-microservices nezinye izinhlelo ezisatshalaliswa ngamafu. Lokhu kuholele ekutheni izinkampani eziningi zihlangabezane nezinkinga ngokugawulwa kwemithi nokulandela umkhondo kuma-microservices. Ukuze kwenziwe ukulandelela okusatshalaliswe kufane, izinga le-OpenTracing, elamukelwa yi-CNCF, kanye nephrojekthi ye-Google ye-OpenCensus yadalwa.
Ngo-2019, amaphrojekthi we-OpenTracing kanye ne-OpenCensus amemezele ukuhlanganiswa ngaphansi kwegama elithi OpenTelemetry. Le nkundla ihlanganisa imikhuba engcono kakhulu eqoqwe phakathi neminyaka eminingi, evumela ukuhlanganiswa okungenazihibe kokulandela umkhondo, ukuloga, namamethrikhi kunoma iyiphi isistimu, kungakhathaliseki ukuthi iyinkimbinkimbi kangakanani.
Namuhla, i-OpenTelemetry akuyona nje iphrojekthi; kuyindinganiso yemboni yokuqoqa nokudlulisa idatha ye-telemetry. Ithuthukiswa futhi isekelwe umphakathi wochwepheshe nezinkampani ezihamba phambili ezimakethe ezifana ne-Google ne-Microsoft. Iphrojekthi iyaqhubeka nokuvela, ithola amakhono amasha okwenza lula inqubo yokuhlanganisa nokusebenzisa.
I-OpenTelemetry isethi ephelele yemikhuba namathuluzi achaza ukuthi yiziphi izimpawu ezingase zenziwe uhlelo lokusebenza ukuze luhlanganyele nomhlaba wangaphandle, nokuthi lezi zimpawu zingaqoqwa kanjani futhi ziboniswe ukuze kuqashwe isimo sezinhlelo zokusebenza kanye nesistimu iyonke. Izinhlobo ezintathu eziyinhloko zamasiginali ukulandelela, ukuloga , kanye nokuqoqwa kwamamethrikhi .
**Ake sihlolisise ingxenye ngayinye: \
I-OpenTelemetry yethula umqondo wezimo zokusebenza. Okuqukethwe kufaka phakathi izichasiso ezifana nokuthi `trace_id`
(inkomba yokusebenza kwamanje) kanye `span_id`
(inkomba yesicelo esincane, ngokuzama ngakunye kwesicelo esingaphansi esinokuthi `span_id`
esihlukile).
Ukwengeza, umongo ungaqukatha ulwazi olungashintshi, njengegama le-node lapho uhlelo lusetshenziswa khona noma igama lendawo (prod/qa). Lezi zinkambu, ezaziwa njengezisetshenziswa kumatemu e-OpenTelemetry, zinamathiselwe kulo lonke ulogi, imethrikhi, noma umkhondo ukuze kusesheke kalula. Okuqukethwe kungaphinda kuhlanganise idatha eguqukayo, njengesihlonzi sephoyinti lokugcina lamanje ( `http_path: "GET /user/:id/info"`
), enganamathiselwa ngokukhetha kumaqembu amalogi, amamethrikhi, noma ukulandelelwa.
Okuqukethwe kwe-OpenTelemetry kungadluliswa phakathi kwezinhlelo zokusebenza ezihlukene kusetshenziswa izivumelwano zokusakaza umongo. Lawa maphrothokholi aqukethe amasethi kanhlokweni abengezwa kuzo zonke izicelo ze-HTTP noma ze-gRPC noma izihloko zemilayezo yolayini. Lokhu kuvumela izinhlelo zokusebenza ezansi nomfula ukuthi zakhe kabusha umongo wokusebenza kusukela kulezi zihloko.
Nazi ezinye izibonelo zokusakazwa komongo:
I-B3-Propagation Lena isethi yezihloko ( x-b3-*
) ezakhelwe ekuqaleni isistimu yokulandela ye-Zipkin. Yashintshwa yaba yi-OpenTracing futhi yasetshenziswa amathuluzi amaningi nemitapo yolwazi. I-B3-Propagation iphethe trace_id
/ span_id
kanye nefulegi elibonisa ukuthi ukusampula kuyadingeka yini.
I-W3C Trace Context Yathuthukiswa yiqembu elisebenzayo le-W3C, leli zinga lihlanganisa izindlela ezihlukahlukene zokusakaza umongo zibe izinga elilodwa futhi liyinto ezenzakalelayo ku-OpenTelemetry. Isibonelo esihle sokusebenzisa lawa mazinga ukulandelela ukuqaliswa kwesicelo esidlula kuma-microservices asetshenziswe ngobuchwepheshe obuhlukahlukene ngaphandle kokufaka engozini ukunemba kokuqapha nokususa iphutha.
Ukulandelela kuyinqubo yokurekhoda futhi kamuva ubone umugqa wesikhathi wendlela yesicelo ngokusebenzisa izinsiza ezincane eziningi.
Ekubukeni, ibha ngayinye ibizwa ngokuthi "i-span" futhi ine- "span_id" ehlukile. I-root span ibizwa ngokuthi "trace" futhi ine- "trace_id" , esebenza njengesihlonzi saso sonke isicelo.
Lolu hlobo lokuboniswa lukuvumela ukuthi:
trace_id
ne span_id
ukuze isetshenziswe kwamanye amasignali.
Naphezu kokubonakala kulula, ukugawula kuseyithuluzi elinamandla kakhulu lokuxilonga izinkinga. I-OpenTelemetry ithuthukisa ukugawulwa kwemithi okungokwesiko ngokungeza ulwazi lwengqikithi. Ngokukhethekile, uma umkhondo osebenzayo ukhona, izibaluli ze-`trace_id` kanye `ne-span_id` zengezwa ngokuzenzakalelayo kulogi, ziwaxhuma emugqeni wesikhathi wokulandelela. Ngaphezu kwalokho, izibaluli zelogi zingabandakanya ulwazi olumile oluvela kumongo we-OpenTelemetry, njengesihlonzi se-node, kanye nolwazi oluguqukayo, njengesihlonzi sephoyinti lokugcina le-HTTP (`http_path: "GET /user/:id"`).
Usebenzisa `i-id_yokulandelela`, ungathola amalogi avela kuzo zonke izinsiza ezincane ezihlobene nesicelo samanje, kuyilapho `span_id` ikuvumela ukuthi uhlukanise phakathi kwezicelo ezincane. Isibonelo, esimweni sokuzama futhi, amalogi asuka emizamweni eyahlukene azoba `no-id`s abahlukile. Ukusebenzisa lezi zihlonzi kunika amandla ukuhlaziya okusheshayo kokuziphatha kwesistimu ngesikhathi sangempela, kusheshiswe ukuhlonzwa kwenkinga nokuthuthukisa ukuzinza nokuthembeka.
Ukuqoqwa kwamamethrikhi kunikeza idatha yobuningi ekusebenzeni kwesistimu, njengokubambezeleka, izilinganiso zamaphutha, ukusetshenziswa kwensiza, nokuningi. Ukuqapha kwesikhathi sangempela kwamamethrikhi kukuvumela ukuthi uphendule ngokushesha ezinguqukweni zokusebenza, uvimbele ukwehluleka kanye nokuphelelwa amandla kwensiza, futhi uqinisekise ukutholakala okuphezulu nokuthembeka kohlelo lokusebenza kubasebenzisi.
Ukuhlanganiswa nokugcinwa kwemethrikhi nezinhlelo zokubonisa ngeso ezifana ne-Prometheus ne-Grafana kwenza kube lula ukubona le datha, okwenza ukuqapha kube lula.
Abaqoqi bemethrikhi be-OpenTelemetry bahambisana namazinga e-Prometheus kanye ne-OpenMetrics, okwenza kube lula ukushintshela kuzixazululo ze-OpenTelemetry ngaphandle kwezinguquko ezibalulekile. I-OpenTelemetry SDK ivumela izibonelo ze-trace_id ukuthi zithunyelwe kanye namamethrikhi, okwenza kube nokwenzeka ukuhlobanisa amamethrikhi ngezibonelo zelogi nokulandelelwa.
Ngokuhlangene, amalogi, amamethrikhi, nokulandelela kudala ukubuka okuphelele kwesimo sesistimu:
Ngokungeziwe ezingxenyeni ezintathu eziyinhloko, i-OpenTelemetry ihlanganisa imiqondo yeSampling, Imithwalo, nokuphathwa komongo wokusebenza.
Ezinhlelweni ezilayisha kakhulu, umthamo wamalogi nokulandelelwa uba kukhulu, okudinga izinsiza ezinkulu zengqalasizinda nokugcinwa kwedatha. Ukuze kubhekwane nalolu daba, amazinga e-OpenTelemetry ahlanganisa ukusampula kwesignali — amandla okuthumela kuphela ingxenye yokulandela kanye namalogi. Isibonelo, ungakhipha amasiginali anemininingwane ukusuka kumaphesenti ezicelo, izicelo ezisebenza isikhathi eside, noma izicelo zamaphutha. Le ndlela ivumela amasampula okwanele ukwakha izibalo ngenkathi kugcinwa izinsiza ezibalulekile.
Kodwa-ke, uma isistimu ngayinye inquma ngokuzimela ukuthi yiziphi izicelo okufanele zigadwe ngokuningiliziwe, sigcina sinombono ohlukene wesicelo ngasinye. Amanye amasistimu angase akhiphe idatha enemininingwane kuyilapho amanye angase akhiphe ingxenye noma angathekelisi nhlobo.
Ukuze kuxazululwe le nkinga, izindlela zokusakaza umongo we-OpenTelemetry zidlulisa ifulegi lesampula kanye `ne-id_yokulandelela`/`span_id`. Lokhu kuqinisekisa ukuthi uma isevisi yokuqala ethola isicelo somsebenzisi inquma ukuthi isicelo kufanele sigadwe ngokuningiliziwe, wonke amanye amasistimu azolandela okufanayo. Uma kungenjalo, wonke amasistimu kufanele akhiphe amasiginali kancane noma angawakhiphi ukuze onge izinsiza. Le ndlela ibizwa ngokuthi "Isampula Yekhanda" - isinqumo esenziwe ekuqaleni kokucutshungulwa kwesicelo, ngokungahleliwe noma ngokusekelwe kwezinye izibaluli zokufaka.
Ngaphandle kwalokho, i-OpenTelemetry isekela i-"Tail Sampling," lapho zonke izinhlelo zokusebenza zihlala zithekelisa wonke amasiginali ngokuningiliziwe, kodwa isilondolozi esimaphakathi sikhona. Ngemva kokuqoqa yonke idatha, le buffer inquma ukuthi igcine idatha egcwele noma igcine ingxenye yesampula kuphela. Le ndlela ivumela isampula elimele kakhulu lesigaba ngasinye sesicelo (impumelelo/inde/iphutha) kodwa idinga ukusethwa kwengqalasizinda eyengeziwe.
Indlela Yomthwalo ivumela amapheya enani lokhiye ngokunganaki ukuthi adluliselwe kanye ne trace_id
/ span_id
, edlula ngokuzenzakalelayo phakathi kwawo wonke ama-microservices ngesikhathi sokucubungula isicelo. Lokhu kuwusizo ekuthumeleni ulwazi olwengeziwe oludingekayo kuyo yonke indlela yokucela—njengolwazi lomsebenzisi noma izilungiselelo zendawo yesikhathi sokusebenza.
Isibonelo sikanhlokweni sokudlulisa umthwalo ngokwezinga le-W3C: tracestate: rojo=00f067aa0ba902b7,congo=t61rcWkgMzE,userId=1c30032v5
Nazi ezinye izibonelo zokusetshenziswa komthwalo:
Ulwazi Lokudlula Lomongo Webhizinisi olufana ne userId
, productId
, noma deviceId
ingadluliselwa kuwo wonke ama-microservices. Izinhlelo zokusebenza zingangena ngokuzenzakalelayo lolu lwazi, okuvumela ukusesha kwelogi ngomongo womsebenzisi wesicelo sangempela.
Izilungiselelo Ezithize Zokucushwa Kwepharamitha yama-SDK noma ingqalasizinda.
Ukuhambisa amafulegi amafulegi asiza ukulayisha ababhalansi ukwenza izinqumo zomzila. Ngesikhathi sokuhlolwa, ezinye izicelo zingase zidinge ukuthi zihanjiswe ukuze kuhlehliswe abantu abangemuva. Njengoba imithwalo ithunyelwa ngokuzenzakalelayo kuzo zonke izinsiza, asikho isidingo sokwenza izivumelwano ezengeziwe—vele usethe umthetho kusilinganisi somthwalo.
Qaphela ukuthi nakuba umthelela wokusebenza Womthwalo umncane, ukusetshenziswa ngokweqile kungakhuphula kakhulu inethiwekhi nomthwalo wesevisi. Khetha ngokucophelela ukuthi iyiphi idatha oyidingayo ngempela ukuze udlule Emthwalweni ukuze ugweme izinkinga zokusebenza.
Ukusebenzisa i-OpenTelemetry ezingeni lengqalasizinda kuhlanganisa ukuhlanganisa i-OpenTelemetry backend esakhiweni sohlelo lokusebenza nokumisa ingqalasizinda yokuhlanganiswa kwedatha.
Inqubo iqukethe izigaba ezine:
Ukuhlanganiswa Kohlelo Lokusebenza Esigabeni sokuqala, ama-OpenTelemetry SDK ahlanganiswe ngokuqondile ezinhlelweni zokusebenza zokuqoqa amamethrikhi, amalogi, nokulandelelwa, okuqinisekisa ukugeleza okuqhubekayo kwedatha mayelana nokusebenza kwengxenye ngayinye yesistimu.
Ukulungiselela Abathumeli Bangaphandle Idatha eqoqiwe ihanjiswa kusuka kuzinhlelo zokusebenza ngabathumelisi bempahla iye kumasistimu angaphandle ukuze kuqhutshekwe nokucutshungulwa, njengokugawula, ukuqapha, ukulandelela, noma amasistimu okuhlaziya, kuye ngezidingo zakho.
Ukuhlanganisa kanye Nesitoreji Lesi sigaba singase sibandakanye idatha yokwenza ngokwejwayelekile, ukuyicebisa ngolwazi olwengeziwe, nokuhlanganisa idatha evela emithonjeni ehlukene ukuze udale ukubuka okuhlangene kwesimo sesistimu.
Ukubonakala Kwedatha Ekugcineni, idatha ecutshunguliwe yethulwa njengamadeshibhodi kumasistimu afana ne-Grafana (yamamethrikhi nokulandelelwa) noma i-Kibana (yamalogu). Lokhu kuvumela amaqembu ukuthi ahlole ngokushesha impilo yesistimu, ahlonze izinkinga namathrendi, futhi asethe izexwayiso ngokusekelwe kumasiginali akhiqiziwe.
Ukuze uhlanganise nohlelo lokusebenza, udinga ukuxhuma i-OpenTelemetry SDK efanele yolimi lokuhlela olusetshenziswayo noma usebenzise amalabhulali nezinhlaka ezisekela i-OpenTelemetry ngokuqondile. I-OpenTelemetry ivamise ukusebenzisa izixhumanisi ezisetshenziswa kabanzi ezivela emitapweni yolwazi eyaziwayo, evumela ukushintshwa kokungena. Isibonelo, ilabhulali ye-Micrometer ivamise ukusetshenziselwa ukuqoqwa kwamamethrikhi ku-ecosystem ye-Java. I-OpenTelemetry SDK inikeza ukusetshenziswa kwayo kwe-Micrometer interface, evumela ukuthunyelwa kwe-metric ngaphandle kokushintsha ikhodi yohlelo lokusebenza eyinhloko. Ngaphezu kwalokho, i-OpenTelemetry inikezela ngokusetshenziswa kwe-OpenTracing endala ne-OpenCensus interface, okusiza ukuthuthela okushelelayo ku-OpenTelemetry.
Ezinhlelweni ze-IT, i-OpenTelemetry ingaba ukhiye wekusasa lezinto ezingemuva ezithembekile nezisebenzayo. Leli thuluzi lenza ukulungisa amaphutha nokuqapha kube lula futhi livula namathuba okuqonda okujulile kokusebenza kohlelo lokusebenza nokwenza kahle ezingeni elisha. Joyina umphakathi we-OpenTelemetry ukuze usize ekulolongeni ikusasa lapho ukuthuthukiswa kwe-backend kulula futhi kusebenza kangcono!