本文整理汇总了Java中io.opentracing.tag.Tags类的典型用法代码示例。如果您正苦于以下问题:Java Tags类的具体用法?Java Tags怎么用?Java Tags使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Tags类属于io.opentracing.tag包,在下文中一共展示了Tags类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildAndFinishChildSpan
import io.opentracing.tag.Tags; //导入依赖的package包/类
private void buildAndFinishChildSpan(ConsumerRecord<K, V> record) {
SpanContext parentContext = TracingKafkaUtils.extract(record.headers(), tracer);
if (parentContext != null) {
Tracer.SpanBuilder spanBuilder = tracer.buildSpan("receive")
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT);
spanBuilder.addReference(References.FOLLOWS_FROM, parentContext);
Span span = spanBuilder.start();
SpanDecorator.onResponse(record, span);
span.finish();
// Inject created span context into record headers for extraction by client to continue span chain
TracingKafkaUtils.injectSecond(span.context(), record.headers(), tracer);
}
}
示例2: testUnknownHostException
import io.opentracing.tag.Tags; //导入依赖的package包/类
@Test
public void testUnknownHostException() throws IOException {
CloseableHttpClient client = clientBuilder.build();
try {
client.execute(new HttpGet("http://notexisting.example.com"));
} catch (UnknownHostException ex) {
}
List<MockSpan> mockSpans = mockTracer.finishedSpans();
Assert.assertEquals(2, mockSpans.size());
MockSpan mockSpan = mockSpans.get(0);
Assert.assertEquals(Boolean.TRUE, mockSpan.tags().get(Tags.ERROR.getKey()));
// logs
Assert.assertEquals(1, mockSpan.logEntries().size());
Assert.assertEquals(2, mockSpan.logEntries().get(0).fields().size());
Assert.assertEquals(Tags.ERROR.getKey(), mockSpan.logEntries().get(0).fields().get("event"));
Assert.assertNotNull(mockSpan.logEntries().get(0).fields().get("error.object"));
}
开发者ID:opentracing-contrib,项目名称:java-apache-httpclient,代码行数:22,代码来源:TracingHttpClientBuilderTest.java
示例3: spring
import io.opentracing.tag.Tags; //导入依赖的package包/类
@Test
public void spring() throws SQLException {
BasicDataSource dataSource = getDataSource(false);
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
jdbcTemplate.execute("CREATE TABLE employee (id INTEGER)");
dataSource.close();
List<MockSpan> finishedSpans = mockTracer.finishedSpans();
assertEquals(1, finishedSpans.size());
MockSpan mockSpan = finishedSpans.get(0);
assertEquals(Tags.SPAN_KIND_CLIENT, mockSpan.tags().get(Tags.SPAN_KIND.getKey()));
assertEquals(JdbcTracingUtils.COMPONENT_NAME, mockSpan.tags().get(Tags.COMPONENT.getKey()));
assertThat(mockSpan.tags().get(Tags.DB_STATEMENT.getKey()).toString()).isNotEmpty();
assertEquals("h2", mockSpan.tags().get(Tags.DB_TYPE.getKey()));
assertEquals("sa", mockSpan.tags().get(Tags.DB_USER.getKey()));
assertEquals(0, mockSpan.generatedErrors().size());
assertNull(mockTracer.activeSpan());
}
示例4: testWrongZuulRoutePort
import io.opentracing.tag.Tags; //导入依赖的package包/类
@Test
public void testWrongZuulRoutePort() {
restTemplate.getForEntity("/wrong-port", String.class);
// 1 span from servlet filter, 1 from zuul
await().until(() -> mockTracer.finishedSpans().size() == 2);
List<MockSpan> mockSpans = mockTracer.finishedSpans();
assertEquals(2, mockSpans.size());
MockSpan zuulSpan = getSpansByComponentName(mockSpans, TracePreZuulFilter.COMPONENT_NAME)
.get(0);
assertEquals(TracePreZuulFilter.COMPONENT_NAME, zuulSpan.tags().get(Tags.COMPONENT.getKey()));
assertEquals(500, zuulSpan.tags().get(Tags.HTTP_STATUS.getKey()));
assertEquals(1, zuulSpan.logEntries().size());
assertEquals(Tags.ERROR.getKey(), zuulSpan.logEntries().get(0).fields().get("event"));
assertTrue(zuulSpan.logEntries().get(0).fields().containsKey("error.object"));
}
示例5: testExceptionInHandler
import io.opentracing.tag.Tags; //导入依赖的package包/类
@Test
public void testExceptionInHandler() throws Exception {
{
router.route("/exception").handler(routingContext -> {
throw new IllegalArgumentException("msg");
});
request("/exception", HttpMethod.GET,500);
Awaitility.await().until(reportedSpansSize(), IsEqual.equalTo(1));
}
List<MockSpan> mockSpans = mockTracer.finishedSpans();
Assert.assertEquals(1, mockSpans.size());
MockSpan mockSpan = mockSpans.get(0);
Assert.assertEquals("GET", mockSpan.operationName());
Assert.assertEquals(6, mockSpan.tags().size());
Assert.assertEquals(Boolean.TRUE, mockSpan.tags().get(Tags.ERROR.getKey()));
Assert.assertEquals(500, mockSpan.tags().get(Tags.HTTP_STATUS.getKey()));
Assert.assertEquals("GET", mockSpan.tags().get(Tags.HTTP_METHOD.getKey()));
Assert.assertEquals("http://localhost:8080/exception", mockSpan.tags().get(Tags.HTTP_URL.getKey()));
Assert.assertEquals(1, mockSpan.logEntries().size());
Assert.assertEquals(2, mockSpan.logEntries().get(0).fields().size());
Assert.assertEquals(Tags.ERROR.getKey(), mockSpan.logEntries().get(0).fields().get("event"));
Assert.assertTrue(mockSpan.logEntries().get(0).fields().get("error.object") instanceof Throwable);
}
示例6: testSecuredURLUnAuthorized
import io.opentracing.tag.Tags; //导入依赖的package包/类
@Test
public void testSecuredURLUnAuthorized() throws Exception {
{
getRestTemplate().getForEntity("/secured", String.class);
Awaitility.await().until(reportedSpansSize(), IsEqual.equalTo(1));
}
List<MockSpan> mockSpans = TracingBeansConfiguration.mockTracer.finishedSpans();
Assert.assertEquals(1, mockSpans.size());
assertOnErrors(mockSpans);
MockSpan span = mockSpans.get(0);
Assert.assertEquals("GET", span.operationName());
Assert.assertEquals(5, span.tags().size());
Assert.assertEquals(Tags.SPAN_KIND_SERVER, span.tags().get(Tags.SPAN_KIND.getKey()));
Assert.assertEquals("GET", span.tags().get(Tags.HTTP_METHOD.getKey()));
Assert.assertEquals(getUrl("/secured"), span.tags().get(Tags.HTTP_URL.getKey()));
Assert.assertEquals(401, span.tags().get(Tags.HTTP_STATUS.getKey()));
Assert.assertNotNull(span.tags().get(Tags.COMPONENT.getKey()));
// request does not hit any controller
assertLogEvents(span.logEntries(), Collections.<String>emptyList());
}
示例7: testControllerMappedException
import io.opentracing.tag.Tags; //导入依赖的package包/类
@Test
public void testControllerMappedException() throws Exception {
{
getRestTemplate().getForEntity("/mappedException", String.class);
Awaitility.await().until(reportedSpansSize(), IsEqual.equalTo(1));
}
List<MockSpan> mockSpans = TracingBeansConfiguration.mockTracer.finishedSpans();
Assert.assertEquals(1, mockSpans.size());
assertOnErrors(mockSpans);
MockSpan span = mockSpans.get(0);
Assert.assertEquals("mappedException", span.operationName());
Assert.assertEquals(5, span.tags().size());
Assert.assertEquals(Tags.SPAN_KIND_SERVER, span.tags().get(Tags.SPAN_KIND.getKey()));
Assert.assertEquals("GET", span.tags().get(Tags.HTTP_METHOD.getKey()));
Assert.assertEquals(getUrl("/mappedException"), span.tags().get(Tags.HTTP_URL.getKey()));
Assert.assertEquals(409, span.tags().get(Tags.HTTP_STATUS.getKey()));
Assert.assertNotNull(span.tags().get(Tags.COMPONENT.getKey()));
assertLogEvents(span.logEntries(), Arrays.asList("preHandle", "afterCompletion"));
}
示例8: testSyncWithStandardTags
import io.opentracing.tag.Tags; //导入依赖的package包/类
@Test
public void testSyncWithStandardTags() throws Exception {
{
getRestTemplate().getForEntity("/sync", String.class);
Awaitility.await().until(reportedSpansSize(), IsEqual.equalTo(1));
}
List<MockSpan> mockSpans = TracingBeansConfiguration.mockTracer.finishedSpans();
Assert.assertEquals(1, mockSpans.size());
assertOnErrors(mockSpans);
MockSpan span = mockSpans.get(0);
Assert.assertEquals("sync", span.operationName());
Assert.assertEquals(5, span.tags().size());
Assert.assertEquals(Tags.SPAN_KIND_SERVER, span.tags().get(Tags.SPAN_KIND.getKey()));
Assert.assertEquals("GET", span.tags().get(Tags.HTTP_METHOD.getKey()));
Assert.assertEquals(getUrl("/sync"), span.tags().get(Tags.HTTP_URL.getKey()));
Assert.assertEquals(200, span.tags().get(Tags.HTTP_STATUS.getKey()));
Assert.assertNotNull(span.tags().get(Tags.COMPONENT.getKey()));
assertLogEvents(span.logEntries(), Arrays.asList("preHandle", "afterCompletion"));
}
示例9: testAsyncDeferred
import io.opentracing.tag.Tags; //导入依赖的package包/类
@Test
public void testAsyncDeferred() throws Exception {
{
getRestTemplate().getForEntity("/asyncDeferred", String.class);
Awaitility.await().until(reportedSpansSize(), IsEqual.equalTo(1));
}
List<MockSpan> mockSpans = TracingBeansConfiguration.mockTracer.finishedSpans();
Assert.assertEquals(1, mockSpans.size());
assertOnErrors(mockSpans);
MockSpan span = mockSpans.get(0);
Assert.assertEquals("test", span.operationName());
Assert.assertEquals(5, span.tags().size());
Assert.assertEquals(Tags.SPAN_KIND_SERVER, span.tags().get(Tags.SPAN_KIND.getKey()));
Assert.assertEquals("GET", span.tags().get(Tags.HTTP_METHOD.getKey()));
Assert.assertEquals(getUrl("/asyncDeferred"), span.tags().get(Tags.HTTP_URL.getKey()));
Assert.assertEquals(202, span.tags().get(Tags.HTTP_STATUS.getKey()));
Assert.assertNotNull(span.tags().get(Tags.COMPONENT.getKey()));
assertLogEvents(span.logEntries(), Arrays.asList("preHandle", "afterConcurrentHandlingStarted",
"preHandle", "afterCompletion"));
}
示例10: testScheduled
import io.opentracing.tag.Tags; //导入依赖的package包/类
@Test
public void testScheduled() throws InterruptedException {
await().until(() -> tracer.finishedSpans().size() == 2);
// 1. span created for @Scheduled
// 2. span created inside scheduled method
List<MockSpan> mockSpans = tracer.finishedSpans();
assertEquals(2, mockSpans.size());
TestUtils.assertSameTraceId(mockSpans);
MockSpan localSpan = mockSpans.get(0);
assertEquals("child", localSpan.operationName());
MockSpan scheduledSpan = mockSpans.get(1);
assertEquals(scheduledSpan.context().spanId(), localSpan.parentId());
assertEquals("scheduledFoo", scheduledSpan.operationName());
assertEquals(3, scheduledSpan.tags().size());
assertEquals(0, scheduledSpan.logEntries().size());
assertEquals(ScheduledAspect.COMPONENT_NAME, scheduledSpan.tags().get(Tags.COMPONENT.getKey()));
assertEquals(ScheduledComponent.class.getSimpleName(),
scheduledSpan.tags().get(ExtensionTags.CLASS_TAG.getKey()));
assertEquals("scheduledFoo", scheduledSpan.tags().get(ExtensionTags.METHOD_TAG.getKey()));
}
示例11: testNoURLMapping
import io.opentracing.tag.Tags; //导入依赖的package包/类
@Test
public void testNoURLMapping() {
{
getRestTemplate().getForEntity("/nouUrlMapping", String.class);
Awaitility.await().until(reportedSpansSize(), IsEqual.equalTo(2));
}
List<MockSpan> mockSpans = TracingBeansConfiguration.mockTracer.finishedSpans();
Assert.assertEquals(2, mockSpans.size());
assertOnErrors(mockSpans);
MockSpan span = mockSpans.get(0);
Assert.assertEquals("GET", span.operationName());
Assert.assertEquals(404, span.tags().get(Tags.HTTP_STATUS.getKey()));
assertLogEvents(span.logEntries(), Collections.<String>emptyList());
span = mockSpans.get(1);
Assert.assertEquals(0, span.tags().size());
Assert.assertEquals(mockSpans.get(0).context().spanId(), span.parentId());
Assert.assertEquals(0, span.tags().size());
assertLogEvents(span.logEntries(), Arrays.asList("preHandle", "afterCompletion"));
Assert.assertEquals("BasicErrorController",
span.logEntries().get(0).fields().get("handler.class_simple_name"));
}
示例12: testView
import io.opentracing.tag.Tags; //导入依赖的package包/类
@Test
public void testView() {
{
getRestTemplate().getForEntity("/view", String.class);
Awaitility.await().until(reportedSpansSize(), IsEqual.equalTo(1));
}
List<MockSpan> mockSpans = TracingBeansConfiguration.mockTracer.finishedSpans();
Assert.assertEquals(1, mockSpans.size());
assertOnErrors(mockSpans);
MockSpan span = mockSpans.get(0);
Assert.assertEquals("view", span.operationName());
Assert.assertEquals(5, span.tags().size());
Assert.assertEquals(Tags.SPAN_KIND_SERVER, span.tags().get(Tags.SPAN_KIND.getKey()));
Assert.assertEquals("GET", span.tags().get(Tags.HTTP_METHOD.getKey()));
Assert.assertEquals(getUrl("/view"), span.tags().get(Tags.HTTP_URL.getKey()));
Assert.assertEquals(200, span.tags().get(Tags.HTTP_STATUS.getKey()));
Assert.assertNotNull(span.tags().get(Tags.COMPONENT.getKey()));
assertLogEvents(span.logEntries(), Arrays.asList("preHandle", "afterCompletion"));
}
示例13: testMetricsReporter
import io.opentracing.tag.Tags; //导入依赖的package包/类
@Test
public void testMetricsReporter() {
MetricFamilySamples samples = testCollectorRegistry.metricFamilySamples().nextElement();
assertTrue(samples.samples.isEmpty());
SpanData metricSpanData=Mockito.mock(SpanData.class);
Mockito.when(metricSpanData.getOperationName()).thenReturn("testOp");
Map<String,Object> testTags = new HashMap<String,Object>();
testTags.put(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT);
Mockito.when(metricSpanData.getTags()).thenReturn(testTags);
Mockito.when(metricSpanData.getDuration()).thenReturn(500L);
metricsReporter.reportSpan(metricSpanData);
samples = testCollectorRegistry.metricFamilySamples().nextElement();
assertFalse(samples.samples.isEmpty());
}
开发者ID:opentracing-contrib,项目名称:java-metrics,代码行数:17,代码来源:PrometheusMetricsReporterConfigurationTest.java
示例14: testWithCustomMetricTypeNames
import io.opentracing.tag.Tags; //导入依赖的package包/类
@Test
public void testWithCustomMetricTypeNames() {
PrometheusMetricsReporter reporter = PrometheusMetricsReporter.newMetricsReporter()
.withName("MyName")
.withCollectorRegistry(collectorRegistry)
.withConstLabel("span.kind", Tags.SPAN_KIND_CLIENT) // Override the default, to make sure span metrics reported
.build();
SpanData spanData = mock(SpanData.class);
when(spanData.getOperationName()).thenReturn("testop");
when(spanData.getTags()).thenReturn(Collections.<String,Object>emptyMap());
when(spanData.getDuration()).thenReturn(100000L);
reporter.reportSpan(spanData);
// Check span duration
List<MetricFamilySamples> samples = reporter.getHistogram().collect();
assertEquals(1, samples.size());
assertEquals("MyName", samples.get(0).name);
}
示例15: testWithCustomLabel
import io.opentracing.tag.Tags; //导入依赖的package包/类
@Test
public void testWithCustomLabel() {
MetricLabel metricLabel = new BaggageMetricLabel(METRIC_LABEL_NAME, METRIC_LABEL_VALUE);
PrometheusMetricsReporter reporter = PrometheusMetricsReporter.newMetricsReporter()
.withName("MyName")
.withCollectorRegistry(collectorRegistry)
.withCustomLabel(metricLabel)
.withConstLabel("span.kind", Tags.SPAN_KIND_CLIENT) // Override the default, to make sure span metrics reported
.build();
SpanData spanData = mock(SpanData.class);
when(spanData.getOperationName()).thenReturn("testop");
when(spanData.getTags()).thenReturn(Collections.<String,Object>emptyMap());
when(spanData.getDuration()).thenReturn(100000L);
reporter.reportSpan(spanData);
List<MetricFamilySamples> samples = reporter.getHistogram().collect();
assertEquals(1, samples.size());
for (Sample sample : samples.get(0).samples) {
assertTrue("Expected MetricLabel with name " + METRIC_LABEL_NAME, sample.labelNames.contains(METRIC_LABEL_NAME));
assertTrue("Expected MetricLabel with value " + METRIC_LABEL_VALUE , sample.labelValues.contains(METRIC_LABEL_VALUE));
}
}