public void submitBinaryAnnotation(String name, String value) { if (enabled) { clientTracer.submitBinaryAnnotation(name, value); } } public void submitAnnotation(String name, String value)
public void submitBinaryAnnotation(String name, int value) { if (enabled) { clientTracer.submitBinaryAnnotation(name, value); } } public void submitBinaryAnnotation(String name, String value)
public void startClientTracer(String clientContext) { if (enabled) { clientTracer.startNewSpan(clientContext); clientTracer.submitBinaryAnnotation(REQUEST_ANNOTATION, clientContext); clientTracer.setClientSent(); } } public void stopClientTracer()
/** * Handles a Client Response. * * @param clientResponseAdapter */ public void handle(final ClientResponseAdapter clientResponseAdapter) { try { final int responseStatus = clientResponseAdapter.getStatusCode(); clientTracer.submitBinaryAnnotation(HTTP_RESPONSE_CODE_ANNOTATION, responseStatus); if (responseStatus < 200 || responseStatus > 299) { // In this case response will be the error message. clientTracer.submitAnnotation(FAILURE_ANNOTATION); } } finally { clientTracer.setClientReceived(); } } }
/** * Interface method implementation. Interprets the response and submits suitable annotation to the client tracer and also marks receipt of the response on it. * @see com.flipkart.phantom.task.spi.interceptor.ResponseInterceptor#process(java.lang.Object) */ public void process(S response, Optional<RuntimeException> transportError) { ClientTracer clientTracer = Brave.getClientTracer(this.eventDispatchingSpanCollector, this.traceFilters); if (transportError.isPresent()) { clientTracer.submitAnnotation(FAILURE_ANNOTATION); } else { final Optional<Integer> statusCode = this.getResponseStatusCode(response); if (statusCode.isPresent()) { clientTracer.submitBinaryAnnotation(RESPONSE_CODE_ANNOTATION, statusCode.get()); } if (!this.isResponseSuccess(response)) { // In this case response will be the error message. clientTracer.submitAnnotation(FAILURE_ANNOTATION); } } clientTracer.setClientReceived(); }
/** * Handle a client response. * * @param adapter Adapter that hides implementation details. */ public void handle(ClientResponseAdapter adapter) { try { for (KeyValueAnnotation annotation : adapter.responseAnnotations()) { clientTracer.submitBinaryAnnotation(annotation.getKey(), annotation.getValue()); } } finally { clientTracer.setClientReceived(); } } }
/** * Handle a client response. * * @param adapter Adapter that hides implementation details. */ public void handle(ClientResponseAdapter adapter) { try { for (KeyValueAnnotation annotation : adapter.responseAnnotations()) { clientTracer.submitBinaryAnnotation(annotation.getKey(), annotation.getValue()); } } finally { clientTracer.setClientReceived(); } } }
/** * Handles a client request. * * @param clientRequestAdapter Provides context about the request. * @param serviceNameOverride Optional name of the service the client request calls. In case it is not specified the name * will be derived from the URI of the request. It is important the used service name should be same on client * as on server side. */ public void handle(final ClientRequestAdapter clientRequestAdapter, final Optional<String> serviceNameOverride) { final String spanName = getSpanName(clientRequestAdapter, serviceNameOverride); final SpanId newSpanId = clientTracer.startNewSpan(spanName); ClientRequestHeaders.addTracingHeaders(clientRequestAdapter, newSpanId, spanName); final Optional<String> serviceName = getServiceName(clientRequestAdapter, serviceNameOverride); if (serviceName.isPresent()) { clientTracer.setCurrentClientServiceName(serviceName.get()); } clientTracer.submitBinaryAnnotation(REQUEST_ANNOTATION, clientRequestAdapter.getMethod() + " " + clientRequestAdapter.getUri()); clientTracer.setClientSent(); }
/** * Interface method implementation. Performs client request tracing. * @see com.flipkart.phantom.task.spi.interceptor.RequestInterceptor#process(com.flipkart.phantom.task.spi.RequestWrapper) */ public void process(T request) { // we let trace filter decide if client request tracing is needed. Handler level config takes precedence even if global trace is on. for (final TraceFilter traceFilter : traceFilters) { if (!traceFilter.trace(request.getRequestName())) { return; } } ClientTracer clientTracer = Brave.getClientTracer(this.eventDispatchingSpanCollector, this.traceFilters); String spanName = this.getSpanName(request); SpanId newSpanId = clientTracer.startNewSpan(spanName); this.addTracingHeaders(request, newSpanId, spanName); if (request.getRequestContext().isPresent() && request.getRequestContext().get().getCurrentClientEndpoint() != null) { // override the service name with the value contained in the request clientTracer.setCurrentClientServiceName(request.getRequestContext().get().getCurrentClientEndpoint().getServiceName()); // submit an annotation so that host endpoint is visible in the span clientTracer.submitBinaryAnnotation(HOST_ANNOTATION, request.getRequestContext().get().getCurrentClientEndpoint().getHost() + ":" + request.getRequestContext().get().getCurrentClientEndpoint().getPort()); } final Optional<String> requestMetadata = request.getRequestMetaData(); if (requestMetadata.isPresent()) { clientTracer.submitBinaryAnnotation(REQUEST_ANNOTATION, requestMetadata.get()); } clientTracer.setClientSent(); }
@Override public void renderEnd(ExecuteContext ctx) { if (ctx.type() == ExecuteType.READ) { // Don't log writes (so as to not loop on collector) brave.clientTracer().startNewSpan("query"); brave.clientTracer().setCurrentClientServiceName("zipkin-query"); String[] batchSQL = ctx.batchSQL(); if (!StringUtils.isBlank(ctx.sql())) { brave.clientTracer().submitBinaryAnnotation("jdbc.query", ctx.sql()); } else if (batchSQL.length > 0 && batchSQL[batchSQL.length - 1] != null) { brave.clientTracer().submitBinaryAnnotation("jdbc.query", StringUtils.join(batchSQL, '\n')); } brave.clientTracer().setClientSent(jdbcEndpoint.ipv4, jdbcEndpoint.port, jdbcEndpoint.serviceName); } }
/** * Handles outgoing request. * * @param adapter The adapter deals with implementation specific details. */ public void handle(ClientRequestAdapter adapter) { SpanId spanId = clientTracer.startNewSpan(adapter.getSpanName()); if (spanId == null) { // We will not trace this request. adapter.addSpanIdToRequest(null); } else { adapter.addSpanIdToRequest(spanId); for (KeyValueAnnotation annotation : adapter.requestAnnotations()) { clientTracer.submitBinaryAnnotation(annotation.getKey(), annotation.getValue()); } recordClientSentAnnotations(adapter.serverAddress()); } }
/** * Handles outgoing request. * * @param adapter The adapter deals with implementation specific details. */ public void handle(ClientRequestAdapter adapter) { SpanId context = clientTracer.startNewSpan(adapter.getSpanName()); if (context == null) { // We will not trace this request. adapter.addSpanIdToRequest(null); } else { adapter.addSpanIdToRequest(context); for (KeyValueAnnotation annotation : adapter.requestAnnotations()) { clientTracer.submitBinaryAnnotation(annotation.getKey(), annotation.getValue()); } recordClientSentAnnotations(adapter.serverAddress()); } }