use of com.couchbase.client.core.cnc.RequestSpan in project couchbase-jvm-clients by couchbase.
the class CoreViewIndexManager method publishDesignDocument.
/**
* Convenience method that gets a the document from the development namespace
* and upserts it to the production namespace.
*
* @param name name of the development design document
* @throws DesignDocumentNotFoundException if the development namespace does not contain a document with the given name
*/
public CompletableFuture<Void> publishDesignDocument(String name, CoreCommonOptions options) {
notNullOrEmpty(name, "Name", () -> new ReducedViewErrorContext(null, null, bucket));
RequestSpan span = buildSpan(TracingIdentifiers.SPAN_REQUEST_MV_PUBLISH_DD, options.parentSpan());
CoreCommonOptions childOptions = options.withParentSpan(span);
return getDesignDocument(name, false, childOptions).thenCompose(doc -> upsertDesignDocument(name, doc, true, childOptions)).whenComplete((r, t) -> span.end());
}
use of com.couchbase.client.core.cnc.RequestSpan in project couchbase-jvm-clients by couchbase.
the class CoreBucketManager method updateBucket.
public CompletableFuture<Void> updateBucket(Map<String, String> settings, final CoreCommonOptions options) {
String bucketName = getBucketName(settings);
RequestSpan span = CbTracing.newSpan(core.context(), TracingIdentifiers.SPAN_REQUEST_MB_UPDATE_BUCKET, options.parentSpan().orElse(null));
span.attribute(TracingIdentifiers.ATTR_NAME, bucketName);
CoreCommonOptions getAllBucketOptions = options.withParentSpan(span);
return Mono.fromFuture(() -> getAllBuckets(getAllBucketOptions)).map(buckets -> buckets.containsKey(bucketName)).flatMap(bucketExists -> {
if (!bucketExists) {
return Mono.error(BucketNotFoundException.forBucket(bucketName));
}
return Mono.fromFuture(httpClient.post(pathForBucket(bucketName), options).form(convertSettingsToParams(settings, true)).exec(core).thenApply(response -> null));
}).then().doOnTerminate(span::end).toFuture();
}
use of com.couchbase.client.core.cnc.RequestSpan in project couchbase-jvm-clients by couchbase.
the class QueryRequest method toExecuteRequest.
/**
* Returns a copy of this request tailored to execute a prepared statement.
*
* @param preparedStatementName name of the prepared statement
* @param encodedPlan (nullable) query plan, or null if enhanced prepared statements are enabled.
*/
@Stability.Internal
public QueryRequest toExecuteRequest(String preparedStatementName, String encodedPlan, RequestTracer requestTracer) {
byte[] newQuery = transformQuery(query -> {
query.remove("statement");
query.put("prepared", preparedStatementName);
if (encodedPlan != null) {
query.put("encoded_plan", encodedPlan);
}
});
RequestSpan newSpan = requestTracer.requestSpan("execute", requestSpan());
return copy(statement(), newQuery, idempotent(), newSpan);
}
use of com.couchbase.client.core.cnc.RequestSpan in project couchbase-jvm-clients by couchbase.
the class AsyncCollection method lookupInRequest.
/**
* Helper method to create the underlying lookup subdoc request.
*
* @param id the outer document ID.
* @param specs the spec which specifies the type of lookups to perform.
* @param opts custom options to modify the lookup options.
* @return the subdoc lookup request.
*/
SubdocGetRequest lookupInRequest(final String id, final List<LookupInSpec> specs, final LookupInOptions.Built opts) {
notNullOrEmpty(id, "Id", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
notNullOrEmpty(specs, "LookupInSpecs", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
ArrayList<SubdocGetRequest.Command> commands = new ArrayList<>(specs.size());
for (int i = 0; i < specs.size(); i++) {
LookupInSpec spec = specs.get(i);
commands.add(spec.export(i));
}
// xattrs come first
commands.sort(Comparator.comparing(v -> !v.xattr()));
Duration timeout = opts.timeout().orElse(environment.timeoutConfig().kvTimeout());
RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.retryStrategy());
byte flags = 0;
if (opts.accessDeleted()) {
flags |= SubdocMutateRequest.SUBDOC_DOC_FLAG_ACCESS_DELETED;
}
RequestSpan span = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_LOOKUP_IN, opts.parentSpan().orElse(null));
SubdocGetRequest request = new SubdocGetRequest(timeout, coreContext, collectionIdentifier, retryStrategy, id, flags, commands, 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 replaceRequest.
/**
* Helper method to generate the replace request.
*
* @param id the document id to replace.
* @param content the document content to replace.
* @param opts custom options to customize the replace behavior.
* @return the replace request.
*/
ReplaceRequest replaceRequest(final String id, final Object content, final ReplaceOptions.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_REPLACE, 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();
ReplaceRequest request = new ReplaceRequest(id, encoded.encoded(), expiry, opts.preserveExpiry(), encoded.flags(), timeout, opts.cas(), coreContext, collectionIdentifier, retryStrategy, opts.durabilityLevel(), span);
request.context().clientContext(opts.clientContext()).encodeLatency(end - start);
return request;
}
Aggregations