本文整理汇总了Java中org.springframework.cloud.sleuth.sampler.AlwaysSampler类的典型用法代码示例。如果您正苦于以下问题:Java AlwaysSampler类的具体用法?Java AlwaysSampler怎么用?Java AlwaysSampler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AlwaysSampler类属于org.springframework.cloud.sleuth.sampler包,在下文中一共展示了AlwaysSampler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: should_pass_tracing_information_when_using_Hystrix_commands
import org.springframework.cloud.sleuth.sampler.AlwaysSampler; //导入依赖的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();
}
示例2: testSpanPropagation
import org.springframework.cloud.sleuth.sampler.AlwaysSampler; //导入依赖的package包/类
@Test
public void testSpanPropagation() {
Span span = this.tracer.createSpan("http:testSendMessage", new AlwaysSampler());
this.channel.send(MessageBuilder.withPayload("hi").build());
Long expectedSpanId = span.getSpanId();
this.tracer.close(span);
Message<?> message = this.channel.receive(0);
assertNotNull("message was null", message);
Long spanId = Span
.hexToId(message.getHeaders().get(Span.SPAN_ID_NAME, String.class));
assertNotEquals("spanId was equal to parent's id", expectedSpanId, spanId);
long traceId = Span
.hexToId(message.getHeaders().get(Span.TRACE_ID_NAME, String.class));
assertNotNull("traceId was null", traceId);
Long parentId = Span
.hexToId(message.getHeaders().get(Span.PARENT_ID_NAME, String.class));
assertEquals("parentId was not equal to parent's id", expectedSpanId, parentId);
}
示例3: should_pass_tracing_information_when_using_Hystrix_commands
import org.springframework.cloud.sleuth.sampler.AlwaysSampler; //导入依赖的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();
}
示例4: testSpanPropagation
import org.springframework.cloud.sleuth.sampler.AlwaysSampler; //导入依赖的package包/类
@Test
public void testSpanPropagation() {
Span span = this.tracer.createSpan("http:testSendMessage", new AlwaysSampler());
this.channel.send(MessageBuilder.withPayload("hi").build());
Long expectedSpanId = span.getSpanId();
this.tracer.close(span);
Message<?> message = this.channel.receive(0);
assertNotNull("message was null", message);
Long spanId = Span.hexToId(
message.getHeaders().get(TraceMessageHeaders.SPAN_ID_NAME, String.class));
assertNotEquals("spanId was equal to parent's id", expectedSpanId, spanId);
long traceId = Span.hexToId(message.getHeaders()
.get(TraceMessageHeaders.TRACE_ID_NAME, String.class));
assertNotNull("traceId was null", traceId);
Long parentId = Span.hexToId(message.getHeaders()
.get(TraceMessageHeaders.PARENT_ID_NAME, String.class));
assertEquals("parentId was not equal to parent's id", expectedSpanId, parentId);
}
开发者ID:spring-cloud,项目名称:spring-cloud-sleuth,代码行数:26,代码来源:TraceContextPropagationChannelInterceptorTests.java
示例5: shouldCloseASpanWhenExceptionOccurred
import org.springframework.cloud.sleuth.sampler.AlwaysSampler; //导入依赖的package包/类
@Test
public void shouldCloseASpanWhenExceptionOccurred() {
Span span = this.tracer.createSpan("http:testSendMessage", new AlwaysSampler());
Map<String, String> errorHeaders = new HashMap<>();
errorHeaders.put("THROW_EXCEPTION", "TRUE");
try {
this.messagingTemplate.send(
MessageBuilder.withPayload("hi").copyHeaders(errorHeaders).build());
SleuthAssertions.fail("Exception should occur");
}
catch (RuntimeException e) {
}
then(this.message).isNotNull();
this.tracer.close(span);
then(TestSpanContextHolder.getCurrentSpan()).isNull();
then(new ListOfSpans(this.accumulator.getSpans()))
.hasASpanWithTagEqualTo(Span.SPAN_ERROR_TAG_NAME,
"A terrible exception has occurred");
}
示例6: shouldUpdateLogsInSpanWhenItGetsContinued
import org.springframework.cloud.sleuth.sampler.AlwaysSampler; //导入依赖的package包/类
@Test
public void shouldUpdateLogsInSpanWhenItGetsContinued() {
DefaultTracer tracer = new DefaultTracer(new AlwaysSampler(), new Random(),
this.spanNamer, this.spanLogger, this.spanReporter, new TraceKeys());
Span span = Span.builder().name(IMPORTANT_WORK_1).traceId(1L).spanId(1L)
.build();
Span continuedSpan = tracer.continueSpan(span);
tracer.addTag("key", "value");
continuedSpan.logEvent("event");
then(span).hasATag("key", "value").hasLoggedAnEvent("event");
then(continuedSpan).hasATag("key", "value").hasLoggedAnEvent("event");
then(span).isEqualTo(continuedSpan);
tracer.close(span);
}
示例7: shouldPropagateBaggageToContinuedSpan
import org.springframework.cloud.sleuth.sampler.AlwaysSampler; //导入依赖的package包/类
@Test
public void shouldPropagateBaggageToContinuedSpan() {
DefaultTracer tracer = new DefaultTracer(new AlwaysSampler(), new Random(),
this.spanNamer, this.spanLogger, this.spanReporter, new TraceKeys());
Span parent = Span.builder().name(IMPORTANT_WORK_1).traceId(1L).spanId(1L)
.baggage("foo", "bar").build();
Span continuedSpan = tracer.continueSpan(parent);
parent.setBaggageItem("baz1", "baz1");
continuedSpan.setBaggageItem("baz2", "baz2");
then(parent).hasBaggageItem("foo", "bar")
.hasBaggageItem("baz1", "baz1")
.hasBaggageItem("baz2", "baz2");
then(continuedSpan).hasBaggageItem("foo", "bar")
.hasBaggageItem("baz1", "baz1")
.hasBaggageItem("baz2", "baz2");
then(parent).isEqualTo(continuedSpan);
}
示例8: traced
import org.springframework.cloud.sleuth.sampler.AlwaysSampler; //导入依赖的package包/类
@RequestMapping("/traced")
public String traced() throws InterruptedException {
Span span = this.tracer.createSpan("http:customTraceEndpoint",
new AlwaysSampler());
int millis = this.random.nextInt(1000);
log.info(String.format("Sleeping for [%d] millis", millis));
Thread.sleep(millis);
this.tracer.addTag("random-sleep-millis", String.valueOf(millis));
String s = this.restTemplate
.getForObject("http://localhost:" + this.port + "/call", String.class);
this.tracer.close(span);
return "traced/" + s;
}
示例9: traced
import org.springframework.cloud.sleuth.sampler.AlwaysSampler; //导入依赖的package包/类
@RequestMapping("/traced")
public String traced() throws InterruptedException {
Span span = this.tracer.createSpan("http:customTraceEndpoint",
new AlwaysSampler());
int millis = this.random.nextInt(1000);
log.info(String.format("Sleeping for [%d] millis", millis));
Thread.sleep(millis);
this.tracer.addTag("random-sleep-millis", String.valueOf(millis));
String s = this.restTemplate.getForObject("http://localhost:" + this.port
+ "/call", String.class);
this.tracer.close(span);
return "traced/" + s;
}
示例10: setup
import org.springframework.cloud.sleuth.sampler.AlwaysSampler; //导入依赖的package包/类
@Before
public void setup() {
this.tracer = new DefaultTracer(new AlwaysSampler(), new Random(),
new DefaultSpanNamer(), new NoOpSpanLogger(), this.spanAccumulator);
this.template.setInterceptors(Arrays.<ClientHttpRequestInterceptor>asList(
new TraceRestTemplateInterceptor(this.tracer, new HttpRequestInjector(),
new HttpTraceKeysInjector(this.tracer, new TraceKeys()))));
TestSpanContextHolder.removeCurrentSpan();
}
示例11: setup
import org.springframework.cloud.sleuth.sampler.AlwaysSampler; //导入依赖的package包/类
@Before
public void setup() {
this.tracer = new DefaultTracer(new AlwaysSampler(), new Random(),
new DefaultSpanNamer(), new NoOpSpanLogger(), new NoOpSpanReporter());
this.template.setInterceptors(Arrays.<ClientHttpRequestInterceptor>asList(
new TraceRestTemplateInterceptor(this.tracer, new HttpRequestInjector(),
new HttpTraceKeysInjector(this.tracer, new TraceKeys()))));
TestSpanContextHolder.removeCurrentSpan();
}
示例12: headerCreation
import org.springframework.cloud.sleuth.sampler.AlwaysSampler; //导入依赖的package包/类
@Test
public void headerCreation() {
Span span = this.tracer.createSpan("http:testSendMessage", new AlwaysSampler());
this.channel.send(MessageBuilder.withPayload("hi").build());
this.tracer.close(span);
assertNotNull("message was null", this.message);
String spanId = this.message.getHeaders().get(Span.SPAN_ID_NAME, String.class);
assertNotNull("spanId was null", spanId);
String traceId = this.message.getHeaders().get(Span.TRACE_ID_NAME, String.class);
assertNotNull("traceId was null", traceId);
assertNull(TestSpanContextHolder.getCurrentSpan());
}
示例13: headerCreationViaMessagingTemplate
import org.springframework.cloud.sleuth.sampler.AlwaysSampler; //导入依赖的package包/类
@Test
public void headerCreationViaMessagingTemplate() {
Span span = this.tracer.createSpan("http:testSendMessage", new AlwaysSampler());
this.messagingTemplate.send(MessageBuilder.withPayload("hi").build());
this.tracer.close(span);
assertNotNull("message was null", this.message);
String spanId = this.message.getHeaders().get(Span.SPAN_ID_NAME, String.class);
assertNotNull("spanId was null", spanId);
String traceId = this.message.getHeaders().get(Span.TRACE_ID_NAME, String.class);
assertNotNull("traceId was null", traceId);
assertNull(TestSpanContextHolder.getCurrentSpan());
}
示例14: setup
import org.springframework.cloud.sleuth.sampler.AlwaysSampler; //导入依赖的package包/类
@Before
public void setup() {
this.tracer = new DefaultTracer(new AlwaysSampler(), new Random(),
this.spanNamer, new NoOpSpanLogger(), new NoOpSpanReporter());
this.traceManagerableExecutorService = new TraceableExecutorService(this.executorService,
this.tracer, new TraceKeys(), this.spanNamer);
TestSpanContextHolder.removeCurrentSpan();
}
示例15: should_wrap_runnable_in_its_sleuth_representative
import org.springframework.cloud.sleuth.sampler.AlwaysSampler; //导入依赖的package包/类
@Test
public void should_wrap_runnable_in_its_sleuth_representative() {
SpanNamer spanNamer = new DefaultSpanNamer();
Tracer tracer = new DefaultTracer(new AlwaysSampler(), new Random(), spanNamer,
new NoOpSpanLogger(), new NoOpSpanReporter());
Span initialSpan = tracer.createSpan("initialSpan");
// tag::trace_runnable[]
Runnable runnable = new Runnable() {
@Override
public void run() {
// do some work
}
@Override
public String toString() {
return "spanNameFromToStringMethod";
}
};
// Manual `TraceRunnable` creation with explicit "calculateTax" Span name
Runnable traceRunnable = new TraceRunnable(tracer, spanNamer, runnable, "calculateTax");
// Wrapping `Runnable` with `Tracer`. The Span name will be taken either from the
// `@SpanName` annotation or from `toString` method
Runnable traceRunnableFromTracer = tracer.wrap(runnable);
// end::trace_runnable[]
then(traceRunnable).isExactlyInstanceOf(TraceRunnable.class);
then(traceRunnableFromTracer).isExactlyInstanceOf(TraceRunnable.class);
tracer.close(initialSpan);
}