protected ResumableStreamIterator(int maxBufferSize, String streamName, Span parent) { checkArgument(maxBufferSize >= 0); this.maxBufferSize = maxBufferSize; this.span = tracer.spanBuilderWithExplicitParent(streamName, parent).startSpan(); }
Span opSpan = tracer.spanBuilderWithExplicitParent(COMMIT, span).startSpan(); try (Scope s = tracer.withSpan(opSpan)) { CommitResponse commitResponse =
.spanBuilderWithExplicitParent(SAMPLE_SPAN, null) .setSampler(Samplers.alwaysSample()) .startScopedSpan()) {
protected ResumableStreamIterator(int maxBufferSize, String streamName, Span parent) { checkArgument(maxBufferSize >= 0); this.maxBufferSize = maxBufferSize; this.span = tracer.spanBuilderWithExplicitParent(streamName, parent).startSpan(); }
/** * 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()); }
/** * 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()); }
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(); }
@Test(expected = NullPointerException.class) public void spanBuilderWithParentAndName_NullName() { noopTracer.spanBuilderWithExplicitParent(null, null); }
@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); }
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(); }
@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); }
@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); }
@Test public void defaultSpanBuilderWithParentAndName() { assertThat(noopTracer.spanBuilderWithExplicitParent(SPAN_NAME, null).startSpan()) .isSameAs(BlankSpan.INSTANCE); }
@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); }
@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); }
@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); }
@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(); } }
@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(); } }
@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(); } } }
@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); } }