use of io.opentelemetry.internal.testing.slf4j.SuppressLogger in project opentelemetry-java by open-telemetry.
the class AbstractGrpcTelemetryExporterTest method errorWithMessage.
@Test
@SuppressLogger(OkHttpGrpcExporter.class)
@SuppressLogger(DefaultGrpcExporter.class)
void errorWithMessage() {
addGrpcError(8, "out of quota");
assertThat(exporter.export(Collections.singletonList(generateFakeTelemetry())).join(10, TimeUnit.SECONDS).isSuccess()).isFalse();
LoggingEvent log = logs.assertContains("Failed to export " + type + "s. Server responded with gRPC status code 8. Error message: out of quota");
assertThat(log.getLevel()).isEqualTo(Level.WARN);
}
use of io.opentelemetry.internal.testing.slf4j.SuppressLogger in project opentelemetry-java by open-telemetry.
the class AbstractGrpcTelemetryExporterTest method error.
@Test
@SuppressLogger(OkHttpGrpcExporter.class)
@SuppressLogger(DefaultGrpcExporter.class)
void error() {
addGrpcError(13, null);
assertThat(exporter.export(Collections.singletonList(generateFakeTelemetry())).join(10, TimeUnit.SECONDS).isSuccess()).isFalse();
LoggingEvent log = logs.assertContains("Failed to export " + type + "s. Server responded with gRPC status code 13. Error message:");
assertThat(log.getLevel()).isEqualTo(Level.WARN);
}
use of io.opentelemetry.internal.testing.slf4j.SuppressLogger in project opentelemetry-java by open-telemetry.
the class TraceConfigzZPageHandlerTest method applyChanges_emitErrorOnInvalidInput.
@Test
@SuppressLogger(TraceConfigzZPageHandler.class)
void applyChanges_emitErrorOnInvalidInput() {
// Invalid samplingProbability (not type of double)
OutputStream output = new ByteArrayOutputStream();
TraceConfigzZPageHandler traceConfigzZPageHandler = new TraceConfigzZPageHandler(configSupplier);
Map<String, String> queryMap = ImmutableMap.of("action", "change", "samplingprobability", "invalid");
traceConfigzZPageHandler.processRequest("POST", queryMap, output);
assertThat(output.toString()).contains("Error while applying trace config changes: ");
assertThat(output.toString()).contains("SamplingProbability must be of the type double");
// Invalid samplingProbability (< 0)
output = new ByteArrayOutputStream();
traceConfigzZPageHandler = new TraceConfigzZPageHandler(configSupplier);
queryMap = ImmutableMap.of("action", "change", "samplingprobability", "-1");
traceConfigzZPageHandler.processRequest("POST", queryMap, output);
assertThat(output.toString()).contains("Error while applying trace config changes: ");
assertThat(output.toString()).contains("ratio must be in range [0.0, 1.0]");
// Invalid samplingProbability (> 1)
output = new ByteArrayOutputStream();
traceConfigzZPageHandler = new TraceConfigzZPageHandler(configSupplier);
queryMap = ImmutableMap.of("action", "change", "samplingprobability", "1.1");
traceConfigzZPageHandler.processRequest("POST", queryMap, output);
assertThat(output.toString()).contains("Error while applying trace config changes: ");
assertThat(output.toString()).contains("ratio must be in range [0.0, 1.0]");
// Invalid maxNumOfAttributes
output = new ByteArrayOutputStream();
traceConfigzZPageHandler = new TraceConfigzZPageHandler(configSupplier);
queryMap = ImmutableMap.of("action", "change", "maxnumofattributes", "invalid");
traceConfigzZPageHandler.processRequest("POST", queryMap, output);
assertThat(output.toString()).contains("Error while applying trace config changes: ");
assertThat(output.toString()).contains("MaxNumOfAttributes must be of the type integer");
// Invalid maxNumOfEvents
output = new ByteArrayOutputStream();
traceConfigzZPageHandler = new TraceConfigzZPageHandler(configSupplier);
queryMap = ImmutableMap.of("action", "change", "maxnumofevents", "invalid");
traceConfigzZPageHandler.processRequest("POST", queryMap, output);
assertThat(output.toString()).contains("Error while applying trace config changes: ");
assertThat(output.toString()).contains("MaxNumOfEvents must be of the type integer");
// Invalid maxNumLinks
output = new ByteArrayOutputStream();
traceConfigzZPageHandler = new TraceConfigzZPageHandler(configSupplier);
queryMap = ImmutableMap.of("action", "change", "maxnumoflinks", "invalid");
traceConfigzZPageHandler.processRequest("POST", queryMap, output);
assertThat(output.toString()).contains("Error while applying trace config changes: ");
assertThat(output.toString()).contains("MaxNumOfLinks must be of the type integer");
// Invalid maxNumOfAttributesPerEvent
output = new ByteArrayOutputStream();
traceConfigzZPageHandler = new TraceConfigzZPageHandler(configSupplier);
queryMap = ImmutableMap.of("action", "change", "maxnumofattributesperevent", "invalid");
traceConfigzZPageHandler.processRequest("POST", queryMap, output);
assertThat(output.toString()).contains("Error while applying trace config changes: ");
assertThat(output.toString()).contains("MaxNumOfAttributesPerEvent must be of the type integer");
// Invalid maxNumOfAttributesPerLink
output = new ByteArrayOutputStream();
traceConfigzZPageHandler = new TraceConfigzZPageHandler(configSupplier);
queryMap = ImmutableMap.of("action", "change", "maxnumofattributesperlink", "invalid");
traceConfigzZPageHandler.processRequest("POST", queryMap, output);
assertThat(output.toString()).contains("Error while applying trace config changes: ");
assertThat(output.toString()).contains("MaxNumOfAttributesPerLink must be of the type integer");
}
use of io.opentelemetry.internal.testing.slf4j.SuppressLogger in project opentelemetry-java by open-telemetry.
the class BatchLogProcessorTest method exporterThrowsException.
@Test
@SuppressLogger(MultiLogExporter.class)
void exporterThrowsException() {
WaitingLogExporter waitingLogExporter = new WaitingLogExporter(1, CompletableResultCode.ofSuccess());
doThrow(new IllegalArgumentException("No export for you.")).when(mockLogExporter).export(anyList());
SdkLogEmitterProvider sdkLogEmitterProvider = SdkLogEmitterProvider.builder().addLogProcessor(BatchLogProcessor.builder(LogExporter.composite(Arrays.asList(mockLogExporter, waitingLogExporter))).setScheduleDelay(MAX_SCHEDULE_DELAY_MILLIS, TimeUnit.MILLISECONDS).build()).build();
emitLog(sdkLogEmitterProvider, LOG_MESSAGE_1);
List<LogData> exported = waitingLogExporter.waitForExport();
assertThat(exported).satisfiesExactly(logData -> assertThat(logData).hasBody(LOG_MESSAGE_1));
waitingLogExporter.reset();
// Continue to export after the exception was received.
emitLog(sdkLogEmitterProvider, LOG_MESSAGE_2);
exported = waitingLogExporter.waitForExport();
assertThat(exported).satisfiesExactly(logData -> assertThat(logData).hasBody(LOG_MESSAGE_2));
}
use of io.opentelemetry.internal.testing.slf4j.SuppressLogger in project opentelemetry-java by open-telemetry.
the class BatchSpanProcessorTest method exporterThrowsException.
@Test
@SuppressLogger(MultiSpanExporter.class)
void exporterThrowsException() {
WaitingSpanExporter waitingSpanExporter = new WaitingSpanExporter(1, CompletableResultCode.ofSuccess());
doThrow(new IllegalArgumentException("No export for you.")).when(mockSpanExporter).export(ArgumentMatchers.anyList());
sdkTracerProvider = SdkTracerProvider.builder().addSpanProcessor(BatchSpanProcessor.builder(SpanExporter.composite(Arrays.asList(mockSpanExporter, waitingSpanExporter))).setScheduleDelay(MAX_SCHEDULE_DELAY_MILLIS, TimeUnit.MILLISECONDS).build()).build();
ReadableSpan span1 = createEndedSpan(SPAN_NAME_1);
List<SpanData> exported = waitingSpanExporter.waitForExport();
assertThat(exported).containsExactly(span1.toSpanData());
waitingSpanExporter.reset();
// Continue to export after the exception was received.
ReadableSpan span2 = createEndedSpan(SPAN_NAME_2);
exported = waitingSpanExporter.waitForExport();
assertThat(exported).containsExactly(span2.toSpanData());
}
Aggregations