Search in sources :

Example 1 with Tag

use of io.jaegertracing.thriftjava.Tag in project instrumentation-java by census-instrumentation.

the class JaegerExporterHandler method timedEventsToLogs.

private static List<Log> timedEventsToLogs(final List<SpanData.TimedEvent<Annotation>> annotations, final List<SpanData.TimedEvent<MessageEvent>> messageEvents) {
    final List<Log> logs = Lists.newArrayListWithExpectedSize(annotations.size() + messageEvents.size());
    for (final SpanData.TimedEvent<Annotation> event : annotations) {
        final long timestampsInMicros = timestampToMicros(event.getTimestamp());
        logs.add(new Log(timestampsInMicros, attributesToTags(event.getEvent().getAttributes(), descriptionToTag(event.getEvent().getDescription()))));
    }
    for (final SpanData.TimedEvent<MessageEvent> event : messageEvents) {
        final long timestampsInMicros = timestampToMicros(event.getTimestamp());
        final Tag tagMessageId = new Tag(MESSAGE_EVENT_ID, TagType.LONG).setVLong(event.getEvent().getMessageId());
        final Tag tagCompressedSize = new Tag(MESSAGE_EVENT_COMPRESSED_SIZE, TagType.LONG).setVLong(event.getEvent().getCompressedMessageSize());
        final Tag tagUncompressedSize = new Tag(MESSAGE_EVENT_UNCOMPRESSED_SIZE, TagType.LONG).setVLong(event.getEvent().getUncompressedMessageSize());
        logs.add(new Log(timestampsInMicros, Arrays.asList(event.getEvent().getType() == Type.RECEIVED ? RECEIVED_MESSAGE_EVENT_TAG : SENT_MESSAGE_EVENT_TAG, tagMessageId, tagCompressedSize, tagUncompressedSize)));
    }
    return logs;
}
Also used : SpanData(io.opencensus.trace.export.SpanData) Log(io.jaegertracing.thriftjava.Log) MessageEvent(io.opencensus.trace.MessageEvent) Tag(io.jaegertracing.thriftjava.Tag) Annotation(io.opencensus.trace.Annotation)

Example 2 with Tag

use of io.jaegertracing.thriftjava.Tag in project instrumentation-java by census-instrumentation.

the class JaegerExporterHandler method spanDataToJaegerThriftSpan.

private Span spanDataToJaegerThriftSpan(final SpanData spanData) {
    final long startTimeInMicros = timestampToMicros(spanData.getStartTimestamp());
    final long endTimeInMicros = timestampToMicros(spanData.getEndTimestamp());
    final SpanContext context = spanData.getContext();
    copyToBuffer(context.getTraceId());
    List<Tag> tags = attributesToTags(spanData.getAttributes().getAttributeMap(), spanKindToTag(spanData.getKind()));
    addStatusTags(tags, spanData.getStatus());
    return new io.jaegertracing.thriftjava.Span(traceIdLow(), traceIdHigh(), spanIdToLong(context.getSpanId()), spanIdToLong(spanData.getParentSpanId()), spanData.getName(), optionsToFlags(context.getTraceOptions()), startTimeInMicros, endTimeInMicros - startTimeInMicros).setReferences(linksToReferences(spanData.getLinks().getLinks())).setTags(tags).setLogs(timedEventsToLogs(spanData.getAnnotations().getEvents(), spanData.getMessageEvents().getEvents()));
}
Also used : SpanContext(io.opencensus.trace.SpanContext) Span(io.jaegertracing.thriftjava.Span) Tag(io.jaegertracing.thriftjava.Tag)

Example 3 with Tag

use of io.jaegertracing.thriftjava.Tag in project jaeger-client-java by jaegertracing.

the class JaegerThriftSpanConverterTest method testConvertSpan.

