Search in sources :

Example 11 with SuppressLogger

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);
}
Also used : LoggingEvent(org.slf4j.event.LoggingEvent) SuppressLogger(io.opentelemetry.internal.testing.slf4j.SuppressLogger) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with SuppressLogger

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);
}
Also used : LoggingEvent(org.slf4j.event.LoggingEvent) SuppressLogger(io.opentelemetry.internal.testing.slf4j.SuppressLogger) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with SuppressLogger

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");
}
Also used : OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SuppressLogger(io.opentelemetry.internal.testing.slf4j.SuppressLogger) Test(org.junit.jupiter.api.Test)

Example 14 with SuppressLogger

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));
}
Also used : LogData(io.opentelemetry.sdk.logs.data.LogData) SdkLogEmitterProvider(io.opentelemetry.sdk.logs.SdkLogEmitterProvider) SuppressLogger(io.opentelemetry.internal.testing.slf4j.SuppressLogger) Test(org.junit.jupiter.api.Test)

Example 15 with SuppressLogger

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());
}
Also used : SpanData(io.opentelemetry.sdk.trace.data.SpanData) ReadableSpan(io.opentelemetry.sdk.trace.ReadableSpan) SuppressLogger(io.opentelemetry.internal.testing.slf4j.SuppressLogger) Test(org.junit.jupiter.api.Test)

Aggregations

SuppressLogger (io.opentelemetry.internal.testing.slf4j.SuppressLogger)32 Test (org.junit.jupiter.api.Test)32 LoggingEvent (org.slf4j.event.LoggingEvent)11 HashMap (java.util.HashMap)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 Attributes (io.opentelemetry.api.common.Attributes)3 ResourceAttributes (io.opentelemetry.semconv.resource.attributes.ResourceAttributes)3 DoubleHistogram (io.opentelemetry.api.metrics.DoubleHistogram)2 LongCounter (io.opentelemetry.api.metrics.LongCounter)2 LongHistogram (io.opentelemetry.api.metrics.LongHistogram)2 CompletableResultCode (io.opentelemetry.sdk.common.CompletableResultCode)2 LogData (io.opentelemetry.sdk.logs.data.LogData)2 LogExporter (io.opentelemetry.sdk.logs.export.LogExporter)2 MetricExporter (io.opentelemetry.sdk.metrics.export.MetricExporter)2 BoundDoubleHistogram (io.opentelemetry.sdk.metrics.internal.instrument.BoundDoubleHistogram)2 BoundLongCounter (io.opentelemetry.sdk.metrics.internal.instrument.BoundLongCounter)2 BoundLongHistogram (io.opentelemetry.sdk.metrics.internal.instrument.BoundLongHistogram)2 SpanExporter (io.opentelemetry.sdk.trace.export.SpanExporter)2 File (java.io.File)2 AggregatedHttpRequest (com.linecorp.armeria.common.AggregatedHttpRequest)1