use of com.couchbase.client.core.cnc.RequestTracer in project couchbase-jvm-clients by couchbase.
the class ChunkedMessageHandler method write.
@Override
@SuppressWarnings("unchecked")
public void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) {
// toes.
if (!pipelined && currentRequest != null) {
RetryOrchestrator.maybeRetry(endpointContext, (REQ) msg, RetryReason.NOT_PIPELINED_REQUEST_IN_FLIGHT);
if (endpoint != null) {
endpoint.decrementOutstandingRequests();
}
return;
}
try {
currentRequest = (REQ) msg;
FullHttpRequest encoded = currentRequest.encode();
encoded.headers().set(HttpHeaderNames.HOST, remoteHost);
encoded.headers().set(HttpHeaderNames.USER_AGENT, endpointContext.environment().userAgent().formattedLong());
chunkResponseParser.updateRequestContext(currentRequest.context());
dispatchTimingStart = System.nanoTime();
if (currentRequest.requestSpan() != null) {
RequestTracer tracer = endpointContext.environment().requestTracer();
currentDispatchSpan = tracer.requestSpan(TracingIdentifiers.SPAN_DISPATCH, currentRequest.requestSpan());
if (!CbTracing.isInternalTracer(tracer)) {
setCommonDispatchSpanAttributes(currentDispatchSpan, ctx.channel().attr(ChannelAttributes.CHANNEL_ID_KEY).get(), ioContext.localHostname(), ioContext.localPort(), endpoint.remoteHostname(), endpoint.remotePort(), currentRequest.operationId());
}
}
ctx.write(encoded, promise);
} catch (Throwable t) {
currentRequest.response().completeExceptionally(t);
if (endpoint != null) {
endpoint.decrementOutstandingRequests();
}
}
}
use of com.couchbase.client.core.cnc.RequestTracer in project couchbase-jvm-clients by couchbase.
the class NonChunkedHttpMessageHandler method write.
/**
* Writes a given request and encodes it.
*
* @param ctx the channel handler context.
* @param msg the msg to write.
* @param promise the promise that will be passed along.
*/
@Override
@SuppressWarnings("unchecked")
public void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) {
// toes.
if (currentRequest != null) {
RetryOrchestrator.maybeRetry(endpointContext, (Request<? extends Response>) msg, RetryReason.NOT_PIPELINED_REQUEST_IN_FLIGHT);
if (endpoint != null) {
endpoint.decrementOutstandingRequests();
}
return;
}
if (msg instanceof NonChunkedHttpRequest) {
try {
currentRequest = (NonChunkedHttpRequest<Response>) msg;
FullHttpRequest encoded = ((NonChunkedHttpRequest<Response>) msg).encode();
encoded.headers().set(HttpHeaderNames.HOST, remoteHost);
encoded.headers().set(HttpHeaderNames.USER_AGENT, endpointContext.environment().userAgent().formattedLong());
dispatchTimingStart = System.nanoTime();
if (currentRequest.requestSpan() != null) {
RequestTracer tracer = endpointContext.environment().requestTracer();
currentDispatchSpan = tracer.requestSpan(TracingIdentifiers.SPAN_DISPATCH, currentRequest.requestSpan());
if (!CbTracing.isInternalTracer(tracer)) {
setCommonDispatchSpanAttributes(currentDispatchSpan, ctx.channel().attr(ChannelAttributes.CHANNEL_ID_KEY).get(), ioContext.localHostname(), ioContext.localPort(), endpoint.remoteHostname(), endpoint.remotePort(), currentRequest.operationId());
}
}
ctx.write(encoded, promise);
} catch (Throwable t) {
currentRequest.response().completeExceptionally(t);
if (endpoint != null) {
endpoint.decrementOutstandingRequests();
}
}
} else {
if (endpoint != null) {
endpoint.decrementOutstandingRequests();
}
eventBus.publish(new InvalidRequestDetectedEvent(ioContext, serviceType, msg));
ctx.channel().close().addListener(f -> eventBus.publish(new ChannelClosedProactivelyEvent(ioContext, ChannelClosedProactivelyEvent.Reason.INVALID_REQUEST_DETECTED)));
}
}
use of com.couchbase.client.core.cnc.RequestTracer in project couchbase-jvm-clients by couchbase.
the class KeyValueMessageHandler method write.
@Override
@SuppressWarnings({ "unchecked" })
public void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) {
if (msg instanceof KeyValueRequest) {
KeyValueRequest<Response> request = (KeyValueRequest<Response>) msg;
int opaque = request.opaque();
writtenRequests.put(opaque, request);
try {
ctx.write(request.encode(ctx.alloc(), opaque, channelContext), promise);
writtenRequestDispatchTimings.put(opaque, (Long) System.nanoTime());
if (request.requestSpan() != null) {
RequestTracer tracer = endpointContext.environment().requestTracer();
RequestSpan dispatchSpan = tracer.requestSpan(TracingIdentifiers.SPAN_DISPATCH, request.requestSpan());
if (!isInternalTracer) {
setCommonDispatchSpanAttributes(dispatchSpan, ctx.channel().attr(ChannelAttributes.CHANNEL_ID_KEY).get(), ioContext.localHostname(), ioContext.localPort(), endpoint.remoteHostname(), endpoint.remotePort(), null);
setNumericOperationId(dispatchSpan, request.opaque());
setCommonKVSpanAttributes(dispatchSpan, request);
}
writtenRequestDispatchSpans.put(opaque, dispatchSpan);
}
} catch (Throwable err) {
writtenRequests.remove(opaque);
if (err instanceof CollectionNotFoundException) {
if (channelContext.collectionsEnabled()) {
ConfigurationProvider cp = ioContext.core().configurationProvider();
if (cp.collectionRefreshInProgress(request.collectionIdentifier())) {
RetryOrchestrator.maybeRetry(ioContext, request, RetryReason.COLLECTION_MAP_REFRESH_IN_PROGRESS);
} else if (cp.config().bucketConfig(request.bucket()) instanceof MemcachedBucketConfig) {
request.fail(FeatureNotAvailableException.collectionsForMemcached());
} else {
handleOutdatedCollection(request, RetryReason.COLLECTION_NOT_FOUND);
}
return;
}
}
request.fail(err);
}
} else {
eventBus.publish(new InvalidRequestDetectedEvent(ioContext, ServiceType.KV, msg));
ctx.channel().close().addListener(f -> eventBus.publish(new ChannelClosedProactivelyEvent(ioContext, ChannelClosedProactivelyEvent.Reason.INVALID_REQUEST_DETECTED)));
}
}
use of com.couchbase.client.core.cnc.RequestTracer in project couchbase-jvm-clients by couchbase.
the class RequestTracerIntegrationTest method beforeAll.
@BeforeAll
static void beforeAll() {
requestTracer = new TrackingRequestTracer();
cluster = createCluster(env -> env.requestTracer(requestTracer));
Bucket bucket = cluster.bucket(config().bucketname());
collection = bucket.defaultCollection();
bucket.waitUntilReady(Duration.ofSeconds(5));
}
Aggregations