Search in sources :

Example 16 with SuppressLogger

use of io.opentelemetry.internal.testing.slf4j.SuppressLogger in project opentelemetry-java by open-telemetry.

the class ConfigErrorTest method globalOpenTelemetryWhenError.

@Test
@SetSystemProperty(key = "otel.traces.sampler", value = "traceidratio")
@SetSystemProperty(key = "otel.traces.sampler.arg", value = "bar")
@SuppressLogger(GlobalOpenTelemetry.class)
void globalOpenTelemetryWhenError() {
    assertThat(GlobalOpenTelemetry.get()).isInstanceOf(OpenTelemetry.class).extracting("propagators").isEqualTo(ContextPropagators.noop());
    LoggingEvent log = logs.assertContains("Error automatically configuring OpenTelemetry SDK. " + "OpenTelemetry will not be enabled.");
    assertThat(log.getLevel()).isEqualTo(Level.ERROR);
    assertThat(log.getThrowable()).isInstanceOf(ConfigurationException.class);
}
Also used : LoggingEvent(org.slf4j.event.LoggingEvent) SuppressLogger(io.opentelemetry.internal.testing.slf4j.SuppressLogger) SetSystemProperty(org.junitpioneer.jupiter.SetSystemProperty) Test(org.junit.jupiter.api.Test)

Example 17 with SuppressLogger

use of io.opentelemetry.internal.testing.slf4j.SuppressLogger in project opentelemetry-java by open-telemetry.

the class AbstractGrpcTelemetryExporterTest method errorWithEscapedMessage.

@Test
@SuppressLogger(OkHttpGrpcExporter.class)
@SuppressLogger(DefaultGrpcExporter.class)
void errorWithEscapedMessage() {
    addGrpcError(5, "クマ🐻");
    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 5. 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 18 with SuppressLogger

use of io.opentelemetry.internal.testing.slf4j.SuppressLogger in project opentelemetry-java by open-telemetry.

the class AbstractGrpcTelemetryExporterTest method testExport_Unimplemented.

@Test
@SuppressLogger(OkHttpGrpcExporter.class)
@SuppressLogger(DefaultGrpcExporter.class)
void testExport_Unimplemented() {
    addGrpcError(12, "UNIMPLEMENTED");
    assertThat(exporter.export(Collections.singletonList(generateFakeTelemetry())).join(10, TimeUnit.SECONDS).isSuccess()).isFalse();
    LoggingEvent log = logs.assertContains("Failed to export " + type + "s. Server responded with UNIMPLEMENTED. " + "This usually means that your collector is not configured with an otlp " + "receiver in the \"pipelines\" section of the configuration. " + "Full error message: UNIMPLEMENTED");
    assertThat(log.getLevel()).isEqualTo(Level.ERROR);
}
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 19 with SuppressLogger

use of io.opentelemetry.internal.testing.slf4j.SuppressLogger in project opentelemetry-java by open-telemetry.

the class AbstractGrpcTelemetryExporterTest method testExport_Unavailable.

@Test
@SuppressLogger(OkHttpGrpcExporter.class)
@SuppressLogger(DefaultGrpcExporter.class)
void testExport_Unavailable() {
    addGrpcError(14, null);
    assertThat(exporter.export(Collections.singletonList(generateFakeTelemetry())).join(10, TimeUnit.SECONDS).isSuccess()).isFalse();
    LoggingEvent log = logs.assertContains("Failed to export " + type + "s. Server is UNAVAILABLE. " + "Make sure your collector is running and reachable from this network.");
    assertThat(log.getLevel()).isEqualTo(Level.ERROR);
}
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 20 with SuppressLogger

use of io.opentelemetry.internal.testing.slf4j.SuppressLogger in project opentelemetry-java by open-telemetry.

the class ZipkinSpanExporterTest method testExport_failed.

@Test
@SuppressLogger(ZipkinSpanExporter.class)
void testExport_failed() {
    ZipkinSpanExporter zipkinSpanExporter = new ZipkinSpanExporter(mockEncoder, mockSender);
    byte[] someBytes = new byte[0];
    when(mockEncoder.encode(standardZipkinSpanBuilder(Span.Kind.SERVER).putTag(ZipkinSpanExporter.OTEL_STATUS_CODE, "OK").build())).thenReturn(someBytes);
    when(mockSender.sendSpans(Collections.singletonList(someBytes))).thenReturn(mockZipkinCall);
    doAnswer(invocation -> {
        Callback<Void> callback = invocation.getArgument(0);
        callback.onError(new IOException());
        return null;
    }).when(mockZipkinCall).enqueue(any());
    CompletableResultCode resultCode = zipkinSpanExporter.export(Collections.singleton(buildStandardSpan().build()));
    assertThat(resultCode.isSuccess()).isFalse();
}
Also used : CompletableResultCode(io.opentelemetry.sdk.common.CompletableResultCode) IOException(java.io.IOException) 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