use of io.opentelemetry.sdk.logs.SdkLogEmitterProvider in project opentelemetry-java by open-telemetry.
the class BatchLogProcessorTest method emitMoreLogsThanBufferSize.
@Test
void emitMoreLogsThanBufferSize() {
CompletableLogExporter logExporter = new CompletableLogExporter();
SdkLogEmitterProvider sdkLogEmitterProvider = SdkLogEmitterProvider.builder().addLogProcessor(BatchLogProcessor.builder(logExporter).setMaxQueueSize(6).setMaxExportBatchSize(2).setScheduleDelay(MAX_SCHEDULE_DELAY_MILLIS, TimeUnit.MILLISECONDS).build()).build();
emitLog(sdkLogEmitterProvider, LOG_MESSAGE_1);
emitLog(sdkLogEmitterProvider, LOG_MESSAGE_1);
emitLog(sdkLogEmitterProvider, LOG_MESSAGE_1);
emitLog(sdkLogEmitterProvider, LOG_MESSAGE_1);
emitLog(sdkLogEmitterProvider, LOG_MESSAGE_1);
emitLog(sdkLogEmitterProvider, LOG_MESSAGE_1);
logExporter.succeed();
await().untilAsserted(() -> assertThat(logExporter.getExported()).hasSize(6).allSatisfy(logData -> assertThat(logData).hasBody(LOG_MESSAGE_1)));
}
use of io.opentelemetry.sdk.logs.SdkLogEmitterProvider in project opentelemetry-java by open-telemetry.
the class AutoConfiguredOpenTelemetrySdkTest method builder_addLogEmitterProviderCustomizer.
// TODO: add test for addMetricExporterCustomizer once OTLP export is enabled by default
@Test
void builder_addLogEmitterProviderCustomizer() {
Mockito.lenient().when(logProcessor.shutdown()).thenReturn(CompletableResultCode.ofSuccess());
when(logProcessor.forceFlush()).thenReturn(CompletableResultCode.ofSuccess());
SdkLogEmitterProvider sdkLogEmitterProvider = builder.addLogEmitterProviderCustomizer((logEmitterProviderBuilder, configProperties) -> logEmitterProviderBuilder.addLogProcessor(logProcessor)).build().getOpenTelemetrySdk().getSdkLogEmitterProvider();
sdkLogEmitterProvider.forceFlush().join(10, TimeUnit.SECONDS);
verify(logProcessor).forceFlush();
}
use of io.opentelemetry.sdk.logs.SdkLogEmitterProvider in project opentelemetry-java-instrumentation by open-telemetry.
the class AgentTestingLogsCustomizer method beforeAgent.
@Override
public void beforeAgent(Config config, AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk) {
SdkLogEmitterProvider logEmitterProvider = SdkLogEmitterProvider.builder().setResource(autoConfiguredOpenTelemetrySdk.getResource()).addLogProcessor(SimpleLogProcessor.create(AgentTestingExporterFactory.logExporter)).build();
AgentLogEmitterProvider.resetForTest();
AgentLogEmitterProvider.set(DelegatingLogEmitterProvider.from(logEmitterProvider));
}
use of io.opentelemetry.sdk.logs.SdkLogEmitterProvider in project opentelemetry-java-instrumentation by open-telemetry.
the class OpenTelemetryAppenderConfigTest method setupAll.
@BeforeAll
static void setupAll() {
logExporter = InMemoryLogExporter.create();
resource = Resource.getDefault();
instrumentationLibraryInfo = InstrumentationLibraryInfo.create("TestLogger", null);
SdkLogEmitterProvider logEmitterProvider = SdkLogEmitterProvider.builder().setResource(resource).addLogProcessor(SimpleLogProcessor.create(logExporter)).build();
OpenTelemetryAppender.resetSdkLogEmitterProviderForTest();
OpenTelemetryAppender.setSdkLogEmitterProvider(logEmitterProvider);
}
use of io.opentelemetry.sdk.logs.SdkLogEmitterProvider in project opentelemetry-java-instrumentation by open-telemetry.
the class OpenTelemetryInstaller method installOpenTelemetrySdk.
/**
* Install the {@link OpenTelemetrySdk} using autoconfigure, and return the {@link
* AutoConfiguredOpenTelemetrySdk}.
*
* @return the {@link AutoConfiguredOpenTelemetrySdk}
*/
static AutoConfiguredOpenTelemetrySdk installOpenTelemetrySdk(Config config) {
System.setProperty("io.opentelemetry.context.contextStorageProvider", "default");
AutoConfiguredOpenTelemetrySdkBuilder builder = AutoConfiguredOpenTelemetrySdk.builder().setResultAsGlobal(true).addPropertiesSupplier(config::getAllProperties);
ClassLoader classLoader = AgentInitializer.getExtensionsClassLoader();
if (classLoader != null) {
// May be null in unit tests.
builder.setServiceClassLoader(classLoader);
}
AutoConfiguredOpenTelemetrySdk autoConfiguredSdk = builder.build();
OpenTelemetrySdk sdk = autoConfiguredSdk.getOpenTelemetrySdk();
OpenTelemetrySdkAccess.internalSetForceFlush((timeout, unit) -> {
CompletableResultCode traceResult = sdk.getSdkTracerProvider().forceFlush();
CompletableResultCode metricsResult = sdk.getSdkMeterProvider().forceFlush();
CompletableResultCode.ofAll(Arrays.asList(traceResult, metricsResult)).join(timeout, unit);
});
SdkLogEmitterProvider sdkLogEmitterProvider = autoConfiguredSdk.getOpenTelemetrySdk().getSdkLogEmitterProvider();
LogEmitterProvider logEmitterProvider = DelegatingLogEmitterProvider.from(sdkLogEmitterProvider);
AgentLogEmitterProvider.set(logEmitterProvider);
return autoConfiguredSdk;
}
Aggregations