Search in sources :

Example 1 with Tag

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

the class JaegerThriftSpanConverter method buildLogs.

static List<Log> buildLogs(List<LogData> logs) {
    List<Log> thriftLogs = new ArrayList<Log>();
    if (logs != null) {
        for (LogData logData : logs) {
            Log thriftLog = new Log();
            thriftLog.setTimestamp(logData.getTime());
            if (logData.getFields() != null) {
                thriftLog.setFields(buildTags(logData.getFields()));
            } else {
                List<Tag> tags = new ArrayList<Tag>();
                if (logData.getMessage() != null) {
                    tags.add(buildTag("event", logData.getMessage()));
                }
                thriftLog.setFields(tags);
            }
            thriftLogs.add(thriftLog);
        }
    }
    return thriftLogs;
}
Also used : LogData(com.uber.jaeger.LogData) Log(com.uber.jaeger.thriftjava.Log) ArrayList(java.util.ArrayList) Tag(com.uber.jaeger.thriftjava.Tag)

Example 2 with Tag

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

the class JaegerThriftSpanConverter method buildTag.

static Tag buildTag(String tagKey, Object tagValue) {
    Tag tag = new Tag();
    tag.setKey(tagKey);
    if (tagValue instanceof Integer || tagValue instanceof Short || tagValue instanceof Long) {
        tag.setVType(TagType.LONG);
        tag.setVLong(((Number) tagValue).longValue());
    } else if (tagValue instanceof Double || tagValue instanceof Float) {
        tag.setVType(TagType.DOUBLE);
        tag.setVDouble(((Number) tagValue).doubleValue());
    } else if (tagValue instanceof Boolean) {
        tag.setVType(TagType.BOOL);
        tag.setVBool((Boolean) tagValue);
    } else {
        buildStringTag(tag, tagValue);
    }
    return tag;
}
Also used : Tag(com.uber.jaeger.thriftjava.Tag)

Example 3 with Tag

use of com.uber.jaeger.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");
    Span span = tracer.buildSpan("operation-name").startManual();
    span = span.log(1, fields);
    span = span.setBaggageItem("foo", "bar");
    com.uber.jaeger.thriftjava.Span thriftSpan = JaegerThriftSpanConverter.convertSpan((com.uber.jaeger.Span) 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(com.uber.jaeger.thriftjava.Log) Tag(com.uber.jaeger.thriftjava.Tag) Span(io.opentracing.Span) Test(org.junit.Test)

Example 4 with Tag

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

the class JaegerThriftSpanConverterTest method testBuildTag.

@Test
@UseDataProvider("dataProviderBuildTag")
public void testBuildTag(Object tagValue, TagType tagType, Object expected) {
    Tag tag = JaegerThriftSpanConverter.buildTag("key", tagValue);
    assertEquals(tagType, tag.getVType());
    assertEquals("key", tag.getKey());
    switch(tagType) {
        case STRING:
        default:
            assertEquals(expected, tag.getVStr());
            break;
        case BOOL:
            assertEquals(expected, tag.isVBool());
            break;
        case LONG:
            assertEquals(expected, tag.getVLong());
            break;
        case DOUBLE:
            assertEquals(expected, tag.getVDouble());
            break;
        case BINARY:
            break;
    }
}
Also used : Tag(com.uber.jaeger.thriftjava.Tag) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

Tag (com.uber.jaeger.thriftjava.Tag)4 Log (com.uber.jaeger.thriftjava.Log)2 Test (org.junit.Test)2 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 LogData (com.uber.jaeger.LogData)1 Span (io.opentracing.Span)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1