Refine search
/** Transaction functions that returns its result in the provided SettableFuture. */ private <T> void runTransaction( final Transaction.Function<T> transactionCallback, final SettableApiFuture<T> resultFuture, final TransactionOptions options) { // span is intentionally not ended here. It will be ended by runTransactionAttempt on success // or error. Span span = tracer.spanBuilder("CloudFirestore.Transaction").startSpan(); try (Scope s = tracer.withSpan(span)) { runTransactionAttempt(transactionCallback, resultFuture, options, span); } }
TransactionManagerImpl(SessionImpl session) { this.session = session; this.span = Tracing.getTracer().getCurrentSpan(); }
protected ResumableStreamIterator(int maxBufferSize, String streamName, Span parent) { checkArgument(maxBufferSize >= 0); this.maxBufferSize = maxBufferSize; this.span = tracer.spanBuilderWithExplicitParent(streamName, parent).startSpan(); }
@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(); } }
/** Helper method to start a span. */ private Span startSpan(String spanName) { return tracer .spanBuilder(spanName) .setRecordEvents(censusHttpModule.isRecordEvents()) .startSpan(); }
@Override public TransactionContext begin() { Preconditions.checkState(txn == null, "begin can only be called once"); try (Scope s = tracer.withSpan(span)) { txn = session.newTransaction(); session.setActive(this); txn.ensureTxn(); txnState = TransactionState.STARTED; return txn; } }
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 doNotCrash_NoopImplementation() throws Exception { SpanBuilder spanBuilder = tracer.spanBuilder("MySpanName"); spanBuilder.setParentLinks(Collections.<Span>emptyList()); spanBuilder.setRecordEvents(true); spanBuilder.setSampler(Samplers.alwaysSample()); spanBuilder.setSpanKind(Kind.SERVER); assertThat(spanBuilder.startSpan()).isSameAs(BlankSpan.INSTANCE); } }
@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); } }
@MustBeClosed @Override public Closeable startScopedSpan(String spanName) { checkNotNull(spanName, "spanName"); return Tracing.getTracer() .spanBuilder(spanName) .setSampler(Samplers.alwaysSample()) .setRecordEvents(true) .startScopedSpan(); }
ServerTracer(String fullMethodName, @Nullable SpanContext remoteSpan) { checkNotNull(fullMethodName, "fullMethodName"); this.span = censusTracer .spanBuilderWithRemoteParent( generateTraceSpanName(true, fullMethodName), remoteSpan) .setRecordEvents(true) .startSpan(); }
Span opSpan = tracer.spanBuilderWithExplicitParent(COMMIT, span).startSpan(); try (Scope s = tracer.withSpan(opSpan)) { CommitResponse commitResponse = runWithRetries(
@MustBeClosed private static Scope newExportScope() { // Start a new span with explicit sampler (with low probability) to avoid the case when user // sets the default sampler to always sample and we get the Thrift span of the Jaeger // export call always sampled and go to an infinite loop. return tracer.spanBuilder(EXPORT_SPAN_NAME).setSampler(lowProbabilitySampler).startScopedSpan(); }
@Test public void getCurrentSpan_WithSpan() { assertThat(noopTracer.getCurrentSpan()).isSameAs(BlankSpan.INSTANCE); Scope ws = noopTracer.withSpan(span); try { assertThat(noopTracer.getCurrentSpan()).isSameAs(span); } finally { ws.close(); } assertThat(noopTracer.getCurrentSpan()).isSameAs(BlankSpan.INSTANCE); }
@Test public void defaultSpanBuilderWithRemoteParent_NullParent() { assertThat(noopTracer.spanBuilderWithRemoteParent(SPAN_NAME, null).startSpan()) .isSameAs(BlankSpan.INSTANCE); }
@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); }
.spanBuilderWithExplicitParent(SAMPLE_SPAN, null) .setSampler(Samplers.alwaysSample()) .startScopedSpan()) { ResultSet resultSet = dbClient.singleUse().executeQuery(Statement.of("SELECT 1"));
@Test public void startScopedSpan() { assertThat(tracer.getCurrentSpan()).isSameAs(BlankSpan.INSTANCE); Scope scope = spanBuilder.startScopedSpan(); try { assertThat(tracer.getCurrentSpan()).isSameAs(span); } finally { scope.close(); } verify(span).end(EndSpanOptions.DEFAULT); assertThat(tracer.getCurrentSpan()).isSameAs(BlankSpan.INSTANCE); }
@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(); } }
/** * 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()); }