use of com.couchbase.client.core.cnc.RequestSpan in project couchbase-jvm-clients by couchbase.
the class RequestContext method logicallyComplete.
/**
* Signals that this request is completed fully, including streaming sections or logical sub-requests also being
* completed (i.e. observe polling).
*/
@Stability.Internal
public RequestContext logicallyComplete() {
this.logicallyCompletedAt = System.nanoTime();
RequestSpan span = request.requestSpan();
if (span != null) {
span.attribute(TracingIdentifiers.ATTR_RETRIES, retryAttempts());
span.end();
}
if (!(environment().meter() instanceof NoopMeter)) {
long latency = logicalRequestLatency();
if (latency > 0) {
core().responseMetric(request).recordValue(latency);
}
}
return this;
}
use of com.couchbase.client.core.cnc.RequestSpan in project couchbase-jvm-clients by couchbase.
the class AsyncQueryIndexManager method watchIndexes.
/**
* Watches/Polls indexes until they are online with custom options.
* <p>
* By default, this method will watch the indexes on the bucket. If the indexes should be watched on a collection,
* both {@link WatchQueryIndexesOptions#scopeName(String)} and
* {@link WatchQueryIndexesOptions#collectionName(String)} must be set.
*
* @param bucketName the name of the bucket where the indexes should be watched.
* @param indexNames the names of the indexes to watch.
* @param timeout the maximum amount of time the indexes should be watched.
* @param options the custom options to apply.
* @return a {@link CompletableFuture} completing when the operation is applied or failed with an error.
* @throws CouchbaseException (async) if any other generic unhandled/unexpected errors.
*/
public CompletableFuture<Void> watchIndexes(final String bucketName, final Collection<String> indexNames, final Duration timeout, final WatchQueryIndexesOptions options) {
notNullOrEmpty(bucketName, "BucketName");
notNull(indexNames, "IndexNames");
notNull(timeout, "Timeout");
notNull(options, "Options");
Set<String> indexNameSet = new HashSet<>(indexNames);
WatchQueryIndexesOptions.Built builtOpts = options.build();
RequestSpan parent = cluster.environment().requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_MQ_WATCH_INDEXES, null);
parent.attribute(TracingIdentifiers.ATTR_SYSTEM, TracingIdentifiers.ATTR_SYSTEM_COUCHBASE);
return Mono.fromFuture(() -> failIfIndexesOffline(bucketName, indexNameSet, builtOpts.watchPrimary(), parent, builtOpts.scopeName(), builtOpts.collectionName())).retryWhen(Retry.onlyIf(ctx -> hasCause(ctx.exception(), IndexesNotReadyException.class)).exponentialBackoff(Duration.ofMillis(50), Duration.ofSeconds(1)).timeout(timeout).toReactorRetry()).onErrorMap(t -> t instanceof RetryExhaustedException ? toWatchTimeoutException(t, timeout) : t).toFuture().whenComplete((r, t) -> parent.end());
}
use of com.couchbase.client.core.cnc.RequestSpan in project couchbase-jvm-clients by couchbase.
the class OpenTracingRequestTracer method requestSpan.
@Override
public RequestSpan requestSpan(final String operationName, final RequestSpan parent) {
try {
Tracer.SpanBuilder builder = tracer.buildSpan(operationName);
if (parent != null) {
builder.asChildOf(castSpan(parent));
}
Span span = builder.start();
tracer.activateSpan(span).close();
return OpenTracingRequestSpan.wrap(tracer, span);
} catch (Exception ex) {
throw new TracerException("Failed to create OpenTracingRequestSpan", ex);
}
}
use of com.couchbase.client.core.cnc.RequestSpan in project couchbase-jvm-clients by couchbase.
the class AsyncCollection method touchRequest.
/**
* Helper method to create the touch request.
*
* @param id the id of the document to update.
* @param expiry the new expiry for the document.
* @param options the custom options.
* @return the touch request.
*/
TouchRequest touchRequest(final String id, final Expiry expiry, final TouchOptions options) {
notNullOrEmpty(id, "Id", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
notNull(expiry, "Expiry", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
notNull(options, "TouchOptions", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
TouchOptions.Built opts = options.build();
Duration timeout = opts.timeout().orElse(environment.timeoutConfig().kvTimeout());
RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.retryStrategy());
RequestSpan span = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_TOUCH, opts.parentSpan().orElse(null));
long encodedExpiry = expiry.encode();
TouchRequest request = new TouchRequest(timeout, coreContext, collectionIdentifier, retryStrategy, id, encodedExpiry, span);
request.context().clientContext(opts.clientContext());
return request;
}
use of com.couchbase.client.core.cnc.RequestSpan in project couchbase-jvm-clients by couchbase.
the class AsyncCollection method upsertRequest.
/**
* Helper method to generate the upsert request.
*
* @param id the document id to upsert.
* @param content the document content to upsert.
* @param opts custom options to customize the upsert behavior.
* @return the upsert request.
*/
UpsertRequest upsertRequest(final String id, final Object content, final UpsertOptions.Built opts) {
notNullOrEmpty(id, "Id", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
notNull(content, "Content", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
Duration timeout = decideKvTimeout(opts, environment.timeoutConfig());
RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.retryStrategy());
Transcoder transcoder = opts.transcoder() == null ? environment.transcoder() : opts.transcoder();
final RequestSpan span = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_UPSERT, opts.parentSpan().orElse(null));
final RequestSpan encodeSpan = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_ENCODING, span);
long start = System.nanoTime();
Transcoder.EncodedValue encoded;
try {
encoded = transcoder.encode(content);
} finally {
encodeSpan.end();
}
long end = System.nanoTime();
long expiry = opts.expiry().encode();
final UpsertRequest request = new UpsertRequest(id, encoded.encoded(), expiry, opts.preserveExpiry(), encoded.flags(), timeout, coreContext, collectionIdentifier, retryStrategy, opts.durabilityLevel(), span);
request.context().clientContext(opts.clientContext()).encodeLatency(end - start);
return request;
}
Aggregations