@Test
public void testConvertSpan() {
    Map<String, Object> fields = new HashMap<String, Object>();
    fields.put("k", "v");
    JaegerSpan span = tracer.buildSpan("operation-name").start();
    span = span.log(1, fields);
    span = span.setBaggageItem("foo", "bar");
    io.jaegertracing.thriftjava.Span thriftSpan = JaegerThriftSpanConverter.convertSpan(span);
    assertEquals("operation-name", thriftSpan.getOperationName());
    assertEquals(2, thriftSpan.getLogs().size());
    Log thriftLog = thriftSpan.getLogs().get(0);
    assertEquals(1, thriftLog.getTimestamp());
    assertEquals(1, thriftLog.getFields().size());
    Tag thriftTag = thriftLog.getFields().get(0);
    assertEquals("k", thriftTag.getKey());
    assertEquals("v", thriftTag.getVStr());
    thriftLog = thriftSpan.getLogs().get(1);
    assertEquals(3, thriftLog.getFields().size());
    thriftTag = thriftLog.getFields().get(0);
    assertEquals("event", thriftTag.getKey());
    assertEquals("baggage", thriftTag.getVStr());
    thriftTag = thriftLog.getFields().get(1);
    assertEquals("value", thriftTag.getKey());
    assertEquals("bar", thriftTag.getVStr());
    thriftTag = thriftLog.getFields().get(2);
    assertEquals("key", thriftTag.getKey());
    assertEquals("foo", thriftTag.getVStr());
}
Also used : HashMap(java.util.HashMap) Log(io.jaegertracing.thriftjava.Log) JaegerSpan(io.jaegertracing.internal.JaegerSpan) Tag(io.jaegertracing.thriftjava.Tag) Test(org.junit.Test)

Example 4 with Tag

use of io.jaegertracing.thriftjava.Tag in project java by wavefrontHQ.

the class JaegerTChannelCollectorHandlerTest method testProtectedTagsProcessOverridesProxyConfig.

@Test
public void testProtectedTagsProcessOverridesProxyConfig() throws Exception {
    // cluster, shard and service are special tags, because they're indexed by wavefront
    // The priority order is:
    // Span Level > Process Level > Proxy Level > Default
    reset(mockTraceHandler, mockTraceLogsHandler);
    mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(9).setName("HTTP GET /").setSource("source-processtag").setSpanId("00000000-0000-0000-0000-00000023cace").setTraceId("00000000-4996-02d2-0000-011f71fb04cb").setAnnotations(ImmutableList.of(new Annotation("ip", "10.0.0.1"), new Annotation("jaegerSpanId", "23cace"), new Annotation("jaegerTraceId", "499602d20000011f71fb04cb"), new Annotation("service", "frontend"), new Annotation("application", "application-processtag"), new Annotation("cluster", "cluster-processtag"), new Annotation("shard", "shard-processtag"))).build());
    expectLastCall();
    replay(mockTraceHandler, mockTraceLogsHandler);
    JaegerTChannelCollectorHandler handler = new JaegerTChannelCollectorHandler("9876", mockTraceHandler, mockTraceLogsHandler, null, () -> false, () -> false, null, new SpanSampler(new RateSampler(1.0D), () -> null), null, null);
    Tag ipTag = new Tag("ip", TagType.STRING);
    ipTag.setVStr("10.0.0.1");
    Tag sourceProcessTag = new Tag("source", TagType.STRING);
    sourceProcessTag.setVStr("source-processtag");
    Tag customApplicationProcessTag = new Tag("application", TagType.STRING);
    customApplicationProcessTag.setVStr("application-processtag");
    Tag customClusterProcessTag = new Tag("cluster", TagType.STRING);
    customClusterProcessTag.setVStr("cluster-processtag");
    Tag customShardProcessTag = new Tag("shard", TagType.STRING);
    customShardProcessTag.setVStr("shard-processtag");
    io.jaegertracing.thriftjava.Span span = new io.jaegertracing.thriftjava.Span(1234567890123L, 1234567890L, 2345678L, 0, "HTTP GET /", 1, startTime * 1000, 9 * 1000);
    Batch testBatch = new Batch();
    testBatch.process = new Process();
    testBatch.process.serviceName = "frontend";
    testBatch.process.setTags(ImmutableList.of(ipTag, sourceProcessTag, customApplicationProcessTag, customClusterProcessTag, customShardProcessTag));
    testBatch.setSpans(ImmutableList.of(span));
    Collector.submitBatches_args batches = new Collector.submitBatches_args();
    batches.addToBatches(testBatch);
    ThriftRequest<Collector.submitBatches_args> request = new ThriftRequest.Builder<Collector.submitBatches_args>("jaeger-collector", "Collector::submitBatches").setBody(batches).build();
    handler.handleImpl(request);
    verify(mockTraceHandler, mockTraceLogsHandler);
}
Also used : RateSampler(com.wavefront.sdk.entities.tracing.sampling.RateSampler) SpanSampler(com.wavefront.agent.sampler.SpanSampler) Process(io.jaegertracing.thriftjava.Process) Span(wavefront.report.Span) Annotation(wavefront.report.Annotation) Batch(io.jaegertracing.thriftjava.Batch) Collector(io.jaegertracing.thriftjava.Collector) Tag(io.jaegertracing.thriftjava.Tag) Test(org.junit.Test)

