@DataProvider(value = { " \t\n\r ", "" }, splitBy = "\\|") @Test @SuppressWarnings("UnnecessaryLocalVariable") public void convertWingtipsSpanToZipkinSpan_throws_IllegalArgumentException_when_passed_wingtipsSpan_with_empty_traceId_format( final String emptyString ) { String emptyTraceId = emptyString; long startTimeEpochMicros = Math.abs(random.nextLong()); long durationNanos = Math.abs(random.nextLong()); final Endpoint zipkinEndpoint = Endpoint.newBuilder().serviceName(UUID.randomUUID().toString()).build(); final Span wingtipsSpan = Span.newBuilder("foo", SpanPurpose.CLIENT) .withTraceId(emptyTraceId) .withSpanStartTimeEpochMicros(startTimeEpochMicros) .withDurationNanos(durationNanos) .build(); Throwable ex = catchThrowable(() -> impl.convertWingtipsSpanToZipkinSpan(wingtipsSpan, zipkinEndpoint)); assertThat(ex) .isInstanceOf(IllegalArgumentException.class) .hasMessage("traceId is empty"); }
@Override public zipkin2.Span convertWingtipsSpanToZipkinSpan(Span wingtipsSpan, Endpoint zipkinEndpoint) { long durationMicros = TimeUnit.NANOSECONDS.toMicros(wingtipsSpan.getDurationNanos()); String spanId = sanitizeIdIfNecessary(wingtipsSpan.getSpanId(), false); String traceId = sanitizeIdIfNecessary(wingtipsSpan.getTraceId(), true); String parentId = sanitizeIdIfNecessary(wingtipsSpan.getParentSpanId(), false); final zipkin2.Span.Builder spanBuilder = zipkin2.Span .newBuilder() .id(spanId) .name(wingtipsSpan.getSpanName()) .parentId(parentId) .traceId(traceId) .timestamp(wingtipsSpan.getSpanStartTimeEpochMicros()) .duration(durationMicros) .localEndpoint(zipkinEndpoint) .kind(determineZipkinKind(wingtipsSpan)); for (Map.Entry<String, String> tagEntry : wingtipsSpan.getTags().entrySet()) { spanBuilder.putTag(tagEntry.getKey(), tagEntry.getValue()); } if (!spanId.equals(wingtipsSpan.getSpanId())) { spanBuilder.putTag("invalid.span_id", wingtipsSpan.getSpanId()); wingtipsSpan.putTag("sanitized_span_id", spanId); } if (!traceId.equals(wingtipsSpan.getTraceId())) { spanBuilder.putTag("invalid.trace_id", wingtipsSpan.getTraceId()); wingtipsSpan.putTag("sanitized_trace_id", traceId); } if (parentId != null && !parentId.equals(wingtipsSpan.getParentSpanId())) { spanBuilder.putTag("invalid.parent_id", wingtipsSpan.getParentSpanId()); wingtipsSpan.putTag("sanitized_parent_id", parentId); } for (TimestampedAnnotation wingtipsAnnotation : wingtipsSpan.getTimestampedAnnotations()) { spanBuilder.addAnnotation(wingtipsAnnotation.getTimestampEpochMicros(), wingtipsAnnotation.getValue()); } return spanBuilder.build(); }
WingtipsToZipkinSpanConverterDefaultImpl implements WingtipsToZipkinSpanConverter { @Override public zipkin2.Span convertWingtipsSpanToZipkinSpan(Span wingtipsSpan, Endpoint zipkinEndpoint) { long durationMicros = TimeUnit.NANOSECONDS.toMicros(wingtipsSpan.getDurationNanos()); String spanId = sanitizeIdIfNecessary(wingtipsSpan.getSpanId(), false); String traceId = sanitizeIdIfNecessary(wingtipsSpan.getTraceId(), true); String parentId = sanitizeIdIfNecessary(wingtipsSpan.getParentSpanId(), false); final zipkin2.Span.Builder spanBuilder = zipkin2.Span .newBuilder() .id(spanId) .name(wingtipsSpan.getSpanName()) .parentId(parentId) .traceId(traceId) .timestamp(wingtipsSpan.getSpanStartTimeEpochMicros()) .duration(durationMicros) .localEndpoint(zipkinEndpoint) .kind(determineZipkinKind(wingtipsSpan)); for (Map.Entry<String, String> tagEntry : wingtipsSpan.getTags().entrySet()) { spanBuilder.putTag(tagEntry.getKey(), tagEntry.getValue()); } if (!spanId.equals(wingtipsSpan.getSpanId())) { spanBuilder.putTag("invalid.span_id", wingtipsSpan.getSpanId()); wingtipsSpan.putTag("sanitized_span_id", spanId); } if (!traceId.equals(wingtipsSpan.getTraceId())) { spanBuilder.putTag("invalid.trace_id", wingtipsSpan.getTraceId()); wingtipsSpan.putTag("sanitized_trace_id", traceId); } if (parentId != null && !parentId.equals(wingtipsSpan.getParentSpanId())) { spanBuilder.putTag("invalid.parent_id", wingtipsSpan.getParentSpanId()); wingtipsSpan.putTag("sanitized_parent_id", parentId); } for (TimestampedAnnotation wingtipsAnnotation : wingtipsSpan.getTimestampedAnnotations()) { spanBuilder.addAnnotation(wingtipsAnnotation.getTimestampEpochMicros(), wingtipsAnnotation.getValue()); } return spanBuilder.build(); } }
WingtipsToZipkinSpanConverterDefaultImpl implements WingtipsToZipkinSpanConverter { @Override public zipkin2.Span convertWingtipsSpanToZipkinSpan(Span wingtipsSpan, Endpoint zipkinEndpoint) { long durationMicros = TimeUnit.NANOSECONDS.toMicros(wingtipsSpan.getDurationNanos()); String spanId = sanitizeIdIfNecessary(wingtipsSpan.getSpanId(), false); String traceId = sanitizeIdIfNecessary(wingtipsSpan.getTraceId(), true); String parentId = sanitizeIdIfNecessary(wingtipsSpan.getParentSpanId(), false); final zipkin2.Span.Builder spanBuilder = zipkin2.Span .newBuilder() .id(spanId) .name(wingtipsSpan.getSpanName()) .parentId(parentId) .traceId(traceId) .timestamp(wingtipsSpan.getSpanStartTimeEpochMicros()) .duration(durationMicros) .localEndpoint(zipkinEndpoint) .kind(determineZipkinKind(wingtipsSpan)); for (Map.Entry<String, String> tagEntry : wingtipsSpan.getTags().entrySet()) { spanBuilder.putTag(tagEntry.getKey(), tagEntry.getValue()); } if (!spanId.equals(wingtipsSpan.getSpanId())) { spanBuilder.putTag("invalid.span_id", wingtipsSpan.getSpanId()); wingtipsSpan.putTag("sanitized_span_id", spanId); } if (!traceId.equals(wingtipsSpan.getTraceId())) { spanBuilder.putTag("invalid.trace_id", wingtipsSpan.getTraceId()); wingtipsSpan.putTag("sanitized_trace_id", traceId); } if (parentId != null && !parentId.equals(wingtipsSpan.getParentSpanId())) { spanBuilder.putTag("invalid.parent_id", wingtipsSpan.getParentSpanId()); wingtipsSpan.putTag("sanitized_parent_id", parentId); } for (TimestampedAnnotation wingtipsAnnotation : wingtipsSpan.getTimestampedAnnotations()) { spanBuilder.addAnnotation(wingtipsAnnotation.getTimestampEpochMicros(), wingtipsAnnotation.getValue()); } return spanBuilder.build(); } WingtipsToZipkinSpanConverterDefaultImpl();  WingtipsToZipkinSpanConverterDefaultImpl(boolean enableIdSanitization); }
WingtipsToZipkinSpanConverterDefaultImpl implements WingtipsToZipkinSpanConverter { @Override public zipkin2.Span convertWingtipsSpanToZipkinSpan(Span wingtipsSpan, Endpoint zipkinEndpoint) { long durationMicros = TimeUnit.NANOSECONDS.toMicros(wingtipsSpan.getDurationNanos()); String spanId = sanitizeIdIfNecessary(wingtipsSpan.getSpanId(), false); String traceId = sanitizeIdIfNecessary(wingtipsSpan.getTraceId(), true); String parentId = sanitizeIdIfNecessary(wingtipsSpan.getParentSpanId(), false); final zipkin2.Span.Builder spanBuilder = zipkin2.Span .newBuilder() .id(spanId) .name(wingtipsSpan.getSpanName()) .parentId(parentId) .traceId(traceId) .timestamp(wingtipsSpan.getSpanStartTimeEpochMicros()) .duration(durationMicros) .localEndpoint(zipkinEndpoint) .kind(determineZipkinKind(wingtipsSpan)); for (Map.Entry<String, String> tagEntry : wingtipsSpan.getTags().entrySet()) { spanBuilder.putTag(tagEntry.getKey(), tagEntry.getValue()); } if (!spanId.equals(wingtipsSpan.getSpanId())) { spanBuilder.putTag("invalid.span_id", wingtipsSpan.getSpanId()); wingtipsSpan.putTag("sanitized_span_id", spanId); } if (!traceId.equals(wingtipsSpan.getTraceId())) { spanBuilder.putTag("invalid.trace_id", wingtipsSpan.getTraceId()); wingtipsSpan.putTag("sanitized_trace_id", traceId); } if (parentId != null && !parentId.equals(wingtipsSpan.getParentSpanId())) { spanBuilder.putTag("invalid.parent_id", wingtipsSpan.getParentSpanId()); wingtipsSpan.putTag("sanitized_parent_id", parentId); } for (TimestampedAnnotation wingtipsAnnotation : wingtipsSpan.getTimestampedAnnotations()) { spanBuilder.addAnnotation(wingtipsAnnotation.getTimestampEpochMicros(), wingtipsAnnotation.getValue()); } return spanBuilder.build(); } WingtipsToZipkinSpanConverterDefaultImpl();  WingtipsToZipkinSpanConverterDefaultImpl(boolean enableIdSanitization); @Override zipkin2.Span convertWingtipsSpanToZipkinSpan(Span wingtipsSpan, Endpoint zipkinEndpoint); }
WingtipsToZipkinSpanConverterDefaultImpl implements WingtipsToZipkinSpanConverter { @Override public zipkin2.Span convertWingtipsSpanToZipkinSpan(Span wingtipsSpan, Endpoint zipkinEndpoint) { long durationMicros = TimeUnit.NANOSECONDS.toMicros(wingtipsSpan.getDurationNanos()); String spanId = sanitizeIdIfNecessary(wingtipsSpan.getSpanId(), false); String traceId = sanitizeIdIfNecessary(wingtipsSpan.getTraceId(), true); String parentId = sanitizeIdIfNecessary(wingtipsSpan.getParentSpanId(), false); final zipkin2.Span.Builder spanBuilder = zipkin2.Span .newBuilder() .id(spanId) .name(wingtipsSpan.getSpanName()) .parentId(parentId) .traceId(traceId) .timestamp(wingtipsSpan.getSpanStartTimeEpochMicros()) .duration(durationMicros) .localEndpoint(zipkinEndpoint) .kind(determineZipkinKind(wingtipsSpan)); for (Map.Entry<String, String> tagEntry : wingtipsSpan.getTags().entrySet()) { spanBuilder.putTag(tagEntry.getKey(), tagEntry.getValue()); } if (!spanId.equals(wingtipsSpan.getSpanId())) { spanBuilder.putTag("invalid.span_id", wingtipsSpan.getSpanId()); wingtipsSpan.putTag("sanitized_span_id", spanId); } if (!traceId.equals(wingtipsSpan.getTraceId())) { spanBuilder.putTag("invalid.trace_id", wingtipsSpan.getTraceId()); wingtipsSpan.putTag("sanitized_trace_id", traceId); } if (parentId != null && !parentId.equals(wingtipsSpan.getParentSpanId())) { spanBuilder.putTag("invalid.parent_id", wingtipsSpan.getParentSpanId()); wingtipsSpan.putTag("sanitized_parent_id", parentId); } for (TimestampedAnnotation wingtipsAnnotation : wingtipsSpan.getTimestampedAnnotations()) { spanBuilder.addAnnotation(wingtipsAnnotation.getTimestampEpochMicros(), wingtipsAnnotation.getValue()); } return spanBuilder.build(); } WingtipsToZipkinSpanConverterDefaultImpl();  WingtipsToZipkinSpanConverterDefaultImpl(boolean enableIdSanitization); @Override zipkin2.Span convertWingtipsSpanToZipkinSpan(Span wingtipsSpan, Endpoint zipkinEndpoint);  }