本文整理汇总了Java中org.springframework.cloud.sleuth.Tracer类的典型用法代码示例。如果您正苦于以下问题:Java Tracer类的具体用法?Java Tracer怎么用?Java Tracer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Tracer类属于org.springframework.cloud.sleuth包,在下文中一共展示了Tracer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SleuthRxJavaSchedulersHook
import org.springframework.cloud.sleuth.Tracer; //导入依赖的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);
}
}
示例2: should_pass_tracing_information_when_using_Hystrix_commands
import org.springframework.cloud.sleuth.Tracer; //导入依赖的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();
}
示例3: should_set_runnable_name_to_annotated_value
import org.springframework.cloud.sleuth.Tracer; //导入依赖的package包/类
@Test
public void should_set_runnable_name_to_annotated_value()
throws ExecutionException, InterruptedException {
ExecutorService executorService = Executors.newSingleThreadExecutor();
SpanNamer spanNamer = new DefaultSpanNamer();
Tracer tracer = Mockito.mock(Tracer.class);
// tag::span_name_annotated_runnable_execution[]
Runnable runnable = new TraceRunnable(tracer, spanNamer, new TaxCountingRunnable());
Future<?> future = executorService.submit(runnable);
// ... some additional logic ...
future.get();
// end::span_name_annotated_runnable_execution[]
BDDMockito.then(tracer).should().createSpan(BDDMockito.eq("calculateTax"), BDDMockito.any(Span.class));
}
示例4: should_set_runnable_name_to_to_string_value
import org.springframework.cloud.sleuth.Tracer; //导入依赖的package包/类
@Test
public void should_set_runnable_name_to_to_string_value()
throws ExecutionException, InterruptedException {
ExecutorService executorService = Executors.newSingleThreadExecutor();
SpanNamer spanNamer = new DefaultSpanNamer();
Tracer tracer = Mockito.mock(Tracer.class);
// tag::span_name_to_string_runnable_execution[]
Runnable runnable = new TraceRunnable(tracer, spanNamer, new Runnable() {
@Override public void run() {
// perform logic
}
@Override public String toString() {
return "calculateTax";
}
});
Future<?> future = executorService.submit(runnable);
// ... some additional logic ...
future.get();
// end::span_name_to_string_runnable_execution[]
BDDMockito.then(tracer).should().createSpan(BDDMockito.eq("calculateTax"), BDDMockito.any(Span.class));
executorService.shutdown();
}
示例5: optInto128BitTraceId
import org.springframework.cloud.sleuth.Tracer; //导入依赖的package包/类
@Test
public void optInto128BitTraceId() {
EnvironmentTestUtils.addEnvironment(context, "spring.sleuth.traceId128:true");
context.register(PropertyPlaceholderAutoConfiguration.class,
SleuthLogAutoConfiguration.class, TraceAutoConfiguration.class);
context.refresh();
Tracer tracer = context.getBean(Tracer.class);
Span span = null;
try {
span = tracer.createSpan("foo", NeverSampler.INSTANCE);
assertThat(span.getTraceIdHigh()).isNotEqualTo(0L);
assertThat(span.getTraceId()).isNotEqualTo(0L);
}
finally {
if (span != null) {
tracer.close(span);
}
}
}
示例6: SpanSubscriber
import org.springframework.cloud.sleuth.Tracer; //导入依赖的package包/类
SpanSubscriber(Subscriber<? super T> subscriber, Context ctx, Tracer tracer,
String name) {
this.subscriber = subscriber;
this.tracer = tracer;
Span root = ctx.getOrDefault(Span.class, tracer.getCurrentSpan());
if (log.isTraceEnabled()) {
log.trace("Span from context [{}]", root);
}
this.rootSpan = root;
if (log.isTraceEnabled()) {
log.trace("Stored context root span [{}]", this.rootSpan);
}
this.span = tracer.createSpan(name, root);
if (log.isTraceEnabled()) {
log.trace("Created span [{}], with name [{}]", this.span, name);
}
this.context = ctx.put(Span.class, this.span);
}
示例7: should_pass_tracing_information_when_using_Hystrix_commands
import org.springframework.cloud.sleuth.Tracer; //导入依赖的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();
}
示例8: invoke
import org.springframework.cloud.sleuth.Tracer; //导入依赖的package包/类
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
boolean isTraceDubbo = false;
Tracer tracer = null;
SpanInjector spanInjector = null;
try {
tracer = ApplicationContextAwareBean.CONTEXT.getBean(Tracer.class);
spanInjector = ApplicationContextAwareBean.CONTEXT.getBean(DubboSpanInjector.class);
isTraceDubbo = (tracer != null && spanInjector != null);
if (isTraceDubbo) {
String spanName = invoker.getUrl().getParameter("interface") + ":" + invocation.getMethodName() + ":" + invoker.getUrl().getParameter("version") + "(" + invoker.getUrl().getHost() + ")";
Span newSpan = tracer.createSpan(spanName);
spanInjector.inject(newSpan, RpcContext.getContext());
newSpan.logEvent(Span.CLIENT_SEND);
}
Result result = invoker.invoke(invocation);
return result;
} finally {
if (isTraceDubbo) {
if (tracer.isTracing()) {
tracer.getCurrentSpan().logEvent(Span.CLIENT_RECV);
tracer.close(tracer.getCurrentSpan());
}
}
}
}
示例9: sleuthTracer
import org.springframework.cloud.sleuth.Tracer; //导入依赖的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);
}
示例10: amqpMessagingSpanManager
import org.springframework.cloud.sleuth.Tracer; //导入依赖的package包/类
@Bean
@ConditionalOnProperty(value = "spring.sleuth.amqp.enabled", matchIfMissing = true)
@ConditionalOnMissingBean(AmqpMessagingSpanManager.class)
public AmqpMessagingSpanManager amqpMessagingSpanManager(
AmqpMessagingSpanInjector amqpMessagingSpanInjector,
AmqpMessagingSpanExtractor amqpMessagingSpanExtractor,
Tracer tracer) {
return new DefaultAmqpMessagingSpanManager(
amqpMessagingSpanInjector, amqpMessagingSpanExtractor, tracer);
}
开发者ID:netshoes,项目名称:spring-cloud-sleuth-amqp-starter,代码行数:11,代码来源:SleuthAmqpMessagingAutoConfiguration.java
示例11: SpringOneController
import org.springframework.cloud.sleuth.Tracer; //导入依赖的package包/类
@Autowired
public SpringOneController(RestTemplate restTemplate, Tracer tracer,
SpanNamer spanNamer, SpringOneWorker springOneWorker,
AsyncRestTemplate asyncRestTemplate, Service1Client service1Client,
TraceKeys traceKeys) {
this.restTemplate = restTemplate;
this.tracer = tracer;
this.spanNamer = spanNamer;
this.springOneWorker = springOneWorker;
this.asyncRestTemplate = asyncRestTemplate;
this.service1Client = service1Client;
this.traceKeys = traceKeys;
}
示例12: traceWebFilter
import org.springframework.cloud.sleuth.Tracer; //导入依赖的package包/类
@Bean
public FilterRegistrationBean traceWebFilter(Tracer tracer, TraceKeys traceKeys,
SkipPatternProvider skipPatternProvider, SpanReporter spanReporter,
SpanExtractor<HttpServletRequest> spanExtractor,
SpanInjector<HttpServletResponse> spanInjector,
HttpTraceKeysInjector httpTraceKeysInjector, TraceFilter traceFilter) {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(traceFilter);
filterRegistrationBean.setDispatcherTypes(ASYNC, ERROR, FORWARD, INCLUDE, REQUEST);
return filterRegistrationBean;
}
示例13: traceFilter
import org.springframework.cloud.sleuth.Tracer; //导入依赖的package包/类
@Bean
public TraceFilter traceFilter(Tracer tracer, TraceKeys traceKeys,
SkipPatternProvider skipPatternProvider, SpanReporter spanReporter,
SpanExtractor<HttpServletRequest> spanExtractor,
SpanInjector<HttpServletResponse> spanInjector,
HttpTraceKeysInjector httpTraceKeysInjector) {
return new TraceFilter(tracer, traceKeys, skipPatternProvider.skipPattern(),
spanReporter, spanExtractor, spanInjector, httpTraceKeysInjector);
}
示例14: traceRestTemplateInterceptor
import org.springframework.cloud.sleuth.Tracer; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
public TraceRestTemplateInterceptor traceRestTemplateInterceptor(Tracer tracer,
SpanInjector<HttpRequest> spanInjector,
HttpTraceKeysInjector httpTraceKeysInjector) {
return new TraceRestTemplateInterceptor(tracer, spanInjector, httpTraceKeysInjector);
}
示例15: TraceAsyncClientHttpRequestFactoryWrapper
import org.springframework.cloud.sleuth.Tracer; //导入依赖的package包/类
/**
* According to the JavaDocs all Spring {@link AsyncClientHttpRequestFactory} implement
* the {@link ClientHttpRequestFactory} interface.
*
* In case that it's not true we're setting the {@link SimpleClientHttpRequestFactory}
* as a default for sync request processing.
*
* @see org.springframework.web.client.AsyncRestTemplate#AsyncRestTemplate(AsyncClientHttpRequestFactory)
*/
public TraceAsyncClientHttpRequestFactoryWrapper(Tracer tracer,
SpanInjector<HttpRequest> spanInjector,
AsyncClientHttpRequestFactory asyncDelegate,
HttpTraceKeysInjector httpTraceKeysInjector) {
super(tracer, spanInjector, httpTraceKeysInjector);
this.asyncDelegate = asyncDelegate;
this.syncDelegate = asyncDelegate instanceof ClientHttpRequestFactory ?
(ClientHttpRequestFactory) asyncDelegate : defaultClientHttpRequestFactory();
}