use of io.opentelemetry.sdk.common.CompletableResultCode in project opentelemetry-java by open-telemetry.
the class SystemOutLogExporterTest method returnCodes.
@Test
void returnCodes() {
SystemOutLogExporter exporter = SystemOutLogExporter.create();
CompletableResultCode resultCode = exporter.export(singletonList(sampleLog(System.currentTimeMillis())));
assertThat(resultCode).isSameAs(CompletableResultCode.ofSuccess());
assertThat(exporter.shutdown()).isSameAs(CompletableResultCode.ofSuccess());
}
use of io.opentelemetry.sdk.common.CompletableResultCode in project opentelemetry-java by open-telemetry.
the class OtlpHttpLogExporterTest method exportAndAssertResult.
private static ExportLogsServiceRequest exportAndAssertResult(OtlpHttpLogExporter otlpHttpLogExporter, boolean expectedResult) {
List<LogData> logs = Collections.singletonList(generateFakeLog());
CompletableResultCode resultCode = otlpHttpLogExporter.export(logs);
resultCode.join(10, TimeUnit.SECONDS);
assertThat(resultCode.isSuccess()).isEqualTo(expectedResult);
List<ResourceLogs> resourceLogs = Arrays.stream(ResourceLogsMarshaler.create(logs)).map(marshaler -> {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
marshaler.writeBinaryTo(bos);
return ResourceLogs.parseFrom(bos.toByteArray());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}).collect(Collectors.toList());
return ExportLogsServiceRequest.newBuilder().addAllResourceLogs(resourceLogs).build();
}
use of io.opentelemetry.sdk.common.CompletableResultCode in project opentelemetry-java by open-telemetry.
the class JaegerGrpcSpanExporterTest method testExport.
@Test
void testExport() throws Exception {
// ms
long duration = 900;
long startMs = System.currentTimeMillis();
long endMs = startMs + duration;
SpanData span = TestSpanData.builder().setHasEnded(true).setSpanContext(SpanContext.create(TRACE_ID, SPAN_ID, TraceFlags.getSampled(), TraceState.getDefault())).setName("GET /api/endpoint").setStartEpochNanos(TimeUnit.MILLISECONDS.toNanos(startMs)).setEndEpochNanos(TimeUnit.MILLISECONDS.toNanos(endMs)).setStatus(StatusData.ok()).setKind(SpanKind.CONSUMER).setLinks(Collections.emptyList()).setTotalRecordedLinks(0).setTotalRecordedEvents(0).setInstrumentationLibraryInfo(InstrumentationLibraryInfo.create("io.opentelemetry.auto", "1.0.0")).setResource(Resource.create(Attributes.of(ResourceAttributes.SERVICE_NAME, "myServiceName", AttributeKey.stringKey("resource-attr-key"), "resource-attr-value"))).build();
// test
CompletableResultCode result = exporter.export(Collections.singletonList(span));
result.join(10, TimeUnit.SECONDS);
assertThat(result.isSuccess()).isEqualTo(true);
// verify
assertThat(postedRequests).hasSize(1);
Model.Batch batch = postedRequests.poll().getBatch();
assertThat(batch.getSpans(0).getOperationName()).isEqualTo("GET /api/endpoint");
assertThat(SpanId.fromBytes(batch.getSpans(0).getSpanId().toByteArray())).isEqualTo(SPAN_ID);
assertThat(getTagValue(batch.getProcess().getTagsList(), "resource-attr-key").orElseThrow(() -> new AssertionError("resource-attr-key not found")).getVStr()).isEqualTo("resource-attr-value");
verifyBatch(batch);
assertThat(batch.getProcess().getServiceName()).isEqualTo("myServiceName");
}
use of io.opentelemetry.sdk.common.CompletableResultCode in project opentelemetry-java by open-telemetry.
the class JaegerThriftSpanExporter method export.
/**
* Submits all the given spans in a single batch to the Jaeger collector.
*
* @param spans the list of sampled Spans to be exported.
* @return the result of the operation
*/
@Override
public CompletableResultCode export(Collection<SpanData> spans) {
Map<Process, List<Span>> batches = spans.stream().collect(Collectors.groupingBy(SpanData::getResource)).entrySet().stream().collect(Collectors.toMap(entry -> createProcess(entry.getKey()), entry -> Adapter.toJaeger(entry.getValue())));
List<CompletableResultCode> batchResults = new ArrayList<>(batches.size());
batches.forEach((process, jaegerSpans) -> {
CompletableResultCode batchResult = new CompletableResultCode();
batchResults.add(batchResult);
try {
// todo: consider making truly async
thriftSender.send(process, jaegerSpans);
batchResult.succeed();
} catch (SenderException e) {
logger.log(Level.WARNING, "Failed to export spans", e);
batchResult.fail();
}
});
return CompletableResultCode.ofAll(batchResults);
}
use of io.opentelemetry.sdk.common.CompletableResultCode in project opentelemetry-java by open-telemetry.
the class OtlpGrpcRetryTest method testRetryableStatusCodes.
private static <T> void testRetryableStatusCodes(Supplier<T> dataSupplier, Function<T, CompletableResultCode> exporter, Supplier<Integer> serverRequestCountSupplier) {
for (Status.Code code : Status.Code.values()) {
server.reset();
server.responseStatuses.add(Status.fromCode(code));
server.responseStatuses.add(Status.OK);
CompletableResultCode resultCode = exporter.apply(dataSupplier.get()).join(10, TimeUnit.SECONDS);
boolean retryable = RetryUtil.retryableGrpcStatusCodes().contains(String.valueOf(code.value()));
boolean expectedResult = retryable || code == Status.Code.OK;
assertThat(resultCode.isSuccess()).as("status code %s should export %s", code, expectedResult ? "successfully" : "unsuccessfully").isEqualTo(expectedResult);
int expectedRequests = retryable ? 2 : 1;
assertThat(serverRequestCountSupplier.get()).as("status code %s should make %s requests", code, expectedRequests).isEqualTo(expectedRequests);
}
}
Aggregations