zipkin2.Span.timestamp()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(6.4k)|赞(0)|评价(0)|浏览(190)

本文整理了Java中zipkin2.Span.timestamp()方法的一些代码示例,展示了Span.timestamp()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Span.timestamp()方法的具体详情如下:
包路径:zipkin2.Span
类名称:Span
方法名:timestamp

Span.timestamp介绍

[英]Epoch microseconds of the start of this span, possibly absent if this an incomplete span.

This value should be set directly by instrumentation, using the most precise value possible. For example, gettimeofday or multiplying System#currentTimeMillis by 1000.

There are three known edge-cases where this could be reported absent:

A span was allocated but never started (ex not yet received a timestamp) 
 The span's start event was lost 
 Data about a completed span (ex tags) were sent after the fact

Note: timestamps at or before epoch (0L == 1970) are invalid
[中]此跨度开始的历元微秒,如果这是一个不完整的跨度,则可能不存在。
该值应由仪器直接设置,使用尽可能精确的值。例如,gettimeofday或将系统#currentTimeMillis乘以1000。
有三种已知的边缘情况可以不报告:

A span was allocated but never started (ex not yet received a timestamp) 
 The span's start event was lost 
 Data about a completed span (ex tags) were sent after the fact

注:历元(0L==1970)时或之前的时间戳无效

代码示例

代码示例来源:origin: openzipkin/brave

/**
 * This ensures thread-state is propagated from trace interceptors to user code. The endpoint
 * "/child" is expected to create an in-process span. When this works, it should be a child of the
 * "current span", in this case the span representing an incoming server request. When thread
 * state isn't managed properly, the child span will appear as a new trace.
 */
@Test
public void createsChildSpan() throws Exception {
 get("/child");
 Span child = takeSpan();
 Span parent = takeSpan();
 assertThat(parent.traceId()).isEqualTo(child.traceId());
 assertThat(parent.id()).isEqualTo(child.parentId());
 assertThat(parent.timestamp()).isLessThan(child.timestamp());
 assertThat(parent.duration()).isGreaterThan(child.duration());
}

代码示例来源:origin: io.zipkin.brave/brave-http-tests

/**
 * This ensures thread-state is propagated from trace interceptors to user code. The endpoint
 * "/child" is expected to create a local span. When this works, it should be a child of the
 * "current span", in this case the span representing an incoming server request. When thread
 * state isn't managed properly, the child span will appear as a new trace.
 */
private void createsChildSpan(String path) {
 Request request = new Request.Builder().url(url(path)).build();
 try (Response response = client.newCall(request).execute()) {
  if (response.code() == 404) throw new AssumptionViolatedException(path + " not supported");
 } catch (AssumptionViolatedException e) {
  throw e;
 } catch (Exception e) {
  // ok, but the span should include an error!
 }
 List<Span> trace = collectedSpans();
 assertThat(trace).hasSize(2);
 Span child = trace.get(0);
 Span parent = trace.get(1);
 assertThat(parent.traceId()).isEqualTo(child.traceId());
 assertThat(parent.id()).isEqualTo(child.parentId());
 assertThat(parent.timestamp()).isLessThan(child.timestamp());
 assertThat(parent.duration()).isGreaterThan(child.duration());
}

代码示例来源:origin: io.zipkin.brave/brave-instrumentation-http-tests

/**
 * This ensures thread-state is propagated from trace interceptors to user code. The endpoint
 * "/child" is expected to create an in-process span. When this works, it should be a child of the
 * "current span", in this case the span representing an incoming server request. When thread
 * state isn't managed properly, the child span will appear as a new trace.
 */
@Test
public void createsChildSpan() throws Exception {
 get("/child");
 Span child = takeSpan();
 Span parent = takeSpan();
 assertThat(parent.traceId()).isEqualTo(child.traceId());
 assertThat(parent.id()).isEqualTo(child.parentId());
 assertThat(parent.timestamp()).isLessThan(child.timestamp());
 assertThat(parent.duration()).isGreaterThan(child.duration());
}

代码示例来源:origin: openzipkin/zipkin-finagle

