Search in sources :

Example 1 with EventData

use of io.opentelemetry.sdk.trace.data.EventData in project opentelemetry-java by open-telemetry.

the class AdapterTest method testJaegerLog.

@Test
void testJaegerLog() {
    // prepare
    EventData event = getTimedEvent();
    // test
    Log log = Adapter.toJaegerLog(event);
    // verify
    assertThat(log.getFieldsSize()).isEqualTo(2);
    assertThat(getValue(log.getFields(), Adapter.KEY_LOG_EVENT).getVStr()).isEqualTo("the log message");
    assertThat(getValue(log.getFields(), "foo").getVStr()).isEqualTo("bar");
    assertThat(getValue(log.getFields(), Adapter.KEY_EVENT_DROPPED_ATTRIBUTES_COUNT)).isNull();
}
Also used : Log(io.jaegertracing.thriftjava.Log) EventData(io.opentelemetry.sdk.trace.data.EventData) Test(org.junit.jupiter.api.Test)

Example 2 with EventData

use of io.opentelemetry.sdk.trace.data.EventData in project opentelemetry-java by open-telemetry.

the class AdapterTest method testJaegerLogs.

@Test
void testJaegerLogs() {
    // prepare
    EventData eventsData = getTimedEvent();
    // test
    Collection<Log> logs = Adapter.toJaegerLogs(Collections.singletonList(eventsData));
    // verify
    assertThat(logs).hasSize(1);
}
Also used : Log(io.jaegertracing.thriftjava.Log) EventData(io.opentelemetry.sdk.trace.data.EventData) Test(org.junit.jupiter.api.Test)

Example 3 with EventData

use of io.opentelemetry.sdk.trace.data.EventData in project opentelemetry-java by open-telemetry.

the class TracezZPageHandler method emitSingleSpan.

private static boolean emitSingleSpan(PrintStream out, Formatter formatter, SpanData span, boolean zebraStripe) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(TimeUnit.NANOSECONDS.toMillis(span.getStartEpochNanos()));
    long microsField = TimeUnit.NANOSECONDS.toMicros(span.getStartEpochNanos());
    String elapsedSecondsStr = span.hasEnded() ? String.format("%.6f", (span.getEndEpochNanos() - span.getStartEpochNanos()) * 1.0e-9) : "";
    formatter.format("<tr style=\"background-color: %s;\">", zebraStripe ? ZEBRA_STRIPE_COLOR : "#fff");
    formatter.format("<td class=\"align-right\"><pre class=\"no-margin wrap-text\"><b>" + "%04d/%02d/%02d-%02d:%02d:%02d.%06d</b></pre></td>", calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, calendar.get(Calendar.DAY_OF_MONTH), calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE), calendar.get(Calendar.SECOND), microsField);
    formatter.format("<td class=\"border-left-dark\"><pre class=\"no-margin wrap-text\"><b>%s</b></pre></td>", elapsedSecondsStr);
    formatter.format("<td class=\"border-left-dark\"><pre class=\"no-margin wrap-text\"><b>" + "TraceId: <b style=\"color:%s;\">%s</b> " + " | SpanId: %s | ParentSpanId: %s</b></pre></td>", span.getSpanContext().isSampled() ? SAMPLED_TRACE_ID_COLOR : NOT_SAMPLED_TRACE_ID_COLOR, span.getTraceId(), span.getSpanId(), span.getParentSpanId());
    out.print("</tr>");
    zebraStripe = !zebraStripe;
    int lastEntryDayOfYear = calendar.get(Calendar.DAY_OF_YEAR);
    long lastEpochNanos = span.getStartEpochNanos();
    List<EventData> timedEvents = span.getEvents().stream().sorted(Comparator.comparingLong(EventData::getEpochNanos)).collect(Collectors.toList());
    for (EventData event : timedEvents) {
        calendar.setTimeInMillis(TimeUnit.NANOSECONDS.toMillis(event.getEpochNanos()));
        formatter.format("<tr style=\"background-color: %s;\">", zebraStripe ? ZEBRA_STRIPE_COLOR : "#fff");
        emitSingleEvent(out, formatter, event, calendar, lastEntryDayOfYear, lastEpochNanos);
        out.print("</tr>");
        if (calendar.get(Calendar.DAY_OF_YEAR) != lastEntryDayOfYear) {
            lastEntryDayOfYear = calendar.get(Calendar.DAY_OF_YEAR);
        }
        lastEpochNanos = event.getEpochNanos();
        zebraStripe = !zebraStripe;
    }
    formatter.format("<tr style=\"background-color: %s;\"><td></td><td class=\"border-left-dark\">" + "</td><td class=\"border-left-dark\"><pre class=\"no-margin wrap-text\">", zebraStripe ? ZEBRA_STRIPE_COLOR : "#fff");
    StatusData status = span.getStatus();
    if (status != null) {
        formatter.format("%s | ", escapeHtml(status.toString()));
    }
    formatter.format("%s</pre></td>", escapeHtml(renderAttributes(span.getAttributes())));
    zebraStripe = !zebraStripe;
    return zebraStripe;
}
Also used : Calendar(java.util.Calendar) EventData(io.opentelemetry.sdk.trace.data.EventData) StatusData(io.opentelemetry.sdk.trace.data.StatusData)

