本文整理了Java中com.nike.wingtips.Span.<init>()
方法的一些代码示例,展示了Span.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Span.<init>()
方法的具体详情如下:
包路径:com.nike.wingtips.Span
类名称:Span
方法名:<init>
[英]The full constructor allowing you to set all fields representing a span's state. The traceId, spanId, and spanName fields cannot be null (an IllegalArgumentException will be thrown if any are null). This method is public to allow full flexibility, however in practice you should use one of the provided #generateRootSpanForNewTrace(String,SpanPurpose) or #generateChildSpan(String,SpanPurpose) helper methods, or the Builder if you need more flexibility than the helper methods. If you pass in null for spanPurpose then SpanPurpose#UNKNOWNwill be used.
WARNING: When deserializing a span that was initially started on a different JVM, you must pass in null for spanStartTimeNanos. Otherwise timing will be completely broken since System#nanoTime() is not comparable across JVMs.
[中]完整的构造函数,允许您设置表示跨度状态的所有字段。traceId、spanId和spanName字段不能为null(如果任何字段为null,将引发IllegalArgumentException)。此方法是公开的,以允许完全的灵活性,但是在实践中,您应该使用提供的#generateRootSpanForNewTrace(String,SpanPurpose)或#generateChildSpan(String,SpanPurpose)辅助方法之一,或者如果您需要比辅助方法更大的灵活性,可以使用生成器。如果您为spanPurpose输入null,则将使用spanPurpose#Unknown。
警告:当反序列化最初在不同JVM上启动的跨距时,您必须为spanStartTimeNanos传递null。否则,计时将完全中断,因为系统#nanoTime()在JVM之间是不可比的。
代码示例来源:origin: Nike-Inc/wingtips
private Span createFilledOutSpan(
boolean completed,
Map<String, String> tags,
List<TimestampedAnnotation> annotations
) {
Long durationNanos = (completed) ? durationNanosForFullyCompletedSpan : null;
return new Span(
traceId, parentSpanId, spanId, spanName, sampleableForFullyCompleteSpan, userId,
spanPurposeForFullyCompletedSpan, startTimeEpochMicrosForFullyCompleteSpan,
startTimeNanosForFullyCompleteSpan, durationNanos, tags, annotations
);
}
代码示例来源:origin: Nike-Inc/wingtips
private Span createFilledOutSpan(boolean completed) {
Long durationNanos = (completed) ? durationNanosForFullyCompletedSpan : null;
return new Span(traceId, parentSpanId, spanId, spanName, sampleableForFullyCompleteSpan, userId,
spanPurposeForFullyCompletedSpan, startTimeEpochMicrosForFullyCompleteSpan,
startTimeNanosForFullyCompleteSpan, durationNanos, tags, annotations
);
}
代码示例来源:origin: Nike-Inc/wingtips
return new Span(
traceId, parentSpanId, spanId, spanName, sampleable, userId, spanPurpose, spanStartTimeEpochMicros,
spanStartTimeNanos, durationNanos, tags, annotations
代码示例来源:origin: Nike-Inc/wingtips
@Test(expected = IllegalArgumentException.class)
public void public_constructor_throws_IllegalArgumentException_if_passed_null_span_id() {
// expect
new Span(traceId, parentSpanId, null, spanName, true, userId, spanPurpose, 42, null, null, null, null);
}
代码示例来源:origin: Nike-Inc/wingtips
@Test(expected = IllegalArgumentException.class)
public void public_constructor_throws_IllegalArgumentException_if_passed_null_span_name() {
// expect
new Span(traceId, parentSpanId, spanId, null, true, userId, spanPurpose, 42, null, null, null, null);
}
代码示例来源:origin: Nike-Inc/wingtips
@Test(expected = IllegalArgumentException.class)
public void public_constructor_throws_IllegalArgumentException_if_passed_null_trace_id() {
// expect
new Span(null, parentSpanId, spanId, spanName, true, userId, spanPurpose, 42, null, null, null, null);
}
代码示例来源:origin: Nike-Inc/wingtips
@Test
public void protected_constructor_generates_instance_with_placeholder_values() {
// given
String placeholderValue = "PLACEHOLDER";
// when
Span result = new Span();
// then
verifySpanDeepEquals(
result,
new Span(
placeholderValue, null, placeholderValue, placeholderValue, false, null, SpanPurpose.UNKNOWN, -1, -1L,
-1L, null, null
),
false
);
}
代码示例来源:origin: Nike-Inc/wingtips
@Test
public void public_constructor_defaults_to_UNKNOWN_span_purpose_if_passed_null() {
// when
Span span = new Span(traceId, parentSpanId, spanId, spanName, true, userId, null, 42, null, null, null, null);
// then
assertThat(span.getSpanPurpose()).isEqualTo(SpanPurpose.UNKNOWN);
}
代码示例来源:origin: Nike-Inc/wingtips
@Test
public void public_constructor_calculates_start_time_nanos_if_passed_null() {
// given
long startTimeEpochMicrosUsed = 42;
long nanosBeforeCall = System.nanoTime();
long epochMicrosBeforeCall = TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis());
// when
Span span = new Span(traceId, parentSpanId, spanId, spanName, true, userId, spanPurpose, startTimeEpochMicrosUsed, null, 41L, null, null);
long epochMicrosAfterCall = TimeUnit.MILLISECONDS.toMicros(System.currentTimeMillis());
long nanosAfterCall = System.nanoTime();
// then
long lowerBound = calculateNanoStartTimeFromSpecifiedEpochMicrosStartTime(startTimeEpochMicrosUsed, epochMicrosBeforeCall, nanosBeforeCall);
long upperBound = calculateNanoStartTimeFromSpecifiedEpochMicrosStartTime(startTimeEpochMicrosUsed, epochMicrosAfterCall, nanosAfterCall);
assertThat(span.getSpanStartTimeNanos()).isBetween(lowerBound, upperBound);
}
代码示例来源:origin: Nike-Inc/wingtips
@Test
public void convertWingtipsSpanToZipkinSpan_works_as_expected_for_128_bit_trace_id() {
// given
String high64Bits = "463ac35c9f6413ad";
String low64Bits = "48485a3953bb6124";
String hex128Bits = high64Bits + low64Bits;
String spanName = UUID.randomUUID().toString();
String traceId = hex128Bits;
String spanId = low64Bits;
long startTimeEpochMicros = Math.abs(random.nextLong());
long durationNanos = Math.abs(random.nextLong());
Endpoint zipkinEndpoint = Endpoint.create(UUID.randomUUID().toString(), 42);
String localComponentNamespace = UUID.randomUUID().toString();
Map<String,String> tags = createSingleTagMap();
List<TimestampedAnnotation> annotations = createSingleTimestampedAnnotationList();
Span wingtipsSpan = new Span(
traceId, null, spanId, spanName, true, null, Span.SpanPurpose.CLIENT, startTimeEpochMicros, null,
durationNanos, tags, annotations
);
// when
zipkin.Span zipkinSpan = impl.convertWingtipsSpanToZipkinSpan(wingtipsSpan, zipkinEndpoint, localComponentNamespace);
// then
assertThat(zipkinSpan.traceIdHigh).isEqualTo(unsignedLowerHexStringToLong(high64Bits));
assertThat(zipkinSpan.traceId).isEqualTo(unsignedLowerHexStringToLong(low64Bits));
}
代码示例来源:origin: Nike-Inc/wingtips
@Test
public void public_constructor_uses_empty_annotations_list_when_annotations_argument_is_null() {
// when
Span span = new Span(traceId, parentSpanId, spanId, spanName, true, userId, null, 42, null, null, null, null);
// then
assertThat(span.getTimestampedAnnotations())
.isNotNull()
.isEmpty();
}
代码示例来源:origin: Nike-Inc/wingtips
Map<String,String> tags = createSingleTagMap();
List<TimestampedAnnotation> annotations = createSingleTimestampedAnnotationList();
final Span wingtipsSpan = new Span(
traceId, null, spanId, spanName, true, null, Span.SpanPurpose.CLIENT, startTimeEpochMicros, null,
durationNanos, tags, annotations
代码示例来源:origin: Nike-Inc/wingtips
@Test
public void public_constructor_uses_empty_tags_map_when_tags_argument_is_null() {
// when
Span span = new Span(traceId, parentSpanId, spanId, spanName, true, userId, null, 42, null, null, null, null);
// then
assertThat(span.getTags())
.isNotNull()
.isEmpty();
}
代码示例来源:origin: Nike-Inc/wingtips
@Test
public void public_constructor_works_as_expected_for_completed_span() {
// when
Span span = new Span(
traceId, parentSpanId, spanId, spanName, sampleableForFullyCompleteSpan, userId,
spanPurposeForFullyCompletedSpan, startTimeEpochMicrosForFullyCompleteSpan,
startTimeNanosForFullyCompleteSpan, durationNanosForFullyCompletedSpan, tags, annotations
);
// then
assertThat(span.getTraceId()).isEqualTo(traceId);
assertThat(span.getParentSpanId()).isEqualTo(parentSpanId);
assertThat(span.getSpanId()).isEqualTo(spanId);
assertThat(span.getSpanName()).isEqualTo(spanName);
assertThat(span.isSampleable()).isEqualTo(sampleableForFullyCompleteSpan);
assertThat(span.getUserId()).isEqualTo(userId);
assertThat(span.getSpanStartTimeEpochMicros()).isEqualTo(startTimeEpochMicrosForFullyCompleteSpan);
assertThat(span.getSpanStartTimeNanos()).isEqualTo(startTimeNanosForFullyCompleteSpan);
assertThat(span.getSpanPurpose()).isEqualTo(spanPurposeForFullyCompletedSpan);
assertThat(span.isCompleted()).isTrue();
assertThat(span.getDurationNanos()).isEqualTo(durationNanosForFullyCompletedSpan);
assertThat(span.getTags()).isEqualTo(tags);
assertThat(span.getTimestampedAnnotations()).isEqualTo(annotations);
}
代码示例来源:origin: Nike-Inc/wingtips
protected static Span fromKeyValueMap(
Map<String, String> map,
Map<String, String> tags,
List<TimestampedAnnotation> annotations
) {
// Use the map to get the field values for the span.
String traceId = nullSafeGetString(map, TRACE_ID_FIELD);
String spanId = nullSafeGetString(map, SPAN_ID_FIELD);
String parentSpanId = nullSafeGetString(map, PARENT_SPAN_ID_FIELD);
String spanName = nullSafeGetString(map, SPAN_NAME_FIELD);
Boolean sampleable = nullSafeGetBoolean(map, SAMPLEABLE_FIELD);
if (sampleable == null) {
throw new IllegalStateException("Unable to parse " + SAMPLEABLE_FIELD + " from serialized Span");
}
String userId = nullSafeGetString(map, USER_ID_FIELD);
Long startTimeEpochMicros = nullSafeGetLong(map, START_TIME_EPOCH_MICROS_FIELD);
if (startTimeEpochMicros == null) {
throw new IllegalStateException(
"Unable to parse " + START_TIME_EPOCH_MICROS_FIELD + " from serialized Span"
);
}
Long durationNanos = nullSafeGetLong(map, DURATION_NANOS_FIELD);
SpanPurpose spanPurpose = nullSafeGetSpanPurpose(map, SPAN_PURPOSE_FIELD);
return new Span(
traceId, parentSpanId, spanId, spanName, sampleable, userId, spanPurpose, startTimeEpochMicros,
null, durationNanos, tags, annotations
);
}
代码示例来源:origin: Nike-Inc/wingtips
@Test
public void public_constructor_works_as_expected_for_incomplete_span() {
// when
Span span = new Span(
traceId, parentSpanId, spanId, spanName, sampleableForFullyCompleteSpan, userId,
spanPurposeForFullyCompletedSpan, startTimeEpochMicrosForFullyCompleteSpan,
startTimeNanosForFullyCompleteSpan, null, tags, annotations
);
// then
assertThat(span.getTraceId()).isEqualTo(traceId);
assertThat(span.getParentSpanId()).isEqualTo(parentSpanId);
assertThat(span.getSpanId()).isEqualTo(spanId);
assertThat(span.getSpanName()).isEqualTo(spanName);
assertThat(span.isSampleable()).isEqualTo(sampleableForFullyCompleteSpan);
assertThat(span.getUserId()).isEqualTo(userId);
assertThat(span.getSpanStartTimeEpochMicros()).isEqualTo(startTimeEpochMicrosForFullyCompleteSpan);
assertThat(span.getSpanStartTimeNanos()).isEqualTo(startTimeNanosForFullyCompleteSpan);
assertThat(span.getSpanPurpose()).isEqualTo(spanPurposeForFullyCompletedSpan);
assertThat(span.isCompleted()).isFalse();
assertThat(span.getDurationNanos()).isNull();
assertThat(span.getTags()).isEqualTo(tags);
assertThat(span.getTimestampedAnnotations()).isEqualTo(annotations);
}
代码示例来源:origin: Nike-Inc/wingtips
long durationMicros = TimeUnit.NANOSECONDS.toMicros(durationNanos);
String localComponentNamespace = UUID.randomUUID().toString();
Span wingtipsSpan = new Span(
traceId, null, spanId, spanName, true, null, spanPurpose, startTimeEpochMicros, null, durationNanos, null,
null
代码示例来源:origin: Nike-Inc/wingtips
Map<String,String> tags = createMultipleTagMap();
List<TimestampedAnnotation> annotations = createMultipleTimestampedAnnotationList();
Span wingtipsSpan = new Span(
traceId, parentId, spanId, spanName, true, null, spanPurpose, startTimeEpochMicros, null, durationNanos,
tags, annotations
代码示例来源:origin: Nike-Inc/wingtips
long durationMicros = TimeUnit.NANOSECONDS.toMicros(durationNanos);
Endpoint zipkinEndpoint = Endpoint.newBuilder().serviceName(UUID.randomUUID().toString()).build();
Span wingtipsSpan = new Span(
traceId, null, spanId, spanName, true, null, spanPurpose, startTimeEpochMicros, null, durationNanos, null,
null
代码示例来源:origin: Nike-Inc/wingtips
Map<String, String> tags = createMultipleTagMap();
List<TimestampedAnnotation> annotations = createMultipleTimestampedAnnotationList();
Span wingtipsSpan = new Span(
traceId, parentId, spanId, spanName, true, null, spanPurpose, startTimeEpochMicros, null, durationNanos,
tags, annotations
内容来源于网络,如有侵权,请联系作者删除!