• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java TraceKeys类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.cloud.sleuth.TraceKeys的典型用法代码示例。如果您正苦于以下问题:Java TraceKeys类的具体用法?Java TraceKeys怎么用?Java TraceKeys使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TraceKeys类属于org.springframework.cloud.sleuth包,在下文中一共展示了TraceKeys类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testInjectSuccess

import org.springframework.cloud.sleuth.TraceKeys; //导入依赖的package包/类
@Test
public void testInjectSuccess() {
  final AmqpMessagingSpanInjector spanInjector = new AmqpMessagingSpanInjector(new TraceKeys());

  final Span span =
      Span.builder().spanId(Span.hexToId("123")).traceId(Span.hexToId("456")).build();
  final Message message = new Message("Test".getBytes(), new MessageProperties());

  spanInjector.inject(span, message);

  final Map<String, Object> headers = message.getMessageProperties().getHeaders();

  Assert.assertEquals("1", headers.get(TraceMessageHeaders.SAMPLED_NAME));
  Assert.assertEquals("0000000000000123", headers.get(TraceMessageHeaders.SPAN_ID_NAME));
  Assert.assertEquals("0000000000000456", headers.get(TraceMessageHeaders.TRACE_ID_NAME));
  Assert.assertEquals(4, headers.size());
}
 
开发者ID:netshoes,项目名称:spring-cloud-sleuth-amqp,代码行数:18,代码来源:AmqpMessagingSpanInjectorTest.java


示例2: testInjectWithParentIdSuccess

import org.springframework.cloud.sleuth.TraceKeys; //导入依赖的package包/类
@Test
public void testInjectWithParentIdSuccess() {
  final AmqpMessagingSpanInjector spanInjector = new AmqpMessagingSpanInjector(new TraceKeys());

  final Span span =
      Span.builder()
          .parent(Span.hexToId("999"))
          .spanId(Span.hexToId("123"))
          .traceId(Span.hexToId("456"))
          .build();
  final Message message = new Message("Test".getBytes(), new MessageProperties());

  spanInjector.inject(span, message);

  final Map<String, Object> headers = message.getMessageProperties().getHeaders();

  Assert.assertEquals("1", headers.get(TraceMessageHeaders.SAMPLED_NAME));
  Assert.assertEquals("0000000000000999", headers.get(TraceMessageHeaders.PARENT_ID_NAME));
  Assert.assertEquals("0000000000000123", headers.get(TraceMessageHeaders.SPAN_ID_NAME));
  Assert.assertEquals("0000000000000456", headers.get(TraceMessageHeaders.TRACE_ID_NAME));
  Assert.assertEquals(5, headers.size());
}
 
开发者ID:netshoes,项目名称:spring-cloud-sleuth-amqp,代码行数:23,代码来源:AmqpMessagingSpanInjectorTest.java


示例3: testInjectSpanNotExportableSuccess

import org.springframework.cloud.sleuth.TraceKeys; //导入依赖的package包/类
@Test
public void testInjectSpanNotExportableSuccess() {
  final AmqpMessagingSpanInjector spanInjector = new AmqpMessagingSpanInjector(new TraceKeys());

  final Message message = new Message("Test".getBytes(), new MessageProperties());

  final Span span =
      Span.builder()
          .exportable(false)
          .spanId(Span.hexToId("123"))
          .traceId(Span.hexToId("456"))
          .build();

  spanInjector.inject(span, message);

  final Map<String, Object> headers = message.getMessageProperties().getHeaders();

  Assert.assertEquals("0", headers.get(TraceMessageHeaders.SAMPLED_NAME));
  Assert.assertEquals("0000000000000123", headers.get(TraceMessageHeaders.SPAN_ID_NAME));
  Assert.assertEquals("0000000000000456", headers.get(TraceMessageHeaders.TRACE_ID_NAME));
  Assert.assertEquals(4, headers.size());
}
 
