use of io.opentelemetry.sdk.logs.SdkLogEmitterProvider in project opentelemetry-java by open-telemetry.
the class LogEmitterProviderConfigurationTest method configureLogEmitterProvider.
@Test
void configureLogEmitterProvider() {
Map<String, String> properties = Collections.singletonMap("otel.logs.exporter", "otlp");
SdkLogEmitterProviderBuilder builder = SdkLogEmitterProvider.builder();
LogEmitterProviderConfiguration.configureLogEmitterProvider(builder, DefaultConfigProperties.createForTest(properties), MeterProvider.noop(), (a, unused) -> a);
SdkLogEmitterProvider logEmitterProvider = builder.build();
try {
assertThat(logEmitterProvider).extracting("sharedState").satisfies(sharedState -> assertThat(sharedState).extracting("logProcessor").isInstanceOf(BatchLogProcessor.class).extracting("worker").satisfies(worker -> {
assertThat(worker).extracting("scheduleDelayNanos").isEqualTo(TimeUnit.MILLISECONDS.toNanos(200));
assertThat(worker).extracting("exporterTimeoutNanos").isEqualTo(TimeUnit.MILLISECONDS.toNanos(30000));
assertThat(worker).extracting("maxExportBatchSize").isEqualTo(512);
assertThat(worker).extracting("queue").isInstanceOfSatisfying(ArrayBlockingQueue.class, queue -> assertThat(queue.remainingCapacity()).isEqualTo(2048));
}));
} finally {
logEmitterProvider.shutdown();
}
}
use of io.opentelemetry.sdk.logs.SdkLogEmitterProvider in project opentelemetry-java by open-telemetry.
the class OpenTelemetrySdkBuilder method build.
/**
* Returns a new {@link OpenTelemetrySdk} built with the configuration of this {@link
* OpenTelemetrySdkBuilder}. This SDK is not registered as the global {@link
* io.opentelemetry.api.OpenTelemetry}. It is recommended that you register one SDK using {@link
* OpenTelemetrySdkBuilder#buildAndRegisterGlobal()} for use by instrumentation that requires
* access to a global instance of {@link io.opentelemetry.api.OpenTelemetry}.
*
* @see GlobalOpenTelemetry
*/
public OpenTelemetrySdk build() {
SdkTracerProvider tracerProvider = this.tracerProvider;
if (tracerProvider == null) {
tracerProvider = SdkTracerProvider.builder().build();
}
SdkMeterProvider meterProvider = this.meterProvider;
if (meterProvider == null) {
meterProvider = SdkMeterProvider.builder().build();
}
SdkLogEmitterProvider logEmitterProvider = this.logEmitterProvider;
if (logEmitterProvider == null) {
logEmitterProvider = SdkLogEmitterProvider.builder().build();
}
return new OpenTelemetrySdk(tracerProvider, meterProvider, logEmitterProvider, propagators);
}
use of io.opentelemetry.sdk.logs.SdkLogEmitterProvider in project opentelemetry-java by open-telemetry.
the class BatchLogProcessorTest method emitLogsToMultipleExporters.
@Test
void emitLogsToMultipleExporters() {
WaitingLogExporter waitingLogExporter1 = new WaitingLogExporter(2, CompletableResultCode.ofSuccess());
WaitingLogExporter waitingLogExporter2 = new WaitingLogExporter(2, CompletableResultCode.ofSuccess());
SdkLogEmitterProvider sdkLogEmitterProvider = SdkLogEmitterProvider.builder().addLogProcessor(BatchLogProcessor.builder(LogExporter.composite(Arrays.asList(waitingLogExporter1, waitingLogExporter2))).setScheduleDelay(MAX_SCHEDULE_DELAY_MILLIS, TimeUnit.MILLISECONDS).build()).build();
emitLog(sdkLogEmitterProvider, LOG_MESSAGE_1);
emitLog(sdkLogEmitterProvider, LOG_MESSAGE_2);
List<LogData> exported1 = waitingLogExporter1.waitForExport();
List<LogData> exported2 = waitingLogExporter2.waitForExport();
assertThat(exported1).hasSize(2).satisfiesExactly(logData -> assertThat(logData).hasBody(LOG_MESSAGE_1), logData -> assertThat(logData).hasBody(LOG_MESSAGE_2));
assertThat(exported2).hasSize(2).satisfiesExactly(logData -> assertThat(logData).hasBody(LOG_MESSAGE_1), logData -> assertThat(logData).hasBody(LOG_MESSAGE_2));
}
use of io.opentelemetry.sdk.logs.SdkLogEmitterProvider 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.sdk.logs.SdkLogEmitterProvider in project opentelemetry-java by open-telemetry.
the class BatchLogProcessorTest method shutdownFlushes.
@Test
@Timeout(10)
void shutdownFlushes() {
WaitingLogExporter waitingLogExporter = new WaitingLogExporter(1, CompletableResultCode.ofSuccess());
// Set the export delay to large value, in order to confirm the #flush() below works
SdkLogEmitterProvider sdkLogEmitterProvider = SdkLogEmitterProvider.builder().addLogProcessor(BatchLogProcessor.builder(waitingLogExporter).setScheduleDelay(10, TimeUnit.SECONDS).build()).build();
emitLog(sdkLogEmitterProvider, LOG_MESSAGE_2);
// Force a shutdown, which forces processing of all remaining logs.
sdkLogEmitterProvider.shutdown().join(10, TimeUnit.SECONDS);
List<LogData> exported = waitingLogExporter.getExported();
assertThat(exported).satisfiesExactly(logData -> assertThat(logData).hasBody(LOG_MESSAGE_2));
;
assertThat(waitingLogExporter.shutDownCalled.get()).isTrue();
}
Aggregations