TransactionManagerImpl(SessionImpl session) { this.session = session; this.span = Tracing.getTracer().getCurrentSpan(); }
@Override public void close() { span.end(); synchronized (lock) { isClosed = true; } }
protected ResumableStreamIterator(int maxBufferSize, String streamName, Span parent) { checkArgument(maxBufferSize >= 0); this.maxBufferSize = maxBufferSize; this.span = tracer.spanBuilderWithExplicitParent(streamName, parent).startSpan(); }
/** 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); } }
@Override public Timestamp writeAtLeastOnce(Iterable<Mutation> mutations) throws SpannerException { Span span = tracer.spanBuilder(READ_WRITE_TRANSACTION).startSpan(); try (Scope s = tracer.withSpan(span)) { return pool.getReadWriteSession().writeAtLeastOnce(mutations); } catch (RuntimeException e) { TraceUtil.endSpanWithFailure(span, e); throw e; } finally { span.end(); } }
@Override public void onCompleted() { Tracing.getTracer() .getCurrentSpan() .addAnnotation( "Firestore.Query: Completed", ImmutableMap.of( "numDocuments", AttributeValue.longAttributeValue(numDocuments))); documentObserver.onCompleted(readTime); } };
static void endSpanWithFailure(Span span, Exception e) { if (e instanceof SpannerException) { endSpanWithFailure(span, (SpannerException) e); } else { span.setStatus(Status.INTERNAL.withDescription(e.getMessage())); span.end(); } }
/** Helper method to start a span. */ private Span startSpan(String spanName) { return tracer .spanBuilder(spanName) .setRecordEvents(censusHttpModule.isRecordEvents()) .startSpan(); }
@Override public void onError(Throwable throwable) { Tracing.getTracer().getCurrentSpan().addAnnotation("Firestore.Query: Error"); documentObserver.onError(throwable); }
@Override public RewriteResponse continueRewrite(RewriteResponse previousResponse) { Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_CONTINUE_REWRITE); Scope scope = tracer.withSpan(span); try { return rewrite(previousResponse.rewriteRequest, previousResponse.rewriteToken); } finally { scope.close(); span.end(); } }
@Override public void onError(Throwable throwable) { tracer.getCurrentSpan().addAnnotation("Firestore.BatchGet: Error"); futureList.setException(throwable); }
private Annotation sessionAnnotation(Session session) { AttributeValue sessionId = AttributeValue.stringAttributeValue(session.getName()); return Annotation.fromDescriptionAndAttributes( "Using Session", ImmutableMap.of("sessionId", sessionId)); }
@Override public TransactionRunner readWriteTransaction() { Span span = tracer.spanBuilder(READ_WRITE_TRANSACTION).startSpan(); try (Scope s = tracer.withSpan(span)) { return pool.getReadWriteSession().readWriteTransaction(); } catch (RuntimeException e) { TraceUtil.endSpanWithFailure(span, e); throw e; } }
@Override public Timestamp write(Iterable<Mutation> mutations) throws SpannerException { Span span = tracer.spanBuilder(READ_WRITE_TRANSACTION).startSpan(); try (Scope s = tracer.withSpan(span)) { return pool.getReadWriteSession().write(mutations); } catch (RuntimeException e) { TraceUtil.endSpanWithFailure(span, e); throw e; } finally { span.end(); } }
private AbstractReadContext(SessionImpl session, SpannerRpc rpc, int defaultPrefetchChunks) { this(session, rpc, defaultPrefetchChunks, Tracing.getTracer().getCurrentSpan()); }
@Override public void close() { try { if (txnState == TransactionState.STARTED && !txn.isAborted()) { txn.rollback(); txnState = TransactionState.ROLLED_BACK; } } finally { span.end(); } }
@Override public ReadOnlyTransaction singleUseReadOnlyTransaction(TimestampBound bound) { Span span = tracer.spanBuilder(READ_ONLY_TRANSACTION).startSpan(); try (Scope s = tracer.withSpan(span)) { return pool.getReadSession().singleUseReadOnlyTransaction(bound); } catch (RuntimeException e) { TraceUtil.endSpanWithFailure(span, e); throw e; } }
TransactionRunnerImpl( SessionImpl session, SpannerRpc rpc, Sleeper sleeper, int defaultPrefetchChunks) { this.session = session; this.sleeper = sleeper; this.span = Tracing.getTracer().getCurrentSpan(); this.txn = session.newTransaction(); }
@Override public long executePartitionedUpdate(Statement stmt) { Span span = tracer.spanBuilder(PARTITION_DML_TRANSACTION).startSpan(); try (Scope s = tracer.withSpan(span)) { return pool.getReadWriteSession().executePartitionedUpdate(stmt); } catch (RuntimeException e) { TraceUtil.endSpanWithFailure(span, e); throw e; } }