Search in sources :

Example 31 with LogData

use of io.opentelemetry.sdk.logs.data.LogData in project opentelemetry-java by open-telemetry.

the class SimpleLogProcessorTest method addLogRecord_ExporterError.

@Test
@SuppressLogger(SimpleLogProcessor.class)
void addLogRecord_ExporterError() {
    LogData logData = TestUtil.createLogData(DEBUG, "Log message");
    when(logExporter.export(any())).thenThrow(new RuntimeException("Exporter error!"));
    logProcessor.emit(logData);
    logProcessor.emit(logData);
    verify(logExporter, times(2)).export(Collections.singletonList(logData));
}
Also used : LogData(io.opentelemetry.sdk.logs.data.LogData) SuppressLogger(io.opentelemetry.internal.testing.slf4j.SuppressLogger) Test(org.junit.jupiter.api.Test)

Example 32 with LogData

use of io.opentelemetry.sdk.logs.data.LogData in project opentelemetry-java-instrumentation by open-telemetry.

the class OpenTelemetryAppenderConfigTest method logWithSpan.

@Test
void logWithSpan() {
    Span span1 = runWithSpan("span1", () -> logger.info("log message 1"));
    logger.info("log message 2");
    Span span2 = runWithSpan("span2", () -> logger.info("log message 3"));
    List<LogData> logDataList = logExporter.getFinishedLogItems();
    assertThat(logDataList).hasSize(3);
    assertThat(logDataList.get(0).getSpanContext()).isEqualTo(span1.getSpanContext());
    assertThat(logDataList.get(1).getSpanContext()).isEqualTo(SpanContext.getInvalid());
    assertThat(logDataList.get(2).getSpanContext()).isEqualTo(span2.getSpanContext());
}
Also used : LogData(io.opentelemetry.sdk.logs.data.LogData) Span(io.opentelemetry.api.trace.Span) Test(org.junit.jupiter.api.Test)

Example 33 with LogData

use of io.opentelemetry.sdk.logs.data.LogData in project opentelemetry-java-instrumentation by open-telemetry.

the class OpenTelemetryAppenderConfigTest method logWithExtras.

@Test
void logWithExtras() {
    Instant start = Instant.now();
    logger.info("log message 1", new IllegalStateException("Error!"));
    List<LogData> logDataList = logExporter.getFinishedLogItems();
    assertThat(logDataList).hasSize(1);
    LogData logData = logDataList.get(0);
    assertThat(logData.getResource()).isEqualTo(resource);
    assertThat(logData.getInstrumentationLibraryInfo()).isEqualTo(instrumentationLibraryInfo);
    assertThat(logData.getBody().asString()).isEqualTo("log message 1");
    assertThat(logData.getEpochNanos()).isGreaterThan(TimeUnit.MILLISECONDS.toNanos(start.toEpochMilli())).isLessThan(TimeUnit.MILLISECONDS.toNanos(Instant.now().toEpochMilli()));
    assertThat(logData.getSeverity()).isEqualTo(Severity.INFO);
    assertThat(logData.getSeverityText()).isEqualTo("INFO");
    assertThat(logData.getAttributes().size()).isEqualTo(3);
    assertThat(logData.getAttributes().get(SemanticAttributes.EXCEPTION_TYPE)).isEqualTo(IllegalStateException.class.getName());
    assertThat(logData.getAttributes().get(SemanticAttributes.EXCEPTION_MESSAGE)).isEqualTo("Error!");
    assertThat(logData.getAttributes().get(SemanticAttributes.EXCEPTION_STACKTRACE)).contains("logWithExtras");
}
Also used : LogData(io.opentelemetry.sdk.logs.data.LogData) Instant(java.time.Instant) Test(org.junit.jupiter.api.Test)

Example 34 with LogData

use of io.opentelemetry.sdk.logs.data.LogData in project opentelemetry-java-instrumentation by open-telemetry.

the class OpenTelemetryAppenderConfigTest method logNoSpan.

@Test
void logNoSpan() {
    logger.info("log message 1");
    List<LogData> logDataList = logExporter.getFinishedLogItems();
    assertThat(logDataList).hasSize(1);
    LogData logData = logDataList.get(0);
    assertThat(logData.getResource()).isEqualTo(resource);
    assertThat(logData.getInstrumentationLibraryInfo()).isEqualTo(instrumentationLibraryInfo);
    assertThat(logData.getBody().asString()).isEqualTo("log message 1");
    assertThat(logData.getAttributes()).isEqualTo(Attributes.empty());
}
Also used : LogData(io.opentelemetry.sdk.logs.data.LogData) Test(org.junit.jupiter.api.Test)

Example 35 with LogData

use of io.opentelemetry.sdk.logs.data.LogData in project opentelemetry-java-instrumentation by open-telemetry.

the class OpenTelemetryAppenderConfigTest method logWithSpan.

@Test
void logWithSpan() {
    Span span1 = runWithSpan("span1", () -> logger.info("log message 1"));
    logger.info("log message 2");
    Span span2 = runWithSpan("span2", () -> logger.info("log message 3"));
    List<LogData> logDataList = logExporter.getFinishedLogItems();
    assertThat(logDataList).hasSize(3);
    assertThat(logDataList.get(0).getSpanContext()).isEqualTo(span1.getSpanContext());
    assertThat(logDataList.get(1).getSpanContext()).isEqualTo(SpanContext.getInvalid());
    assertThat(logDataList.get(2).getSpanContext()).isEqualTo(span2.getSpanContext());
}
Also used : LogData(io.opentelemetry.sdk.logs.data.LogData) Span(io.opentelemetry.api.trace.Span) Test(org.junit.jupiter.api.Test)

Aggregations

LogData (io.opentelemetry.sdk.logs.data.LogData)40 Test (org.junit.jupiter.api.Test)34 Instant (java.time.Instant)8 SdkLogEmitterProvider (io.opentelemetry.sdk.logs.SdkLogEmitterProvider)7 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 Attributes (io.opentelemetry.api.common.Attributes)5 SpanContext (io.opentelemetry.api.trace.SpanContext)4 SuppressLogger (io.opentelemetry.internal.testing.slf4j.SuppressLogger)4 Clock (io.opentelemetry.sdk.common.Clock)4 CompletableResultCode (io.opentelemetry.sdk.common.CompletableResultCode)4 Resource (io.opentelemetry.sdk.resources.Resource)4 TimeUnit (java.util.concurrent.TimeUnit)4 SpanLinkage (com.splunk.opentelemetry.profiler.context.SpanLinkage)3 EventPeriods (com.splunk.opentelemetry.profiler.events.EventPeriods)3 TraceFlags (io.opentelemetry.api.trace.TraceFlags)3 TraceState (io.opentelemetry.api.trace.TraceState)3 LogDataBuilder (io.opentelemetry.sdk.logs.data.LogDataBuilder)3 Mockito.when (org.mockito.Mockito.when)3 CONFIG_KEY_MEMORY_SAMPLER_INTERVAL (com.splunk.opentelemetry.profiler.Configuration.CONFIG_KEY_MEMORY_SAMPLER_INTERVAL)2 CONFIG_KEY_TLAB_ENABLED (com.splunk.opentelemetry.profiler.Configuration.CONFIG_KEY_TLAB_ENABLED)2