use of com.couchbase.client.core.error.context.ReducedAnalyticsErrorContext 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;
}
Aggregations