use of com.couchbase.client.core.cnc.RequestSpan in project couchbase-jvm-clients by couchbase.
the class AsyncCluster method queryRequest.
/**
* Helper method to construct the query request.
*
* @param statement the statement of the query.
* @param options the options.
* @return the constructed query request.
*/
QueryRequest queryRequest(final String statement, final QueryOptions.Built options) {
notNullOrEmpty(statement, "Statement", () -> new ReducedQueryErrorContext(statement));
Duration timeout = options.timeout().orElse(environment.get().timeoutConfig().queryTimeout());
RetryStrategy retryStrategy = options.retryStrategy().orElse(environment.get().retryStrategy());
final JsonObject query = JsonObject.create();
query.put("statement", statement);
query.put("timeout", encodeDurationToMs(timeout));
options.injectParams(query);
final byte[] queryBytes = query.toString().getBytes(StandardCharsets.UTF_8);
final String clientContextId = query.getString("client_context_id");
final RequestSpan span = environment().requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_QUERY, options.parentSpan().orElse(null));
QueryRequest request = new QueryRequest(timeout, core.context(), retryStrategy, authenticator, statement, queryBytes, options.readonly(), clientContextId, span, null, null, null);
request.context().clientContext(options.clientContext());
return request;
}
use of com.couchbase.client.core.cnc.RequestSpan in project couchbase-jvm-clients by couchbase.
the class AsyncCluster method analyticsRequest.
/**
* Helper method to craft an analytics request.
*
* @param statement the statement to use.
* @param opts the built analytics options.
* @return the created analytics request.
*/
AnalyticsRequest analyticsRequest(final String statement, final AnalyticsOptions.Built opts) {
notNullOrEmpty(statement, "Statement", () -> new ReducedAnalyticsErrorContext(statement));
Duration timeout = opts.timeout().orElse(environment.get().timeoutConfig().analyticsTimeout());
RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.get().retryStrategy());
JsonObject query = JsonObject.create();
query.put("statement", statement);
query.put("timeout", encodeDurationToMs(timeout));
opts.injectParams(query);
final byte[] queryBytes = query.toString().getBytes(StandardCharsets.UTF_8);
final String clientContextId = query.getString("client_context_id");
final RequestSpan span = environment().requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_ANALYTICS, opts.parentSpan().orElse(null));
AnalyticsRequest request = new AnalyticsRequest(timeout, core.context(), retryStrategy, authenticator, queryBytes, opts.priority(), opts.readonly(), clientContextId, statement, span, null, null);
request.context().clientContext(opts.clientContext());
return request;
}
use of com.couchbase.client.core.cnc.RequestSpan in project couchbase-jvm-clients by couchbase.
the class AsyncCluster method searchRequest.
SearchRequest searchRequest(final String indexName, final SearchQuery query, final SearchOptions.Built opts) {
notNullOrEmpty(indexName, "IndexName", () -> new ReducedSearchErrorContext(indexName, query.export().toMap()));
Duration timeout = opts.timeout().orElse(environment.get().timeoutConfig().searchTimeout());
JsonObject params = query.export();
opts.injectParams(indexName, params, timeout);
byte[] bytes = params.toString().getBytes(StandardCharsets.UTF_8);
RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.get().retryStrategy());
final RequestSpan span = environment().requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_SEARCH, opts.parentSpan().orElse(null));
SearchRequest request = new SearchRequest(timeout, core.context(), retryStrategy, authenticator, indexName, bytes, 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 getAndLockRequest.
/**
* Helper method to create the get and lock request.
*
* @param id the document id which is used to uniquely identify it.
* @param lockTime how long to lock the document for. Any values above 30 seconds will be
* treated as 30 seconds.
* @param opts custom options to change the default behavior.
* @return the get and lock request.
*/
@Stability.Internal
GetAndLockRequest getAndLockRequest(final String id, final Duration lockTime, final GetAndLockOptions.Built opts) {
notNullOrEmpty(id, "Id", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
notNull(lockTime, "LockTime", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
Duration timeout = opts.timeout().orElse(environment.timeoutConfig().kvTimeout());
RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.retryStrategy());
RequestSpan span = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_GET_AND_LOCK, opts.parentSpan().orElse(null));
GetAndLockRequest request = new GetAndLockRequest(id, timeout, coreContext, collectionIdentifier, retryStrategy, lockTime, 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 AsyncSearchIndexManager method getIndex.
/**
* Fetches an index from the server if it exists.
*
* @param name the name of the search index.
* @return a {@link CompletableFuture} the found index once complete.
*/
public CompletableFuture<SearchIndex> getIndex(final String name, GetSearchIndexOptions options) {
notNullOrEmpty(name, "Search Index Name");
RequestSpan span = CbTracing.newSpan(core.context(), TracingIdentifiers.SPAN_REQUEST_MS_GET_INDEX, options.build().parentSpan().orElse(null));
return getAllIndexes(getAllSearchIndexesOptions().parentSpan(span)).thenApply(indexes -> indexes.stream().filter(i -> i.name().equals(name)).findFirst().orElseThrow(() -> new IndexNotFoundException(name))).whenComplete((r, t) -> span.end());
}
Aggregations