本文整理汇总了Java中org.springframework.cloud.sleuth.TraceKeys类的典型用法代码示例。如果您正苦于以下问题:Java TraceKeys类的具体用法?Java TraceKeys怎么用?Java TraceKeys使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TraceKeys类属于org.springframework.cloud.sleuth包,在下文中一共展示了TraceKeys类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
}
示例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());
}
示例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());
}
示例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);
}
}
示例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();
}
示例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);
}
示例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());
}
示例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);
}
示例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();
}
示例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);
}
示例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());
}
示例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));
}
示例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);
}
示例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));
}
}
示例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));
}