@Override public void submit() { Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_BATCH_SUBMIT); Scope scope = tracer.withSpan(span); try { span.putAttribute("batch size", AttributeValue.longAttributeValue(batches.size())); for (BatchRequest batch : batches) { // TODO(hailongwen@): instrument 'google-api-java-client' to further break down the span. // Here we only add a annotation to at least know how much time each batch takes. span.addAnnotation("Execute batch request"); batch.setBatchUrl( new GenericUrl(String.format("%s/batch/storage/v1", options.getHost()))); batch.execute(); } } catch (IOException ex) { span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage())); throw translate(ex); } finally { scope.close(); span.end(); } } }
@Test public void putAttributeCallsAddAttributesByDefault() { Span span = Mockito.spy(new NoopSpan(spanContext, spanOptions)); span.putAttribute("MyKey", AttributeValue.booleanAttributeValue(true)); span.end(); verify(span) .putAttributes( eq(Collections.singletonMap("MyKey", AttributeValue.booleanAttributeValue(true)))); }
private static void putAttributeIfNotEmptyOrNull(Span span, String key, @Nullable String value) { if (value != null && !value.isEmpty()) { span.putAttribute(key, AttributeValue.stringAttributeValue(value)); } }
/** {@inheritDoc} */ @Override public void batchRequestSent(long elementCount, long requestSize) { span.putAttribute("batch count", AttributeValue.longAttributeValue(elementCount)); span.putAttribute("batch size", AttributeValue.longAttributeValue(requestSize)); }
private static void putAttributeIfNotEmptyOrNull(Span span, String key, @Nullable String value) { if (value != null && !value.isEmpty()) { span.putAttribute(key, AttributeValue.stringAttributeValue(value)); } }
/** {@inheritDoc} */ @Override public void batchRequestSent(long elementCount, long requestSize) { span.putAttribute("batch count", AttributeValue.longAttributeValue(elementCount)); span.putAttribute("batch size", AttributeValue.longAttributeValue(requestSize)); }
private void verifyAttributes(String key) { verify(span).putAttribute(eq(key), attributeCaptor.capture()); AttributeValue attribute = attributeCaptor.getValue(); assertThat(attribute.toString()).contains(attributeMap.get(key)); }
void spanEnd(Span span, @Nullable P response, @Nullable Throwable error) { int statusCode = extractor.getStatusCode(response); if (span.getOptions().contains(Options.RECORD_EVENTS)) { span.putAttribute( HttpTraceAttributeConstants.HTTP_STATUS_CODE, AttributeValue.longAttributeValue(statusCode)); } span.setStatus(HttpTraceUtil.parseResponseStatus(statusCode, error)); span.end(); }
void spanEnd(Span span, @Nullable P response, @Nullable Throwable error) { int statusCode = extractor.getStatusCode(response); if (span.getOptions().contains(Options.RECORD_EVENTS)) { span.putAttribute( HttpTraceAttributeConstants.HTTP_STATUS_CODE, AttributeValue.longAttributeValue(statusCode)); } span.setStatus(HttpTraceUtil.parseResponseStatus(statusCode, error)); span.end(); }
public static <T> Middleware<AsyncHandler<Response<T>>, AsyncHandler<Response<T>>> tracer( Tracer tracer, String service) { return innerHandler -> requestContext -> { final Request request = requestContext.request(); final URI uri = URI.create(request.uri()); final Span span = tracer.spanBuilder(service + '/' + uri.getPath()).startSpan(); span.putAttribute("method", stringAttributeValue(request.method())); span.putAttribute("uri", stringAttributeValue(request.uri())); final CompletionStage<Response<T>> response; try { response = innerHandler.invoke(requestContext); } catch (Exception e) { span.setStatus(UNKNOWN); span.end(); Throwables.throwIfUnchecked(e); throw new RuntimeException(e); } response.whenComplete((r, ex) -> { if (ex != null) { span.setStatus(UNKNOWN); } span.end(); }); return response; }; }
@Override public void submit() { Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_BATCH_SUBMIT); Scope scope = tracer.withSpan(span); try { span.putAttribute("batch size", AttributeValue.longAttributeValue(batches.size())); for (BatchRequest batch : batches) { // TODO(hailongwen@): instrument 'google-api-java-client' to further break down the span. // Here we only add a annotation to at least know how much time each batch takes. span.addAnnotation("Execute batch request"); batch.setBatchUrl( new GenericUrl(String.format("%s/batch/storage/v1", options.getHost()))); batch.execute(); } } catch (IOException ex) { span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage())); throw translate(ex); } finally { scope.close(); span.end(); } } }
@Test public void testBatchExample() { tracer.batchRequestSent(100, 1000); tracer.attemptStarted(0); tracer.connectionSelected(1); tracer.attemptSucceeded(); tracer.operationSucceeded(); verify(span).putAttribute("batch count", AttributeValue.longAttributeValue(100)); verify(span).putAttribute("batch size", AttributeValue.longAttributeValue(1000)); }
tracer.getCurrentSpan().addAnnotation(START_PROCESSING_VIDEO); tracer.getCurrentSpan().putAttribute("foo", AttributeValue.stringAttributeValue("bar")); tracer.getCurrentSpan().addAnnotation(FINISHED_PROCESSING_VIDEO); } catch (Exception e) {
@Override public final void handle(HttpExchange httpExchange) throws IOException { Span span = tracer .spanBuilderWithExplicitParent(httpServerSpanName, null) .setRecordEvents(true) .startSpan(); try (Scope ss = tracer.withSpan(span)) { span.putAttribute( "/http/method ", AttributeValue.stringAttributeValue(httpExchange.getRequestMethod())); httpExchange.sendResponseHeaders(200, 0); zpageHandler.emitHtml( uriQueryToMap(httpExchange.getRequestURI()), httpExchange.getResponseBody()); } finally { httpExchange.close(); span.end(END_SPAN_OPTIONS); } }