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));
}
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());
}
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");
}
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());
}
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());
}
Aggregations