Example 5 with Tag

use of io.jaegertracing.thriftjava.Tag in project java by wavefrontHQ.

the class JaegerTChannelCollectorHandlerTest method testSourceTagPriority.

@Test
public void testSourceTagPriority() throws Exception {
    reset(mockTraceHandler, mockTraceLogsHandler);
    mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(9).setName("HTTP GET /").setSource("source-spantag").setSpanId("00000000-0000-0000-0000-00000023cace").setTraceId("00000000-4996-02d2-0000-011f71fb04cb").setAnnotations(ImmutableList.of(new Annotation("ip", "10.0.0.1"), new Annotation("jaegerSpanId", "23cace"), new Annotation("jaegerTraceId", "499602d20000011f71fb04cb"), new Annotation("service", "frontend"), new Annotation("parent", "00000000-0000-0000-0000-00000012d687"), new Annotation("application", "Jaeger"), new Annotation("cluster", "none"), new Annotation("shard", "none"))).build());
    expectLastCall();
    mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(4).setName("HTTP GET").setSource("source-processtag").setSpanId("00000000-0000-0000-0000-00000012d687").setTraceId("00000000-4996-02d2-0000-011f71fb04cb").setAnnotations(ImmutableList.of(new Annotation("ip", "10.0.0.1"), new Annotation("jaegerSpanId", "12d687"), new Annotation("jaegerTraceId", "499602d20000011f71fb04cb"), new Annotation("service", "frontend"), new Annotation("application", "Jaeger"), new Annotation("cluster", "none"), new Annotation("shard", "none"))).build());
    expectLastCall();
    mockTraceHandler.report(Span.newBuilder().setCustomer("dummy").setStartMillis(startTime).setDuration(3456).setName("HTTP GET /test").setSource("hostname-processtag").setSpanId("00000000-0000-0000-0000-0051759bfc69").setTraceId("0000011e-ab2a-9944-0000-000049631900").setAnnotations(ImmutableList.of(new Annotation("ip", "10.0.0.1"), new Annotation("jaegerSpanId", "51759bfc69"), new Annotation("jaegerTraceId", "11eab2a99440000000049631900"), new Annotation("service", "frontend"), new Annotation("application", "Jaeger"), new Annotation("cluster", "none"), new Annotation("shard", "none"))).build());
    expectLastCall();
    replay(mockTraceHandler, mockTraceLogsHandler);
    JaegerTChannelCollectorHandler handler = new JaegerTChannelCollectorHandler("9876", mockTraceHandler, mockTraceLogsHandler, null, () -> false, () -> false, null, new SpanSampler(new RateSampler(1.0D), () -> null), null, null);
    Tag ipTag = new Tag("ip", TagType.STRING);
    ipTag.setVStr("10.0.0.1");
    Tag hostNameProcessTag = new Tag("hostname", TagType.STRING);
    hostNameProcessTag.setVStr("hostname-processtag");
    Tag customSourceProcessTag = new Tag("source", TagType.STRING);
    customSourceProcessTag.setVStr("source-processtag");
    Tag customSourceSpanTag = new Tag("source", TagType.STRING);
    customSourceSpanTag.setVStr("source-spantag");
    io.jaegertracing.thriftjava.Span span1 = new io.jaegertracing.thriftjava.Span(1234567890123L, 1234567890L, 2345678L, 1234567L, "HTTP GET /", 1, startTime * 1000, 9 * 1000);
    span1.setTags(ImmutableList.of(customSourceSpanTag));
    io.jaegertracing.thriftjava.Span span2 = new io.jaegertracing.thriftjava.Span(1234567890123L, 1234567890L, 1234567L, 0L, "HTTP GET", 1, startTime * 1000, 4 * 1000);
    io.jaegertracing.thriftjava.Span span3 = new io.jaegertracing.thriftjava.Span(1231231232L, 1231232342340L, 349865507945L, 0, "HTTP GET /test", 1, startTime * 1000, 3456 * 1000);
    Batch testBatch = new Batch();
    testBatch.process = new Process();
    testBatch.process.serviceName = "frontend";
    testBatch.process.setTags(ImmutableList.of(ipTag, hostNameProcessTag, customSourceProcessTag));
    testBatch.setSpans(ImmutableList.of(span1, span2));
    Collector.submitBatches_args batches = new Collector.submitBatches_args();
    batches.addToBatches(testBatch);
    ThriftRequest<Collector.submitBatches_args> request = new ThriftRequest.Builder<Collector.submitBatches_args>("jaeger-collector", "Collector::submitBatches").setBody(batches).build();
    handler.handleImpl(request);
    // Span3 to verify hostname process level tags precedence. So do not set any process level
    // source tag.
    Batch testBatchSourceAsProcessTagHostName = new Batch();
    testBatchSourceAsProcessTagHostName.process = new Process();
    testBatchSourceAsProcessTagHostName.process.serviceName = "frontend";
    testBatchSourceAsProcessTagHostName.process.setTags(ImmutableList.of(ipTag, hostNameProcessTag));
    testBatchSourceAsProcessTagHostName.setSpans(ImmutableList.of(span3));
    Collector.submitBatches_args batchesSourceAsProcessTagHostName = new Collector.submitBatches_args();
    batchesSourceAsProcessTagHostName.addToBatches(testBatchSourceAsProcessTagHostName);
    ThriftRequest<Collector.submitBatches_args> requestForProxyLevel = new ThriftRequest.Builder<Collector.submitBatches_args>("jaeger-collector", "Collector::submitBatches").setBody(batchesSourceAsProcessTagHostName).build();
    handler.handleImpl(requestForProxyLevel);
    verify(mockTraceHandler, mockTraceLogsHandler);
}
Also used : RateSampler(com.wavefront.sdk.entities.tracing.sampling.RateSampler) SpanSampler(com.wavefront.agent.sampler.SpanSampler) Process(io.jaegertracing.thriftjava.Process) Span(wavefront.report.Span) Annotation(wavefront.report.Annotation) Batch(io.jaegertracing.thriftjava.Batch) Collector(io.jaegertracing.thriftjava.Collector) Tag(io.jaegertracing.thriftjava.Tag) Test(org.junit.Test)

Aggregations

Tag (io.jaegertracing.thriftjava.Tag)23 Test (org.junit.Test)14 Annotation (wavefront.report.Annotation)12 SpanSampler (com.wavefront.agent.sampler.SpanSampler)11 Batch (io.jaegertracing.thriftjava.Batch)11 Span (wavefront.report.Span)11 Process (io.jaegertracing.thriftjava.Process)10 Collector (io.jaegertracing.thriftjava.Collector)9 RateSampler (com.wavefront.sdk.entities.tracing.sampling.RateSampler)8 Log (io.jaegertracing.thriftjava.Log)8 SpanLog (wavefront.report.SpanLog)5 Span (io.jaegertracing.thriftjava.Span)3 SpanData (io.opencensus.trace.export.SpanData)3 ArrayList (java.util.ArrayList)3 DurationSampler (com.wavefront.sdk.entities.tracing.sampling.DurationSampler)2 SpanRef (io.jaegertracing.thriftjava.SpanRef)2 AttributeValue (io.opencensus.trace.AttributeValue)2 Map (java.util.Map)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1