开发者ID:netshoes,项目名称:spring-cloud-sleuth-amqp,代码行数:23,代码来源:AmqpMessagingSpanInjectorTest.java


示例4: SleuthRxJavaSchedulersHook

import org.springframework.cloud.sleuth.TraceKeys; //导入依赖的package包/类
SleuthRxJavaSchedulersHook(Tracer tracer, TraceKeys traceKeys,
		List<String> threadsToSample) {
	this.tracer = tracer;
	this.traceKeys = traceKeys;
	this.threadsToSample = threadsToSample;
	try {
		this.delegate = RxJavaPlugins.getInstance().getSchedulersHook();
		if (this.delegate instanceof SleuthRxJavaSchedulersHook) {
			return;
		}
		RxJavaErrorHandler errorHandler = RxJavaPlugins.getInstance().getErrorHandler();
		RxJavaObservableExecutionHook observableExecutionHook
			= RxJavaPlugins.getInstance().getObservableExecutionHook();
		logCurrentStateOfRxJavaPlugins(errorHandler, observableExecutionHook);
		RxJavaPlugins.getInstance().reset();
		RxJavaPlugins.getInstance().registerSchedulersHook(this);
		RxJavaPlugins.getInstance().registerErrorHandler(errorHandler);
		RxJavaPlugins.getInstance().registerObservableExecutionHook(observableExecutionHook);
	} catch (Exception e) {
		log.error("Failed to register Sleuth RxJava SchedulersHook", e);
	}
}
 
开发者ID:reshmik,项目名称:Zipkin,代码行数:23,代码来源:SleuthRxJavaSchedulersHook.java


示例5: should_pass_tracing_information_when_using_Hystrix_commands

import org.springframework.cloud.sleuth.TraceKeys; //导入依赖的package包/类
@Test
public void should_pass_tracing_information_when_using_Hystrix_commands() {
	Tracer tracer = new DefaultTracer(new AlwaysSampler(), new Random(),
			new DefaultSpanNamer(), new NoOpSpanLogger(), new NoOpSpanReporter());
	TraceKeys traceKeys = new TraceKeys();
	HystrixCommand.Setter setter = HystrixCommand.Setter
			.withGroupKey(HystrixCommandGroupKey.Factory.asKey("group"))
			.andCommandKey(HystrixCommandKey.Factory.asKey("command"));
	// tag::hystrix_command[]
	HystrixCommand<String> hystrixCommand = new HystrixCommand<String>(setter) {
		@Override
		protected String run() throws Exception {
			return someLogic();
		}
	};
	// end::hystrix_command[]
	// tag::trace_hystrix_command[]
	TraceCommand<String> traceCommand = new TraceCommand<String>(tracer, traceKeys, setter) {
		@Override
		public String doRun() throws Exception {
			return someLogic();
		}
	};
	// end::trace_hystrix_command[]

	String resultFromHystrixCommand = hystrixCommand.execute();
	String resultFromTraceCommand = traceCommand.execute();

	then(resultFromHystrixCommand).isEqualTo(resultFromTraceCommand);
	then(tracer.getCurrentSpan()).isNull();
}
 
开发者ID:reshmik,项目名称:Zipkin,代码行数:32,代码来源:TraceCommandTests.java


示例6: shouldCloseSpanWhenExceptionIsThrown

import org.springframework.cloud.sleuth.TraceKeys; //导入依赖的package包/类
@Test
public void shouldCloseSpanWhenExceptionIsThrown() throws Exception {
	Span startedSpan = this.tracer.createSpan("http:start");
	final AtomicReference<Span> span = new AtomicReference<>();

	new TracePreZuulFilter(this.tracer, new RequestContextInjector(),
			new HttpTraceKeysInjector(this.tracer, new TraceKeys())) {
		@Override
		public Object run() {
			super.run();
			span.set(TracePreZuulFilterTests.this.tracer.getCurrentSpan());
			throw new RuntimeException();
		}
	}.runFilter();

	then(startedSpan).isNotEqualTo(span.get());
	then(span.get().logs()).extracting("event").contains(Span.CLIENT_SEND);
	then(span.get()).hasATag("http.method", "GET");
	then(this.tracer.getCurrentSpan()).isEqualTo(startedSpan);
}
 
