当前位置: 首页>>代码示例>>Java>>正文


Java TextMapUtil类代码示例

本文整理汇总了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;
  }
}
 
开发者ID:saturnism,项目名称:istio-by-example-java,代码行数:18,代码来源:IstioHttpSpanExtractor.java

示例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);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-sleuth,代码行数:18,代码来源:HeaderBasedMessagingExtractor.java

示例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);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-sleuth,代码行数:13,代码来源:HeaderBasedMessagingInjector.java

示例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);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-sleuth,代码行数:16,代码来源:HeaderBasedMessagingInjector.java

示例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();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-sleuth,代码行数:10,代码来源:TraceFilterCustomExtractorTests.java


注:本文中的org.springframework.cloud.sleuth.util.TextMapUtil类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。