@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(request).map(EmptyToVoid.INSTANCE); }
/** * Sends new spans to new or existing traces. You cannot update existing spans. * * <p>Sample code: * * <pre><code> * try (TraceServiceClient traceServiceClient = TraceServiceClient.create()) { * ProjectName name = ProjectName.of("[PROJECT]"); * List<Span> spans = new ArrayList<>(); * traceServiceClient.batchWriteSpans(name, spans); * } * </code></pre> * * @param name Required. The name of the project where the spans belong. The format is * `projects/[PROJECT_ID]`. * @param spans A list of new spans. The span names must not match existing spans, or the results * are undefined. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final void batchWriteSpans(ProjectName name, List<Span> spans) { BatchWriteSpansRequest request = BatchWriteSpansRequest.newBuilder() .setName(name == null ? null : name.toString()) .addAllSpans(spans) .build(); batchWriteSpans(request); }
/** * Sends new spans to new or existing traces. You cannot update existing spans. * * <p>Sample code: * * <pre><code> * try (TraceServiceClient traceServiceClient = TraceServiceClient.create()) { * ProjectName name = ProjectName.of("[PROJECT]"); * List<Span> spans = new ArrayList<>(); * traceServiceClient.batchWriteSpans(name.toString(), spans); * } * </code></pre> * * @param name Required. The name of the project where the spans belong. The format is * `projects/[PROJECT_ID]`. * @param spans A list of new spans. The span names must not match existing spans, or the results * are undefined. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final void batchWriteSpans(String name, List<Span> spans) { BatchWriteSpansRequest request = BatchWriteSpansRequest.newBuilder().setName(name).addAllSpans(spans).build(); batchWriteSpans(request); }