@Test public void reportsSpanOn_ServerSend() throws Exception {
 advanceAndRecord(0, root, Annotation.ServerRecv$.MODULE$);
 advanceAndRecord(1, root, Annotation.ServerSend$.MODULE$);
 Span span = spansSent.take();
 assertThat(span.kind()).isEqualTo(Span.Kind.SERVER);
 assertThat(span.annotations()).isEmpty();
 assertThat(span.timestamp()).isEqualTo(TODAY * 1000);
 assertThat(span.duration()).isEqualTo(1000);
}

代码示例来源:origin: openzipkin/zipkin-finagle

@Test public void reportsSpanOn_ClientRecv() throws Exception {
 advanceAndRecord(0, root, Annotation.ClientSend$.MODULE$);
 advanceAndRecord(1, root, Annotation.ClientRecv$.MODULE$);
 Span span = spansSent.take();
 assertThat(span.kind()).isEqualTo(Span.Kind.CLIENT);
 assertThat(span.annotations()).isEmpty();
 assertThat(span.timestamp()).isEqualTo(TODAY * 1000);
 assertThat(span.duration()).isEqualTo(1000);
}

代码示例来源:origin: com.google.cloud.trace.adapters.zipkin/translation

TraceSpan.Builder translate(TraceSpan.Builder spanBuilder, Span zipkinSpan) {
 spanBuilder.setName(zipkinSpan.name());
 SpanKind kind = getSpanKind(zipkinSpan.kind());
 spanBuilder.setKind(kind);
 rewriteIds(zipkinSpan, spanBuilder, kind);
 if (zipkinSpan.timestamp() != null) {
  spanBuilder.setStartTime(createTimestamp(zipkinSpan.timestamp()));
  if (zipkinSpan.duration() != null) {
   Timestamp endTime = createTimestamp(zipkinSpan.timestamp() + zipkinSpan.duration());
   spanBuilder.setEndTime(endTime);
  }
 }
 spanBuilder.putAllLabels(labelExtractor.extract(zipkinSpan));
 return spanBuilder;
}

代码示例来源:origin: openzipkin/zipkin-finagle

@Test public void reportsSpanOn_Timeout() throws Exception {
 advanceAndRecord(0, root, Annotation.ClientSend$.MODULE$);
 advanceAndRecord(1, root, new Annotation.Message(TimeoutFilter.TimeoutAnnotation()));
 Span span = spansSent.take();
 assertThat(span.kind()).isEqualTo(Span.Kind.CLIENT);
 assertThat(span.annotations()).extracting(zipkin2.Annotation::value).containsExactly(
   "finagle.timeout"
 );
 assertThat(span.timestamp()).isEqualTo(TODAY * 1000);
 assertThat(span.duration()).isEqualTo(1000);
}

代码示例来源:origin: Nike-Inc/wingtips

assertThat(zipkinSpan.name()).isEqualTo(wingtipsSpan.getSpanName());
assertThat(zipkinSpan.parentId()).isEqualTo(wingtipsSpan.getParentSpanId());
assertThat(zipkinSpan.timestamp()).isEqualTo(wingtipsSpan.getSpanStartTimeEpochMicros());
assertThat(zipkinSpan.traceId()).isEqualTo(wingtipsSpan.getTraceId());
assertThat(zipkinSpan.duration()).isEqualTo(durationMicros);

代码示例来源:origin: Nike-Inc/wingtips

assertThat(zipkinSpan.name()).isEqualTo(wingtipsSpan.getSpanName());
assertThat(zipkinSpan.parentId()).isNull();
assertThat(zipkinSpan.timestamp()).isEqualTo(wingtipsSpan.getSpanStartTimeEpochMicros());
assertThat(zipkinSpan.traceId()).isEqualTo(wingtipsSpan.getTraceId());
assertThat(zipkinSpan.duration()).isEqualTo(durationMicros);

代码示例来源:origin: io.zipkin.brave/brave-core

long startTs = in.timestamp() == null ? 0L : in.timestamp();
Long endTs = in.duration() == null ? 0L : in.timestamp() + in.duration();
if (startTs != 0L) {
 result.timestamp(startTs);

相关文章