com.google.devtools.cloudtrace.v2.BatchWriteSpansRequest Java Examples
The following examples show how to use
com.google.devtools.cloudtrace.v2.BatchWriteSpansRequest.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AsyncReporterStackdriverSenderTest.java From zipkin-gcp with Apache License 2.0 | 6 votes |
@Test public void sendSpans() { onClientCall( observer -> { observer.onNext(Empty.getDefaultInstance()); observer.onCompleted(); }); reporter.report(TestObjects.CLIENT_SPAN); reporter.flush(); ArgumentCaptor<BatchWriteSpansRequest> requestCaptor = ArgumentCaptor.forClass(BatchWriteSpansRequest.class); verify(traceService).batchWriteSpans(requestCaptor.capture(), any()); BatchWriteSpansRequest request = requestCaptor.getValue(); assertThat(request.getName()).isEqualTo("projects/" + projectId); assertThat(request.getSpansList()).containsExactlyElementsOf( SpanTranslator.translate(projectId, asList(TestObjects.CLIENT_SPAN))); }
Example #2
Source File: UnaryClientCallTest.java From zipkin-gcp with Apache License 2.0 | 6 votes |
@Test(expected = IllegalStateException.class) public void execute_timeout() throws Throwable { long overriddenTimeout = 50; call = new BatchWriteSpansCall(server.getChannel(), BatchWriteSpansRequest.newBuilder().build(), overriddenTimeout); onClientCall( observer -> Executors.newSingleThreadExecutor().submit(() -> { try { Thread.sleep(overriddenTimeout + 10); } catch (InterruptedException e) {} observer.onCompleted(); })); call.execute(); }
Example #3
Source File: StackdriverSenderTest.java From zipkin-gcp with Apache License 2.0 | 6 votes |
void verifyRequestSent(List<Span> spans) throws IOException { onClientCall( observer -> { observer.onNext(Empty.getDefaultInstance()); observer.onCompleted(); }); List<byte[]> encodedSpans = spans.stream().map(StackdriverEncoder.V2::encode).collect(Collectors.toList()); sender.sendSpans(encodedSpans).execute(); BatchWriteSpansRequest request = takeRequest(); List<com.google.devtools.cloudtrace.v2.Span> translated = SpanTranslator.translate(projectId, spans); // sanity check the data assertThat(request.getSpansList()).containsExactlyElementsOf(translated); // verify our estimate is correct int actualSize = request.getSerializedSize(); assertThat(sender.messageSizeInBytes(encodedSpans)).isEqualTo(actualSize); }
Example #4
Source File: StackdriverSpanConsumerTest.java From zipkin-gcp with Apache License 2.0 | 6 votes |
@Test public void accept() throws Exception { onClientCall( observer -> { observer.onNext(Empty.getDefaultInstance()); observer.onCompleted(); }); spanConsumer.accept(asList(TestObjects.CLIENT_SPAN)).execute(); ArgumentCaptor<BatchWriteSpansRequest> requestCaptor = ArgumentCaptor.forClass(BatchWriteSpansRequest.class); verify(traceService).batchWriteSpans(requestCaptor.capture(), any()); BatchWriteSpansRequest request = requestCaptor.getValue(); assertThat(request.getName()).isEqualTo("projects/" + projectId); assertThat(request.getSpansList()) .isEqualTo(SpanTranslator.translate(projectId, asList(TestObjects.CLIENT_SPAN))); }
Example #5
Source File: StackdriverSender.java From zipkin-gcp with Apache License 2.0 | 6 votes |
StackdriverSender(Builder builder) { channel = builder.channel; callOptions = builder.callOptions; projectName = ByteString.copyFromUtf8("projects/" + builder.projectId); serverResponseTimeoutMs = builder.serverResponseTimeoutMs; traceIdPrefix = projectName.concat(ByteString.copyFromUtf8("/traces/")); shutdownChannelOnClose = builder.shutdownChannelOnClose; projectNameFieldSize = CodedOutputStream.computeBytesSize(1, projectName); // The size of the contents of the Span.name field, used to preallocate the correct sized // buffer when computing Span.name. spanNameSize = traceIdPrefix.size() + 32 + SPAN_ID_PREFIX.size() + 16; spanNameFieldSize = CodedOutputStream.computeTagSize(1) + CodedOutputStream.computeUInt32SizeNoTag(spanNameSize) + spanNameSize; BatchWriteSpansRequest healthcheckRequest = BatchWriteSpansRequest.newBuilder() .setNameBytes(projectName) .addSpans(Span.newBuilder().build()) .build(); healthcheckCall = new BatchWriteSpansCall(healthcheckRequest); }
Example #6
Source File: StackdriverSender.java From zipkin-gcp with Apache License 2.0 | 5 votes |
@Override public Call<Void> sendSpans(List<byte[]> traceIdPrefixedSpans) { if (closeCalled) throw new IllegalStateException("closed"); int length = traceIdPrefixedSpans.size(); if (length == 0) return Call.create(null); BatchWriteSpansRequest.Builder request = BatchWriteSpansRequest.newBuilder() .setNameBytes(projectName); for (byte[] traceIdPrefixedSpan : traceIdPrefixedSpans) { request.addSpans(parseTraceIdPrefixedSpan(traceIdPrefixedSpan, spanNameSize, traceIdPrefix)); } return new BatchWriteSpansCall(request.build()).map(EmptyToVoid.INSTANCE); }
Example #7
Source File: UnaryClientCallTest.java From zipkin-gcp with Apache License 2.0 | 5 votes |
void verifyPatchRequestSent() { ArgumentCaptor<BatchWriteSpansRequest> requestCaptor = ArgumentCaptor.forClass(BatchWriteSpansRequest.class); verify(traceService).batchWriteSpans(requestCaptor.capture(), any()); BatchWriteSpansRequest request = requestCaptor.getValue(); assertThat(request).isEqualTo(BatchWriteSpansRequest.getDefaultInstance()); }
Example #8
Source File: StackdriverSenderTest.java From zipkin-gcp with Apache License 2.0 | 5 votes |
BatchWriteSpansRequest takeRequest() { ArgumentCaptor<BatchWriteSpansRequest> requestCaptor = ArgumentCaptor.forClass(BatchWriteSpansRequest.class); verify(traceService).batchWriteSpans(requestCaptor.capture(), any()); return requestCaptor.getValue(); }
Example #9
Source File: StackdriverReporter.java From curiostack with MIT License | 5 votes |
@Override public void flush() { List<Span> spans = new ArrayList<>(queue.size()); queue.drain(spans::add); if (spans.isEmpty()) { return; } List<com.google.devtools.cloudtrace.v2.Span> translated = SpanTranslator.translate(projectId, spans); BatchWriteSpansRequest request = BatchWriteSpansRequest.newBuilder() .setName("projects/" + projectId) .addAllSpans(translated) .build(); Futures.addCallback( traceServiceClient.get().batchWriteSpans(request), new FutureCallback<Empty>() { @Override public void onFailure(Throwable t) { logger.warn("Error reporting traces.", t); } @Override public void onSuccess(Empty result) { logger.trace("Successfully reported traces."); } }, MoreExecutors.directExecutor()); }
Example #10
Source File: StackdriverStorage.java From zipkin-gcp with Apache License 2.0 | 5 votes |
StackdriverStorage(Builder builder, UnaryGrpcClient grpcClient) { this.grpcClient = grpcClient; projectId = builder.projectId; BatchWriteSpansRequest healthcheckRequest = BatchWriteSpansRequest.newBuilder() .setName("projects/" + builder.projectId) .build(); healthcheckCall = new BatchWriteSpansCall(grpcClient, healthcheckRequest); }
Example #11
Source File: StackdriverSpanConsumer.java From zipkin-gcp with Apache License 2.0 | 5 votes |
@Override public Call<Void> accept(List<Span> spans) { if (spans.isEmpty()) return Call.create(null); List<com.google.devtools.cloudtrace.v2.Span> stackdriverSpans = SpanTranslator.translate(projectId, spans); BatchWriteSpansRequest request = BatchWriteSpansRequest.newBuilder() .setName(projectName) .addAllSpans(stackdriverSpans) .build(); return new BatchWriteSpansCall(grpcClient, request); }
Example #12
Source File: StackdriverMockServer.java From zipkin-gcp with Apache License 2.0 | 5 votes |
@Override public void batchWriteSpans(BatchWriteSpansRequest request, StreamObserver<Empty> responseObserver) { final List<Span> spansList = request.getSpansList(); for (Span span : spansList) { spanIds.add(span.getSpanId()); spanCountdown.countDown(); } responseObserver.onNext(Empty.getDefaultInstance()); responseObserver.onCompleted(); }
Example #13
Source File: ZipkinStackdriverStorageIntegrationTest.java From zipkin-gcp with Apache License 2.0 | 5 votes |
@Test public void mockGrpcServerServesOverSSL() { // sanity checks the mock server TraceServiceGrpc.TraceServiceBlockingStub sslTraceService = Clients.builder("gproto+https://" + mockServer.grpcURI() + "/") .factory(ClientFactory.builder() .tlsCustomizer(tls -> tls.trustManager(InsecureTrustManagerFactory.INSTANCE)) .build()) .build(TraceServiceGrpc.TraceServiceBlockingStub.class); sslTraceService.batchWriteSpans(BatchWriteSpansRequest.getDefaultInstance()); }
Example #14
Source File: StackdriverTraceAutoConfigurationTests.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
@Override public void batchWriteSpans(BatchWriteSpansRequest request, StreamObserver<Empty> responseObserver) { request.getSpansList().forEach((span) -> this.traces.put(span.getSpanId(), span)); responseObserver.onNext(Empty.getDefaultInstance()); responseObserver.onCompleted(); }
Example #15
Source File: StackdriverSender.java From zipkin-gcp with Apache License 2.0 | 4 votes |
BatchWriteSpansCall(BatchWriteSpansRequest request) { super(channel, TraceServiceGrpc.getBatchWriteSpansMethod(), callOptions, request, serverResponseTimeoutMs); }
Example #16
Source File: StackdriverSpanConsumer.java From zipkin-gcp with Apache License 2.0 | 4 votes |
BatchWriteSpansCall(UnaryGrpcClient grpcClient, BatchWriteSpansRequest request) { this.grpcClient = grpcClient; this.request = request; }
Example #17
Source File: UnaryClientCallTest.java From zipkin-gcp with Apache License 2.0 | 4 votes |
BatchWriteSpansCall(Channel channel, BatchWriteSpansRequest request, long serverResponseTimeout) { super(channel, TraceServiceGrpc.getBatchWriteSpansMethod(), DEFAULT, request, serverResponseTimeout); this.channel = channel; }
Example #18
Source File: UnaryClientCallTest.java From zipkin-gcp with Apache License 2.0 | 4 votes |
@Before public void setUp() { server.getServiceRegistry().addService(traceService); call = new BatchWriteSpansCall(server.getChannel(), BatchWriteSpansRequest.newBuilder().build(), DEFAULT_SERVER_TIMEOUT_MS); }