io.opencensus.trace.Tracer.spanBuilderWithExplicitParent()方法的使用及代码示例

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

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

Tracer.spanBuilderWithExplicitParent介绍

[英]Returns a SpanBuilder to create and start a new child Span (or root if parent is null or has an invalid SpanContext), with parent being the designated Span.

See SpanBuilder for usage examples.

This must be used to create a Span when manual Context propagation is used OR when creating a root Span with a null parent.
[中]返回一个SpanBuilder,以创建并启动一个新的子跨度(如果父跨度为null或具有无效的SpanContext,则返回root),父跨度为指定的跨度。
有关用法示例,请参见SpanBuilder。
当使用手动上下文传播或使用空父级创建根范围时,必须使用此选项来创建范围。

代码示例

代码示例来源:origin: googleapis/google-cloud-java

protected ResumableStreamIterator(int maxBufferSize, String streamName, Span parent) {
 checkArgument(maxBufferSize >= 0);
 this.maxBufferSize = maxBufferSize;
 this.span = tracer.spanBuilderWithExplicitParent(streamName, parent).startSpan();
}

代码示例来源:origin: googleapis/google-cloud-java

Span opSpan = tracer.spanBuilderWithExplicitParent(COMMIT, span).startSpan();
try (Scope s = tracer.withSpan(opSpan)) {
 CommitResponse commitResponse =

代码示例来源:origin: GoogleCloudPlatform/java-docs-samples

.spanBuilderWithExplicitParent(SAMPLE_SPAN, null)
.setSampler(Samplers.alwaysSample())
.startScopedSpan()) {

代码示例来源:origin: com.google.cloud/google-cloud-spanner

protected ResumableStreamIterator(int maxBufferSize, String streamName, Span parent) {
 checkArgument(maxBufferSize >= 0);
 this.maxBufferSize = maxBufferSize;
 this.span = tracer.spanBuilderWithExplicitParent(streamName, parent).startSpan();
}

代码示例来源:origin: census-instrumentation/opencensus-java

/**
 * Returns a {@link SpanBuilder} to create and start a new child {@link Span} as a child of to the
 * current {@code Span} if any, otherwise creates a root {@code Span}.
 *
 * <p>See {@link SpanBuilder} for usage examples.
 *
 * <p>This <b>must</b> be used to create a {@code Span} when automatic Context propagation is
 * used.
 *
 * <p>This is equivalent with:
 *
 * <pre>{@code
 * tracer.spanBuilderWithExplicitParent("MySpanName",tracer.getCurrentSpan());
 * }</pre>
 *
 * @param spanName The name of the returned Span.
 * @return a {@code SpanBuilder} to create and start a new {@code Span}.
 * @throws NullPointerException if {@code spanName} is {@code null}.
 * @since 0.5
 */
public final SpanBuilder spanBuilder(String spanName) {
 return spanBuilderWithExplicitParent(spanName, CurrentSpanUtils.getCurrentSpan());
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

/**
 * Returns a {@link SpanBuilder} to create and start a new child {@link Span} as a child of to the
 * current {@code Span} if any, otherwise creates a root {@code Span}.
 *
 * <p>See {@link SpanBuilder} for usage examples.
 *
 * <p>This <b>must</b> be used to create a {@code Span} when automatic Context propagation is
 * used.
 *
 * <p>This is equivalent with:
 *
 * <pre>{@code
 * tracer.spanBuilderWithExplicitParent("MySpanName",tracer.getCurrentSpan());
 * }</pre>
 *
 * @param spanName The name of the returned Span.
 * @return a {@code SpanBuilder} to create and start a new {@code Span}.
 * @throws NullPointerException if {@code spanName} is {@code null}.
 */
public final SpanBuilder spanBuilder(String spanName) {
 return spanBuilderWithExplicitParent(spanName, CurrentSpanUtils.getCurrentSpan());
}

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

ClientCallTracer(@Nullable Span parentSpan, MethodDescriptor<?, ?> method) {
 checkNotNull(method, "method");
 this.isSampledToLocalTracing = method.isSampledToLocalTracing();
 this.span =
   censusTracer
     .spanBuilderWithExplicitParent(
       generateTraceSpanName(false, method.getFullMethodName()),
       parentSpan)
     .setRecordEvents(true)
     .startSpan();
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test(expected = NullPointerException.class)
public void spanBuilderWithParentAndName_NullName() {
 noopTracer.spanBuilderWithExplicitParent(null, null);
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Before
public void setUp() {
 MockitoAnnotations.initMocks(this);
 handler =
   new HttpClientHandler<Object, Object, Object>(
     tracer, extractor, textFormat, textFormatSetter);
 when(tracer.spanBuilderWithExplicitParent(any(String.class), same(parentSpan)))
   .thenReturn(spanBuilder);
 when(spanBuilder.startSpan()).thenReturn(childSpan);
}

代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded

ClientCallTracer(@Nullable Span parentSpan, MethodDescriptor<?, ?> method) {
 checkNotNull(method, "method");
 this.isSampledToLocalTracing = method.isSampledToLocalTracing();
 this.span =
   censusTracer
     .spanBuilderWithExplicitParent(
       generateTraceSpanName(false, method.getFullMethodName()),
       parentSpan)
     .setRecordEvents(true)
     .startSpan();
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void handleStartCreateChildSpanInSpecifiedContext() {
 // without scope
 HttpRequestContext context = handler.handleStart(parentSpan, carrier, request);
 verify(tracer).spanBuilderWithExplicitParent(any(String.class), same(parentSpan));
 assertThat(context.span).isEqualTo(childSpan);
}

代码示例来源:origin: com.google.api/gax

@Override
public ApiTracer newRootTracer(SpanName spanName) {
 if (clientNameOverride != null) {
  spanName = spanName.withClientName(clientNameOverride);
 }
 Span span =
   internalTracer
     .spanBuilderWithExplicitParent(spanName.toString(), BlankSpan.INSTANCE)
     .setRecordEvents(true)
     .startSpan();
 return new OpencensusTracer(internalTracer, span);
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void defaultSpanBuilderWithParentAndName() {
 assertThat(noopTracer.spanBuilderWithExplicitParent(SPAN_NAME, null).startSpan())
   .isSameAs(BlankSpan.INSTANCE);
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void handleStartShouldIgnoreContextParseException() throws Exception {
 when(textFormat.extract(same(carrier), same(textFormatGetter)))
   .thenThrow(new SpanContextParseException("test"));
 HttpRequestContext context = handler.handleStart(carrier, request);
 verify(tracer).spanBuilderWithExplicitParent(any(String.class), any(Span.class));
 assertThat(context.span).isEqualTo(spanWithLocalParent);
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Before
public void setUp() throws SpanContextParseException {
 MockitoAnnotations.initMocks(this);
 handler =
   new HttpServerHandler<Object, Object, Object>(
     tracer, extractor, textFormat, textFormatGetter, false);
 handlerForPublicEndpoint =
   new HttpServerHandler<Object, Object, Object>(
     tracer, extractor, textFormat, textFormatGetter, true);
 when(tracer.spanBuilderWithRemoteParent(any(String.class), same(spanContextRemote)))
   .thenReturn(spanBuilderWithRemoteParent);
 when(tracer.spanBuilderWithExplicitParent(any(String.class), any(Span.class)))
   .thenReturn(spanBuilderWithLocalParent);
 when(spanBuilderWithRemoteParent.startSpan()).thenReturn(spanWithRemoteParent);
 when(spanBuilderWithLocalParent.startSpan()).thenReturn(spanWithLocalParent);
 when(textFormat.extract(same(carrier), same(textFormatGetter))).thenReturn(spanContextRemote);
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void handleStartWithPublicEndpointShouldAddLink() throws Exception {
 handlerForPublicEndpoint.handleStart(carrier, request);
 verify(tracer).spanBuilderWithExplicitParent(any(String.class), any(Span.class));
 verify(spanWithLocalParent).addLink(captor.capture());
 Link link = captor.getValue();
 assertThat(link.getSpanId()).isEqualTo(spanContextRemote.getSpanId());
 assertThat(link.getTraceId()).isEqualTo(spanContextRemote.getTraceId());
 assertThat(link.getType()).isEqualTo(Type.PARENT_LINKED_SPAN);
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void handleStartShouldCreateChildSpanInCurrentContext() {
 Scope scope = tracer.withSpan(parentSpan);
 try {
  HttpRequestContext context = handler.handleStart(null, carrier, request);
  verify(tracer).spanBuilderWithExplicitParent(any(String.class), same(parentSpan));
  assertThat(context.span).isEqualTo(childSpan);
 } finally {
  scope.close();
 }
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
public void startSpanWithParentFromContext() {
 Scope ws = tracer.withSpan(span);
 try {
  assertThat(tracer.getCurrentSpan()).isSameAs(span);
  when(tracer.spanBuilderWithExplicitParent(same(SPAN_NAME), same(span)))
    .thenReturn(spanBuilder);
  assertThat(tracer.spanBuilder(SPAN_NAME)).isSameAs(spanBuilder);
 } finally {
  ws.close();
 }
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
 public void startSpanWithInvalidParentFromContext() {
  Scope ws = tracer.withSpan(BlankSpan.INSTANCE);
  try {
   assertThat(tracer.getCurrentSpan()).isSameAs(BlankSpan.INSTANCE);
   when(tracer.spanBuilderWithExplicitParent(same(SPAN_NAME), same(BlankSpan.INSTANCE)))
     .thenReturn(spanBuilder);
   assertThat(tracer.spanBuilder(SPAN_NAME)).isSameAs(spanBuilder);
  } finally {
   ws.close();
  }
 }
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Override
public final void handle(HttpExchange httpExchange) throws IOException {
 Span span =
   tracer
     .spanBuilderWithExplicitParent(httpServerSpanName, null)
     .setRecordEvents(true)
     .startSpan();
 try (Scope ss = tracer.withSpan(span)) {
  span.putAttribute(
    "/http/method ", AttributeValue.stringAttributeValue(httpExchange.getRequestMethod()));
  httpExchange.sendResponseHeaders(200, 0);
  zpageHandler.emitHtml(
    uriQueryToMap(httpExchange.getRequestURI()), httpExchange.getResponseBody());
 } finally {
  httpExchange.close();
  span.end(END_SPAN_OPTIONS);
 }
}

相关文章