@UseDataProvider("idSanitizationScenarios") @Test public void convertWingtipsSpanToZipkinSpan_sanitizes_traceId_as_expected_when_sanitization_is_enabled( IdSanitizationScenario scenario ) { impl = new WingtipsToZipkinSpanConverterDefaultImpl(true); final Endpoint zipkinEndpoint = Endpoint.newBuilder().serviceName(UUID.randomUUID().toString()).build(); final Span wingtipsSpan = Span.newBuilder("foo", SpanPurpose.CLIENT) .withTraceId(scenario.originalId) .withSpanStartTimeEpochMicros(Math.abs(random.nextLong())) .withDurationNanos(Math.abs(random.nextLong())) .build(); String expectedZipkinInvalidIdTagValue = (scenario.expectedSanitizedResultForTraceId.equals(scenario.originalId)) ? null : scenario.originalId; String expectedWingtipsSanitizedIdTagValue = (scenario.expectedSanitizedResultForTraceId.equals(scenario.originalId)) ? null : scenario.expectedSanitizedResultForTraceId; zipkin2.Span zipkinSpan = impl.convertWingtipsSpanToZipkinSpan(wingtipsSpan, zipkinEndpoint); assertThat(zipkinSpan.traceId()).isEqualTo(scenario.expectedSanitizedResultForTraceId); assertThat(zipkinSpan.tags().get("invalid.trace_id")).isEqualTo(expectedZipkinInvalidIdTagValue); assertThat(wingtipsSpan.getTags().get("sanitized_trace_id")).isEqualTo(expectedWingtipsSanitizedIdTagValue); }
@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);  }