Example 4 with EventData

use of io.opentelemetry.sdk.trace.data.EventData in project opentelemetry-java by open-telemetry.

the class TestSpanDataTest method timedEvent_canSetTotalAttributeCount.

@Test
void timedEvent_canSetTotalAttributeCount() {
    EventData event = EventData.create(START_EPOCH_NANOS, "foo", Attributes.empty(), 123);
    assertThat(event.getTotalAttributeCount()).isEqualTo(123);
}
Also used : EventData(io.opentelemetry.sdk.trace.data.EventData) Test(org.junit.jupiter.api.Test)

Example 5 with EventData

use of io.opentelemetry.sdk.trace.data.EventData in project opentelemetry-java by open-telemetry.

the class SdkSpanTest method recordException_additionalAttributes.

@Test
void recordException_additionalAttributes() {
    IllegalStateException exception = new IllegalStateException("there was an exception");
    SdkSpan span = createTestRootSpan();
    StringWriter writer = new StringWriter();
    exception.printStackTrace(new PrintWriter(writer));
    String stacktrace = writer.toString();
    testClock.advance(Duration.ofNanos(1000));
    long timestamp = testClock.now();
    span.recordException(exception, Attributes.of(stringKey("key1"), "this is an additional attribute", stringKey("exception.message"), "this is a precedence attribute"));
    List<EventData> events = span.toSpanData().getEvents();
    assertThat(events).hasSize(1);
    EventData event = events.get(0);
    assertThat(event.getName()).isEqualTo("exception");
    assertThat(event.getEpochNanos()).isEqualTo(timestamp);
    assertThat(event.getAttributes()).isEqualTo(Attributes.builder().put("key1", "this is an additional attribute").put("exception.type", "java.lang.IllegalStateException").put("exception.message", "this is a precedence attribute").put("exception.stacktrace", stacktrace).build());
}
Also used : StringWriter(java.io.StringWriter) EventData(io.opentelemetry.sdk.trace.data.EventData) PrintWriter(java.io.PrintWriter) Test(org.junit.jupiter.api.Test)

Aggregations

EventData (io.opentelemetry.sdk.trace.data.EventData)24 Test (org.junit.jupiter.api.Test)18 SpanData (io.opentelemetry.sdk.trace.data.SpanData)7 Log (io.jaegertracing.thriftjava.Log)3 Attributes (io.opentelemetry.api.common.Attributes)2 StatusData (io.opentelemetry.sdk.trace.data.StatusData)2 PrintWriter (java.io.PrintWriter)2 StringWriter (java.io.StringWriter)2 HashMap (java.util.HashMap)2 AttributeKey (io.opentelemetry.api.common.AttributeKey)1 Span (io.opentelemetry.api.trace.Span)1 SpanContext (io.opentelemetry.api.trace.SpanContext)1 SpanKind (io.opentelemetry.api.trace.SpanKind)1 Scope (io.opentelemetry.context.Scope)1 Model (io.opentelemetry.exporter.jaeger.proto.api_v2.Model)1 InstrumentationLibraryInfo (io.opentelemetry.sdk.common.InstrumentationLibraryInfo)1 Resource (io.opentelemetry.sdk.resources.Resource)1 TestClock (io.opentelemetry.sdk.testing.time.TestClock)1 ReadableSpan (io.opentelemetry.sdk.trace.ReadableSpan)1 LinkData (io.opentelemetry.sdk.trace.data.LinkData)1