开发者ID:reshmik,项目名称:Zipkin,代码行数:21,代码来源:TracePreZuulFilterTests.java


示例7: shouldNotCloseSpanWhenNoExceptionIsThrown

import org.springframework.cloud.sleuth.TraceKeys; //导入依赖的package包/类
@Test
public void shouldNotCloseSpanWhenNoExceptionIsThrown() throws Exception {
	Span startedSpan = this.tracer.createSpan("http:start");
	final AtomicReference<Span> span = new AtomicReference<>();

	new TracePreZuulFilter(this.tracer, new RequestContextInjector(),
			new HttpTraceKeysInjector(this.tracer, new TraceKeys())) {
		@Override
		public Object run() {
			span.set(TracePreZuulFilterTests.this.tracer.getCurrentSpan());
			return super.run();
		}
	}.runFilter();

	then(startedSpan).isNotEqualTo(span.get());
	then(span.get().logs()).extracting("event").contains(Span.CLIENT_SEND);
	then(span.get().tags()).containsKey(Span.SPAN_LOCAL_COMPONENT_TAG_NAME);
	then(this.tracer.getCurrentSpan()).isEqualTo(span.get());
}
 
开发者ID:reshmik,项目名称:Zipkin,代码行数:20,代码来源:TracePreZuulFilterTests.java


示例8: init

