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();
}
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);
}
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;
}
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);
}
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());
}
Aggregations