本文整理汇总了Java中org.springframework.cloud.sleuth.util.TextMapUtil类的典型用法代码示例。如果您正苦于以下问题:Java TextMapUtil类的具体用法?Java TextMapUtil怎么用?Java TextMapUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TextMapUtil类属于org.springframework.cloud.sleuth.util包,在下文中一共展示了TextMapUtil类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: joinTrace
import org.springframework.cloud.sleuth.util.TextMapUtil; //导入依赖的package包/类
@Override
public Span joinTrace(SpanTextMap textMap) {
Map<String, String> carrier = TextMapUtil.asMap(textMap);
if (carrier.get(Span.TRACE_ID_NAME) == null) {
// can't build a Span without trace id
return null;
}
try {
String uri = carrier.get(URI_HEADER);
boolean skip = Span.SPAN_NOT_SAMPLED.equals(carrier.get(Span.SAMPLED_NAME));
long spanId = spanId(carrier);
return buildParentSpan(carrier, uri, skip, spanId);
} catch (Exception e) {
log.error("Exception occurred while trying to extract span from carrier", e);
return null;
}
}
示例2: joinTrace
import org.springframework.cloud.sleuth.util.TextMapUtil; //导入依赖的package包/类
@Override
public Span joinTrace(SpanTextMap textMap) {
Map<String, String> carrier = TextMapUtil.asMap(textMap);
boolean spanIdMissing = !hasHeader(carrier, TraceMessageHeaders.SPAN_ID_NAME);
boolean traceIdMissing = !hasHeader(carrier, TraceMessageHeaders.TRACE_ID_NAME);
if (Span.SPAN_SAMPLED.equals(carrier.get(TraceMessageHeaders.SPAN_FLAGS_NAME))) {
String traceId = generateTraceIdIfMissing(carrier, traceIdMissing);
if (spanIdMissing) {
carrier.put(TraceMessageHeaders.SPAN_ID_NAME, traceId);
}
} else if (spanIdMissing) {
return null;
// TODO: Consider throwing IllegalArgumentException;
}
boolean idMissing = spanIdMissing || traceIdMissing;
return extractSpanFromHeaders(carrier, Span.builder(), idMissing);
}
示例3: inject
import org.springframework.cloud.sleuth.util.TextMapUtil; //导入依赖的package包/类
@Override
public void inject(Span span, SpanTextMap carrier) {
Map<String, String> map = TextMapUtil.asMap(carrier);
if (span == null) {
if (!isSampled(map, TraceMessageHeaders.SAMPLED_NAME)) {
carrier.put(TraceMessageHeaders.SAMPLED_NAME, Span.SPAN_NOT_SAMPLED);
return;
}
return;
}
addHeaders(map, span, carrier);
}
示例4: addAnnotations
import org.springframework.cloud.sleuth.util.TextMapUtil; //导入依赖的package包/类
private void addAnnotations(TraceKeys traceKeys, SpanTextMap spanTextMap, Span span) {
Map<String, String> map = TextMapUtil.asMap(spanTextMap);
for (String name : traceKeys.getMessage().getHeaders()) {
if (map.containsKey(name)) {
String key = traceKeys.getMessage().getPrefix() + name.toLowerCase();
Object value = map.get(name);
if (value == null) {
value = "null";
}
// TODO: better way to serialize?
tagIfEntryMissing(span, key, value.toString());
}
}
addPayloadAnnotations(traceKeys, map, span);
}
示例5: joinTrace
import org.springframework.cloud.sleuth.util.TextMapUtil; //导入依赖的package包/类
@Override public Span joinTrace(SpanTextMap carrier) {
Map<String, String> map = TextMapUtil.asMap(carrier);
long traceId = Span.hexToId(map.get("correlationid"));
long spanId = Span.hexToId(map.get("myspanid"));
// extract all necessary headers
Span.SpanBuilder builder = Span.builder().traceId(traceId).spanId(spanId);
// build rest of the Span
return builder.build();
}