import org.springframework.cloud.sleuth.TraceKeys; //导入依赖的package包/类
@Before
public void init() {
	initMocks(this);
	this.tracer = new DefaultTracer(new DelegateSampler(), new Random(),
			new DefaultSpanNamer(), this.spanLogger, this.spanReporter, new TraceKeys()) {
		@Override
		public Span continueSpan(Span span) {
			TraceFilterTests.this.span = super.continueSpan(span);
			return TraceFilterTests.this.span;
		}
	};
	this.request = builder().buildRequest(new MockServletContext());
	this.response = new MockHttpServletResponse();
	this.response.setContentType(MediaType.APPLICATION_JSON_VALUE);
	this.filterChain = new MockFilterChain();
	this.httpTraceKeysInjector = new HttpTraceKeysInjector(this.tracer, this.traceKeys);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-sleuth,代码行数:18,代码来源:TraceFilterTests.java


示例9: should_pass_tracing_information_when_using_Hystrix_commands

import org.springframework.cloud.sleuth.TraceKeys; //导入依赖的package包/类
@Test
public void should_pass_tracing_information_when_using_Hystrix_commands() {
	Tracer tracer = new DefaultTracer(new AlwaysSampler(), new Random(),
			new DefaultSpanNamer(), new NoOpSpanLogger(), new NoOpSpanReporter(), new TraceKeys());
	TraceKeys traceKeys = new TraceKeys();
	HystrixCommand.Setter setter = withGroupKey(asKey("group"))
			.andCommandKey(HystrixCommandKey.Factory.asKey("command"));
	// tag::hystrix_command[]
	HystrixCommand<String> hystrixCommand = new HystrixCommand<String>(setter) {
		@Override
		protected String run() throws Exception {
			return someLogic();
		}
	};
	// end::hystrix_command[]
	// tag::trace_hystrix_command[]
	TraceCommand<String> traceCommand = new TraceCommand<String>(tracer, traceKeys, setter) {
		@Override
		public String doRun() throws Exception {
			return someLogic();
		}
	};
	// end::trace_hystrix_command[]

	String resultFromHystrixCommand = hystrixCommand.execute();
	String resultFromTraceCommand = traceCommand.execute();

	then(resultFromHystrixCommand).isEqualTo(resultFromTraceCommand);
	then(tracer.getCurrentSpan()).isNull();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-sleuth,代码行数:31,代码来源:TraceCommandTests.java


示例10: shouldCloseSpanWhenExceptionIsThrown

import org.springframework.cloud.sleuth.TraceKeys; //导入依赖的package包/类
@Test
public void shouldCloseSpanWhenExceptionIsThrown() throws Exception {
	Span startedSpan = this.tracer.createSpan("http:start");
	final AtomicReference<Span> span = new AtomicReference<>();

	new TracePreZuulFilter(this.tracer, new ZipkinHttpSpanInjector(),
			new HttpTraceKeysInjector(this.tracer, new TraceKeys()), new ExceptionMessageErrorParser()) {
		@Override
		public Object run() {
			super.run();
			span.set(TracePreZuulFilterTests.this.tracer.getCurrentSpan());
			throw new RuntimeException("foo");
		}
	}.runFilter();

	then(startedSpan).isNotEqualTo(span.get());
	then(span.get().logs()).extracting("event").contains(Span.CLIENT_SEND);
	then(span.get()).hasATag("http.method", "GET");
	then(span.get()).hasATag("error", "foo");
	then(this.tracer.getCurrentSpan()).isEqualTo(startedSpan);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-sleuth,代码行数:22,代码来源:TracePreZuulFilterTests.java


示例11: shouldNotCloseSpanWhenNoExceptionIsThrown

import org.springframework.cloud.sleuth.TraceKeys; //导入依赖的package包/类
@Test
public void shouldNotCloseSpanWhenNoExceptionIsThrown() throws Exception {
	Span startedSpan = this.tracer.createSpan("http:start");
	final AtomicReference<Span> span = new AtomicReference<>();

	new TracePreZuulFilter(this.tracer, new ZipkinHttpSpanInjector(),
			new HttpTraceKeysInjector(this.tracer, new TraceKeys()), new ExceptionMessageErrorParser()) {
		@Override
		public Object run() {
			span.set(TracePreZuulFilterTests.this.tracer.getCurrentSpan());
			return super.run();
		}
	}.runFilter();

	then(startedSpan).isNotEqualTo(span.get());
	then(span.get().logs()).extracting("event").contains(Span.CLIENT_SEND);
	then(span.get().tags()).containsKey(Span.SPAN_LOCAL_COMPONENT_TAG_NAME);
	then(this.tracer.getCurrentSpan()).isEqualTo(span.get());
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-sleuth,代码行数:20,代码来源:TracePreZuulFilterTests.java


示例12: should_wrap_methods_in_trace_representation_only_for_non_tracing_callables

import org.springframework.cloud.sleuth.TraceKeys; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void should_wrap_methods_in_trace_representation_only_for_non_tracing_callables() throws Exception {
	ExecutorService executorService = Mockito.mock(ExecutorService.class);
	TraceableExecutorService traceExecutorService = new TraceableExecutorService(
			executorService, this.tracer, new TraceKeys(), this.spanNamer);

	traceExecutorService.invokeAll(callables());
	BDDMockito.then(executorService).should().invokeAll(BDDMockito.argThat(
			withSpanContinuingTraceCallablesOnly()));

	traceExecutorService.invokeAll(callables(), 1L, TimeUnit.DAYS);
	BDDMockito.then(executorService).should().invokeAll(BDDMockito.argThat(
			withSpanContinuingTraceCallablesOnly()),
			BDDMockito.eq(1L) , BDDMockito.eq(TimeUnit.DAYS));

	traceExecutorService.invokeAny(callables());
	BDDMockito.then(executorService).should().invokeAny(BDDMockito.argThat(
			withSpanContinuingTraceCallablesOnly()));

	traceExecutorService.invokeAny(callables(), 1L, TimeUnit.DAYS);
	BDDMockito.then(executorService).should().invokeAny(BDDMockito.argThat(
			withSpanContinuingTraceCallablesOnly()),
			BDDMockito.eq(1L) , BDDMockito.eq(TimeUnit.DAYS));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-sleuth,代码行数:26,代码来源:TraceableExecutorServiceTests.java


示例13: addAnnotations

import org.springframework.cloud.sleuth.TraceKeys; //导入依赖的package包/类
private void addAnnotations(TraceKeys traceKeys, Message message, Span span) {
  for (String name : traceKeys.getMessage().getHeaders()) {
    final MessageProperties messageProperties = message.getMessageProperties();
    final Map<String, Object> headers = messageProperties.getHeaders();
    if (headers.containsKey(name)) {
      final String key = traceKeys.getMessage().getPrefix() + name.toLowerCase();
      Object value = headers.get(name);
      if (value == null) {
        value = "null";
      }
      tagIfEntryMissing(span, key, value.toString());
    }
  }
  addPayloadAnnotations(traceKeys, message.getBody(), span);
}
 
开发者ID:netshoes,项目名称:spring-cloud-sleuth-amqp,代码行数:16,代码来源:AmqpMessagingSpanInjector.java


示例14: addPayloadAnnotations

import org.springframework.cloud.sleuth.TraceKeys; //导入依赖的package包/类
private void addPayloadAnnotations(TraceKeys traceKeys, byte[] payload, Span span) {
  if (payload != null) {
    final Payload traceKeyPayloadMessage = traceKeys.getMessage().getPayload();
    tagIfEntryMissing(
        span, traceKeyPayloadMessage.getType(), payload.getClass().getCanonicalName());
    tagIfEntryMissing(span, traceKeyPayloadMessage.getSize(), String.valueOf((payload).length));
  }
}
 
开发者ID:netshoes,项目名称:spring-cloud-sleuth-amqp,代码行数:9,代码来源:AmqpMessagingSpanInjector.java


示例15: testInjectSpanAlreadySampledSuccess

import org.springframework.cloud.sleuth.TraceKeys; //导入依赖的package包/类
@Test
public void testInjectSpanAlreadySampledSuccess() {
  final AmqpMessagingSpanInjector spanInjector = new AmqpMessagingSpanInjector(new TraceKeys());

  final MessageProperties messageProperties = new MessageProperties();
  messageProperties.setHeader(TraceMessageHeaders.SAMPLED_NAME, "1");
  final Message message = new Message("Test".getBytes(), messageProperties);

  spanInjector.inject(null, message);

  final Map<String, Object> headers = message.getMessageProperties().getHeaders();

  Assert.assertEquals("1", headers.get(TraceMessageHeaders.SAMPLED_NAME));
}
 
开发者ID:netshoes,项目名称:spring-cloud-sleuth-amqp,代码行数:15,代码来源:AmqpMessagingSpanInjectorTest.java


示例16: testInjectWithTrackKeysSuccess

import org.springframework.cloud.sleuth.TraceKeys; //导入依赖的package包/类
@Test
public void testInjectWithTrackKeysSuccess() {
  final TraceKeys traceKeys = new TraceKeys();
  final Collection<String> traceKeyMessageHeaders = Arrays.asList("CUSTOM_HEADER", "NULL_HEADER");
  final TraceKeys.Message traceKeyMessage = new TraceKeys.Message();
  traceKeyMessage.setHeaders(traceKeyMessageHeaders);
  traceKeys.setMessage(traceKeyMessage);

  final AmqpMessagingSpanInjector spanInjector = new AmqpMessagingSpanInjector(traceKeys);

  final Span span =
      Span.builder().spanId(Span.hexToId("123")).traceId(Span.hexToId("456")).build();

  final MessageProperties messageProperties = new MessageProperties();
  messageProperties.setHeader("CUSTOM_HEADER", "Custom header value");
  messageProperties.setHeader("NULL_HEADER", null);

  final Message message = new Message("Test".getBytes(), messageProperties);

  spanInjector.inject(span, message);

  final Map<String, Object> headers = message.getMessageProperties().getHeaders();

  Assert.assertEquals("1", headers.get(TraceMessageHeaders.SAMPLED_NAME));
  Assert.assertEquals("0000000000000123", headers.get(TraceMessageHeaders.SPAN_ID_NAME));
  Assert.assertEquals("0000000000000456", headers.get(TraceMessageHeaders.TRACE_ID_NAME));
  Assert.assertEquals(6, headers.size());
  Assert.assertEquals("Custom header value", span.tags().get("message/custom_header"));
  Assert.assertEquals("null", span.tags().get("message/null_header"));
}
 
开发者ID:netshoes,项目名称:spring-cloud-sleuth-amqp,代码行数:31,代码来源:AmqpMessagingSpanInjectorTest.java


示例17: setRestTemplateInterceptor

import org.springframework.cloud.sleuth.TraceKeys; //导入依赖的package包/类
private void setRestTemplateInterceptor(final RestTemplate restTemplate) {
    restTemplate.setInterceptors(Collections.singletonList(
            new TraceRestTemplateInterceptor(this.tracer, new ZipkinHttpSpanInjector(),
                    new HttpTraceKeysInjector(this.tracer, new TraceKeys()))));
}
 
开发者ID:eclipse,项目名称:keti,代码行数:6,代码来源:PolicyEvaluationWithAttributeConnectorIT.java


示例18: sleuthTracer

import org.springframework.cloud.sleuth.TraceKeys; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean(Tracer.class)
public Tracer sleuthTracer(Sampler sampler, Random random,
		SpanNamer spanNamer, SpanLogger spanLogger,
		SpanReporter spanReporter, TraceKeys traceKeys) {
	return new DefaultTracer(sampler, random, spanNamer, spanLogger,
			spanReporter, true, traceKeys);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:9,代码来源:StackdriverTraceAutoConfiguration.java


示例19: buildLabelRenameMapFromTraceKeys

import org.springframework.cloud.sleuth.TraceKeys; //导入依赖的package包/类
/**
 * Builds a
 * @param traceKeys Sleuth's {@link TraceKeys}
 * @return A mapping of Sleuth's HTTP trace keys to Stackdriver label keys
 */
public static Map<String, String> buildLabelRenameMapFromTraceKeys(TraceKeys traceKeys) {
	Map<String, String> labelRenameMap = new HashMap<>();
	TraceKeys.Http httpKeys = traceKeys.getHttp();
	labelRenameMap = new HashMap<>();
	labelRenameMap.put(httpKeys.getHost(), "/http/host");
	labelRenameMap.put(httpKeys.getMethod(), "/http/method");
	labelRenameMap.put(httpKeys.getStatusCode(), "/http/status_code");
	labelRenameMap.put(httpKeys.getRequestSize(), "/http/request/size");
	labelRenameMap.put(httpKeys.getResponseSize(), "/http/response/size");
	labelRenameMap.put(httpKeys.getUrl(), "/http/url");
	return labelRenameMap;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:18,代码来源:LabelExtractor.java


示例20: testLabelReplacement

import org.springframework.cloud.sleuth.TraceKeys; //导入依赖的package包/类
@Test
public void testLabelReplacement() {
	LabelExtractor extractor = new LabelExtractor(new TraceKeys());
	Span span = Span.builder()
			.tag("http.host", "localhost")
			.build();
	Map<String, String> labels = extractor.extract(span, TraceSpan.SpanKind.RPC_CLIENT, null);

	Assert.assertNotNull("labels shouldn't be null", labels);
	Assert.assertEquals("localhost", labels.get("/http/host"));
	Assert.assertFalse(labels.containsKey("http.host"));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gcp,代码行数:13,代码来源:LabelExtractorTests.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PsiCommentImpl类代码示例发布时间:2022-05-22
下一篇:
Java State类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap