public void stopClientTracer() { if (enabled) { clientTracer.setClientReceived(); } } public void startServerTracer(String contextPath) throws Exception
public void startClientTracer(String clientContext) { if (enabled) { clientTracer.startNewSpan(clientContext); clientTracer.submitBinaryAnnotation(REQUEST_ANNOTATION, clientContext); clientTracer.setClientSent(); } } public void stopClientTracer()
public void submitFailure() { if (enabled) { clientTracer.submitAnnotation(FAILURE_ANNOTATION); } }
/** * Like {@link #setClientSent()}, except you can log the network context of the destination. * * @param server represents the server (peer). Set {@link Endpoint#service_name} to * "unknown" if unknown. */ public void setClientSent(Endpoint server) { submitAddress("sa", server); submitStartAnnotation("cs"); }
/** * Sets the 'client received' event for current thread. This will also submit span because setting a client received * event means this span is finished. */ public void setClientReceived() { if (submitEndAnnotation("cr")) { currentSpan().setCurrentSpan(null); } }
/** * 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(); }
/** * 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(); } } }
/** * 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 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()); } }
private void recordClientSentAnnotations(Endpoint serverAddress) { if (serverAddress == null) { clientTracer.setClientSent(); } else { clientTracer.setClientSent(serverAddress); } } }
public void submitBinaryAnnotation(String name, String value) { if (enabled) { clientTracer.submitBinaryAnnotation(name, value); } } public void submitAnnotation(String name, String value)
/** * Sets the 'client received' event for current thread. This will also submit span because setting a client received * event means this span is finished. */ public void setClientReceived() { if (submitEndAnnotation(zipkinCoreConstants.CLIENT_RECV, spanCollector())) { spanAndEndpoint().state().setCurrentClientSpan(null); } }
/** * Sets 'client sent' event for current thread. */ public void setClientSent() { submitStartAnnotation(zipkinCoreConstants.CLIENT_SEND); }
@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); } }
/** * 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(); } } }
/** * 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()); } }
private void recordClientSentAnnotations(Endpoint serverAddress) { if (serverAddress == null) { clientTracer.setClientSent(); } else { clientTracer.setClientSent(serverAddress.ipv4, serverAddress.port, serverAddress.service_name); } } }
public void submitBinaryAnnotation(String name, int value) { if (enabled) { clientTracer.submitBinaryAnnotation(name, value); } } public void submitBinaryAnnotation(String name, String value)
/** * Like {@link #setClientSent()}, except you can log the network context of the destination. * * @param ipv4 ipv4 of the server as an int. Ex for 1.2.3.4, it would be (1 << 24) | (2 << 16) | (3 << 8) | 4 * @param port listen port the client is connecting to, or 0 if unknown * @param serviceName lowercase {@link Endpoint#service_name name} of the service being called * or null if unknown */ public void setClientSent(int ipv4, int port, @Nullable String serviceName) { submitAddress(zipkinCoreConstants.SERVER_ADDR, ipv4, port, serviceName); submitStartAnnotation(zipkinCoreConstants.CLIENT_SEND); }