W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
需要進行傳播以確保源自同一根的活動被收集到同一條跡線中。最常見的傳播方法是通過將RPC請求發(fā)送到接收它的服務(wù)器來從客戶端復(fù)制跟蹤上下文。
例如,進行下游HTTP調(diào)用時,其跟蹤上下文被編碼為請求標頭,并與之一起發(fā)送,如下圖所示:
Client Span Server Span ┌──────────────────┐ ┌──────────────────┐ │ │ │ │ │ TraceContext │ Http Request Headers │ TraceContext │ │ ┌──────────────┐ │ ┌───────────────────┐ │ ┌──────────────┐ │ │ │ TraceId │ │ │ X─B3─TraceId │ │ │ TraceId │ │ │ │ │ │ │ │ │ │ │ │ │ │ ParentSpanId │ │ Extract │ X─B3─ParentSpanId │ Inject │ │ ParentSpanId │ │ │ │ ├─┼─────────>│ ├────────┼>│ │ │ │ │ SpanId │ │ │ X─B3─SpanId │ │ │ SpanId │ │ │ │ │ │ │ │ │ │ │ │ │ │ Sampled │ │ │ X─B3─Sampled │ │ │ Sampled │ │ │ └──────────────┘ │ └───────────────────┘ │ └──────────────┘ │ │ │ │ │ └──────────────────┘ └──────────────────┘
上面的名稱來自B3 Propagation,它內(nèi)置于Brave,并具有許多語言和框架的實現(xiàn)。
大多數(shù)用戶使用框架攔截器來自動化傳播。接下來的兩個示例顯示了這對于客戶端和服務(wù)器的工作方式。
以下示例顯示了客戶端傳播如何工作:
@Autowired Tracing tracing; // configure a function that injects a trace context into a request injector = tracing.propagation().injector(Request.Builder::addHeader); // before a request is sent, add the current span's context to it injector.inject(span.context(), request);
以下示例顯示了服務(wù)器端傳播的工作方式:
@Autowired Tracing tracing; @Autowired Tracer tracer; // configure a function that extracts the trace context from a request extractor = tracing.propagation().extractor(Request::getHeader); // when a server receives a request, it joins or starts a new trace span = tracer.nextSpan(extractor.extract(request));
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: