Search in sources :

Example 31 with RequestSpan

use of com.couchbase.client.core.cnc.RequestSpan in project couchbase-jvm-clients by couchbase.

the class ReplicaHelper method getAllReplicasAsync.

/**
 * Reads from replicas or the active node based on the options and returns the results as a list
 * of futures that might complete or fail.
 *
 * @param clientContext (nullable)
 * @param parentSpan (nullable)
 * @param responseMapper converts the GetReplicaResponse to the client's native result type
 * @return a list of results from the active and the replica.
 */
public static <R> CompletableFuture<List<CompletableFuture<R>>> getAllReplicasAsync(final Core core, final CollectionIdentifier collectionIdentifier, final String documentId, final Duration timeout, final RetryStrategy retryStrategy, final Map<String, Object> clientContext, final RequestSpan parentSpan, final Function<GetReplicaResponse, R> responseMapper) {
    CoreEnvironment env = core.context().environment();
    RequestSpan getAllSpan = env.requestTracer().requestSpan(TracingIdentifiers.SPAN_GET_ALL_REPLICAS, parentSpan);
    getAllSpan.attribute(TracingIdentifiers.ATTR_SYSTEM, TracingIdentifiers.ATTR_SYSTEM_COUCHBASE);
    return getAllReplicasRequests(core, collectionIdentifier, documentId, clientContext, retryStrategy, timeout, getAllSpan).thenApply(stream -> stream.map(request -> get(core, request).thenApply(response -> new GetReplicaResponse(response, request instanceof ReplicaGetRequest)).thenApply(responseMapper)).collect(Collectors.toList())).whenComplete((completableFutures, throwable) -> {
        final AtomicInteger toComplete = new AtomicInteger(completableFutures.size());
        for (CompletableFuture<R> cf : completableFutures) {
            cf.whenComplete((a, b) -> {
                if (toComplete.decrementAndGet() == 0) {
                    getAllSpan.end();
                }
            });
        }
    });
}
Also used : CouchbaseException(com.couchbase.client.core.error.CouchbaseException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) CouchbaseBucketConfig(com.couchbase.client.core.config.CouchbaseBucketConfig) ArrayList(java.util.ArrayList) DefaultErrorUtil.keyValueStatusToException(com.couchbase.client.core.error.DefaultErrorUtil.keyValueStatusToException) TracingIdentifiers(com.couchbase.client.core.cnc.TracingIdentifiers) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) DocumentUnretrievableException(com.couchbase.client.core.error.DocumentUnretrievableException) CoreContext(com.couchbase.client.core.CoreContext) Duration(java.time.Duration) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Stability(com.couchbase.client.core.annotation.Stability) RequestSpan(com.couchbase.client.core.cnc.RequestSpan) GetResponse(com.couchbase.client.core.msg.kv.GetResponse) IndividualReplicaGetFailedEvent(com.couchbase.client.core.cnc.events.request.IndividualReplicaGetFailedEvent) BucketConfig(com.couchbase.client.core.config.BucketConfig) Reactor(com.couchbase.client.core.Reactor) CommonExceptions(com.couchbase.client.core.error.CommonExceptions) Mono(reactor.core.publisher.Mono) CompletionException(java.util.concurrent.CompletionException) CoreEnvironment(com.couchbase.client.core.env.CoreEnvironment) Collectors(java.util.stream.Collectors) Validators.notNullOrEmpty(com.couchbase.client.core.util.Validators.notNullOrEmpty) Flux(reactor.core.publisher.Flux) List(java.util.List) Stream(java.util.stream.Stream) GetRequest(com.couchbase.client.core.msg.kv.GetRequest) ReplicaGetRequest(com.couchbase.client.core.msg.kv.ReplicaGetRequest) ErrorContext(com.couchbase.client.core.error.context.ErrorContext) CollectionIdentifier(com.couchbase.client.core.io.CollectionIdentifier) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) Core(com.couchbase.client.core.Core) ReducedKeyValueErrorContext(com.couchbase.client.core.error.context.ReducedKeyValueErrorContext) Collections(java.util.Collections) AggregateErrorContext(com.couchbase.client.core.error.context.AggregateErrorContext) CoreEnvironment(com.couchbase.client.core.env.CoreEnvironment) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ReplicaGetRequest(com.couchbase.client.core.msg.kv.ReplicaGetRequest) RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Example 32 with RequestSpan

use of com.couchbase.client.core.cnc.RequestSpan in project couchbase-jvm-clients by couchbase.

the class OpenTelemetryRequestTracer method requestSpan.

@Override
public RequestSpan requestSpan(String operationName, RequestSpan parent) {
    try {
        SpanBuilder spanBuilder = tracer.spanBuilder(operationName);
        Context parentContext = Context.current();
        if (parent != null) {
            parentContext = parentContext.with(castSpan(parent));
        }
        Span span = spanBuilder.setParent(parentContext).startSpan();
        return OpenTelemetryRequestSpan.wrap(span);
    } catch (Exception ex) {
        throw new TracerException("Failed to create OpenTelemetryRequestSpan", ex);
    }
}
Also used : Context(io.opentelemetry.context.Context) SpanBuilder(io.opentelemetry.api.trace.SpanBuilder) TracerException(com.couchbase.client.core.error.TracerException) Span(io.opentelemetry.api.trace.Span) RequestSpan(com.couchbase.client.core.cnc.RequestSpan) TracerException(com.couchbase.client.core.error.TracerException)

Example 33 with RequestSpan

use of com.couchbase.client.core.cnc.RequestSpan in project couchbase-jvm-clients by couchbase.

the class AsyncBinaryCollection method decrementRequest.

DecrementRequest decrementRequest(final String id, final DecrementOptions.Built opts) {
    notNullOrEmpty(id, "Id", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
    Duration timeout = decideKvTimeout(opts, environment.timeoutConfig());
    RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.retryStrategy());
    RequestSpan span = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_DECREMENT, opts.parentSpan().orElse(null));
    long expiry = opts.expiry().encode();
    DecrementRequest request = new DecrementRequest(timeout, coreContext, collectionIdentifier, retryStrategy, id, opts.delta(), opts.initial(), expiry, opts.durabilityLevel(), span);
    request.context().clientContext(opts.clientContext());
    return request;
}
Also used : DecrementRequest(com.couchbase.client.core.msg.kv.DecrementRequest) Duration(java.time.Duration) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Example 34 with RequestSpan

use of com.couchbase.client.core.cnc.RequestSpan in project couchbase-jvm-clients by couchbase.

the class AsyncBinaryCollection method prependRequest.

PrependRequest prependRequest(final String id, final byte[] content, final PrependOptions.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());
    RequestSpan span = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_PREPEND, opts.parentSpan().orElse(null));
    PrependRequest request = new PrependRequest(timeout, coreContext, collectionIdentifier, retryStrategy, id, content, opts.cas(), opts.durabilityLevel(), span);
    request.context().clientContext(opts.clientContext());
    return request;
}
Also used : Duration(java.time.Duration) PrependRequest(com.couchbase.client.core.msg.kv.PrependRequest) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Example 35 with RequestSpan

use of com.couchbase.client.core.cnc.RequestSpan in project couchbase-jvm-clients by couchbase.

the class AsyncBinaryCollection method incrementRequest.

IncrementRequest incrementRequest(final String id, final IncrementOptions.Built opts) {
    notNullOrEmpty(id, "Id", () -> ReducedKeyValueErrorContext.create(id, collectionIdentifier));
    Duration timeout = decideKvTimeout(opts, environment.timeoutConfig());
    RetryStrategy retryStrategy = opts.retryStrategy().orElse(environment.retryStrategy());
    RequestSpan span = environment.requestTracer().requestSpan(TracingIdentifiers.SPAN_REQUEST_KV_INCREMENT, opts.parentSpan().orElse(null));
    long expiry = opts.expiry().encode();
    IncrementRequest request = new IncrementRequest(timeout, coreContext, collectionIdentifier, retryStrategy, id, opts.delta(), opts.initial(), expiry, opts.durabilityLevel(), span);
    request.context().clientContext(opts.clientContext());
    return request;
}
Also used : IncrementRequest(com.couchbase.client.core.msg.kv.IncrementRequest) Duration(java.time.Duration) RetryStrategy(com.couchbase.client.core.retry.RetryStrategy) RequestSpan(com.couchbase.client.core.cnc.RequestSpan)

Aggregations

RequestSpan (com.couchbase.client.core.cnc.RequestSpan)42 Duration (java.time.Duration)30 RetryStrategy (com.couchbase.client.core.retry.RetryStrategy)28 TracingIdentifiers (com.couchbase.client.core.cnc.TracingIdentifiers)12 CompletableFuture (java.util.concurrent.CompletableFuture)11 Stability (com.couchbase.client.core.annotation.Stability)10 Validators.notNullOrEmpty (com.couchbase.client.core.util.Validators.notNullOrEmpty)10 List (java.util.List)10 Core (com.couchbase.client.core.Core)9 ArrayList (java.util.ArrayList)9 Map (java.util.Map)9 BucketConfig (com.couchbase.client.core.config.BucketConfig)8 CouchbaseException (com.couchbase.client.core.error.CouchbaseException)8 Objects.requireNonNull (java.util.Objects.requireNonNull)8 Mono (reactor.core.publisher.Mono)8 Reactor (com.couchbase.client.core.Reactor)7 InvalidArgumentException (com.couchbase.client.core.error.InvalidArgumentException)7 GetRequest (com.couchbase.client.core.msg.kv.GetRequest)7 Function (java.util.function.Function)7 CoreContext (com.couchbase.client.core.CoreContext)6