use of io.opentelemetry.sdk.trace.data.StatusData 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.StatusData in project opentelemetry-java by open-telemetry.
the class TracezSpanBuckets method addToBucket.
void addToBucket(ReadableSpan span) {
StatusData status = span.toSpanData().getStatus();
if (status.getStatusCode() != StatusCode.ERROR) {
latencyBuckets.get(LatencyBoundary.getBoundary(span.getLatencyNanos())).add(span);
return;
}
errors.add(span);
}
use of io.opentelemetry.sdk.trace.data.StatusData in project opentelemetry-java by open-telemetry.
the class ZipkinSpanExporter method generateSpan.
Span generateSpan(SpanData spanData) {
Endpoint endpoint = getEndpoint(spanData);
long startTimestamp = toEpochMicros(spanData.getStartEpochNanos());
long endTimestamp = toEpochMicros(spanData.getEndEpochNanos());
Span.Builder spanBuilder = Span.newBuilder().traceId(spanData.getTraceId()).id(spanData.getSpanId()).kind(toSpanKind(spanData)).name(spanData.getName()).timestamp(toEpochMicros(spanData.getStartEpochNanos())).duration(Math.max(1, endTimestamp - startTimestamp)).localEndpoint(endpoint);
if (spanData.getParentSpanContext().isValid()) {
spanBuilder.parentId(spanData.getParentSpanId());
}
Attributes spanAttributes = spanData.getAttributes();
spanAttributes.forEach((key, value) -> spanBuilder.putTag(key.getKey(), valueToString(key, value)));
int droppedAttributes = spanData.getTotalAttributeCount() - spanAttributes.size();
if (droppedAttributes > 0) {
spanBuilder.putTag(OTEL_DROPPED_ATTRIBUTES_COUNT, String.valueOf(droppedAttributes));
}
StatusData status = spanData.getStatus();
// include status code & error.
if (status.getStatusCode() != StatusCode.UNSET) {
spanBuilder.putTag(OTEL_STATUS_CODE, status.getStatusCode().toString());
// add the error tag, if it isn't already in the source span.
if (status.getStatusCode() == StatusCode.ERROR && spanAttributes.get(STATUS_ERROR) == null) {
spanBuilder.putTag(STATUS_ERROR.getKey(), nullToEmpty(status.getDescription()));
}
}
InstrumentationLibraryInfo instrumentationLibraryInfo = spanData.getInstrumentationLibraryInfo();
if (!instrumentationLibraryInfo.getName().isEmpty()) {
spanBuilder.putTag(KEY_INSTRUMENTATION_LIBRARY_NAME, instrumentationLibraryInfo.getName());
}
if (instrumentationLibraryInfo.getVersion() != null) {
spanBuilder.putTag(KEY_INSTRUMENTATION_LIBRARY_VERSION, instrumentationLibraryInfo.getVersion());
}
for (EventData annotation : spanData.getEvents()) {
spanBuilder.addAnnotation(toEpochMicros(annotation.getEpochNanos()), annotation.getName());
}
int droppedEvents = spanData.getTotalRecordedEvents() - spanData.getEvents().size();
if (droppedEvents > 0) {
spanBuilder.putTag(OTEL_DROPPED_EVENTS_COUNT, String.valueOf(droppedEvents));
}
return spanBuilder.build();
}
Aggregations