Search in sources :

Example 6 with SdkLogEmitterProvider

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)));
}
Also used : Strictness(org.mockito.quality.Strictness) LogAssertions.assertThat(io.opentelemetry.sdk.testing.assertj.LogAssertions.assertThat) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) AssertionsForClassTypes.assertThatCode(org.assertj.core.api.AssertionsForClassTypes.assertThatCode) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Mock(org.mockito.Mock) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayList(java.util.ArrayList) Mockito.doThrow(org.mockito.Mockito.doThrow) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) LogData(io.opentelemetry.sdk.logs.data.LogData) Nullable(javax.annotation.Nullable) Awaitility.await(org.awaitility.Awaitility.await) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) GuardedBy(io.opentelemetry.api.internal.GuardedBy) SdkLogEmitterProvider(io.opentelemetry.sdk.logs.SdkLogEmitterProvider) Collection(java.util.Collection) LogAssertions(io.opentelemetry.sdk.testing.assertj.LogAssertions) Mockito.when(org.mockito.Mockito.when) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) SuppressLogger(io.opentelemetry.internal.testing.slf4j.SuppressLogger) Mockito.reset(org.mockito.Mockito.reset) Timeout(org.junit.jupiter.api.Timeout) CompletableResultCode(io.opentelemetry.sdk.common.CompletableResultCode) SdkLogEmitterProvider(io.opentelemetry.sdk.logs.SdkLogEmitterProvider) Test(org.junit.jupiter.api.Test)

Example 7 with SdkLogEmitterProvider

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();
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Sampler(io.opentelemetry.sdk.trace.samplers.Sampler) BeforeEach(org.junit.jupiter.api.BeforeEach) LogProcessor(io.opentelemetry.sdk.logs.LogProcessor) SpanId(io.opentelemetry.api.trace.SpanId) W3CTraceContextPropagator(io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator) OpenTelemetrySdk(io.opentelemetry.sdk.OpenTelemetrySdk) Resource(io.opentelemetry.sdk.resources.Resource) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes) TextMapPropagator(io.opentelemetry.context.propagation.TextMapPropagator) MetricReader(io.opentelemetry.sdk.metrics.export.MetricReader) SimpleSpanProcessor(io.opentelemetry.sdk.trace.export.SimpleSpanProcessor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Map(java.util.Map) ContextKey(io.opentelemetry.context.ContextKey) Context(io.opentelemetry.context.Context) IdGenerator(io.opentelemetry.sdk.trace.IdGenerator) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Span(io.opentelemetry.api.trace.Span) SdkLogEmitterProvider(io.opentelemetry.sdk.logs.SdkLogEmitterProvider) OpenTelemetry(io.opentelemetry.api.OpenTelemetry) SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) Mockito.when(org.mockito.Mockito.when) SdkTracerProvider(io.opentelemetry.sdk.trace.SdkTracerProvider) Mockito.verify(org.mockito.Mockito.verify) GlobalOpenTelemetry(io.opentelemetry.api.GlobalOpenTelemetry) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) SdkMeterProvider(io.opentelemetry.sdk.metrics.SdkMeterProvider) Mockito(org.mockito.Mockito) List(java.util.List) InMemorySpanExporter(io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter) AttributeKey.stringKey(io.opentelemetry.api.common.AttributeKey.stringKey) TextMapGetter(io.opentelemetry.context.propagation.TextMapGetter) MetricReaderFactory(io.opentelemetry.sdk.metrics.export.MetricReaderFactory) TraceId(io.opentelemetry.api.trace.TraceId) SpanData(io.opentelemetry.sdk.trace.data.SpanData) Collections(java.util.Collections) CompletableResultCode(io.opentelemetry.sdk.common.CompletableResultCode) SdkLogEmitterProvider(io.opentelemetry.sdk.logs.SdkLogEmitterProvider) Test(org.junit.jupiter.api.Test)

Example 8 with SdkLogEmitterProvider

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));
}
Also used : SdkLogEmitterProvider(io.opentelemetry.sdk.logs.SdkLogEmitterProvider)

Example 9 with SdkLogEmitterProvider

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);
}
Also used : SdkLogEmitterProvider(io.opentelemetry.sdk.logs.SdkLogEmitterProvider) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 10 with SdkLogEmitterProvider

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;
}
Also used : AutoConfiguredOpenTelemetrySdkBuilder(io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder) AgentLogEmitterProvider(io.opentelemetry.javaagent.instrumentation.api.appender.internal.AgentLogEmitterProvider) DelegatingLogEmitterProvider(io.opentelemetry.instrumentation.sdk.appender.internal.DelegatingLogEmitterProvider) SdkLogEmitterProvider(io.opentelemetry.sdk.logs.SdkLogEmitterProvider) LogEmitterProvider(io.opentelemetry.instrumentation.api.appender.internal.LogEmitterProvider) CompletableResultCode(io.opentelemetry.sdk.common.CompletableResultCode) AutoConfiguredOpenTelemetrySdk(io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk) SdkLogEmitterProvider(io.opentelemetry.sdk.logs.SdkLogEmitterProvider) AutoConfiguredOpenTelemetrySdk(io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk) OpenTelemetrySdk(io.opentelemetry.sdk.OpenTelemetrySdk)

Aggregations

SdkLogEmitterProvider (io.opentelemetry.sdk.logs.SdkLogEmitterProvider)16 Test (org.junit.jupiter.api.Test)10 LogData (io.opentelemetry.sdk.logs.data.LogData)8 CompletableResultCode (io.opentelemetry.sdk.common.CompletableResultCode)4 List (java.util.List)4 TimeUnit (java.util.concurrent.TimeUnit)4 SuppressLogger (io.opentelemetry.internal.testing.slf4j.SuppressLogger)3 OpenTelemetrySdk (io.opentelemetry.sdk.OpenTelemetrySdk)3 SdkMeterProvider (io.opentelemetry.sdk.metrics.SdkMeterProvider)3 SdkTracerProvider (io.opentelemetry.sdk.trace.SdkTracerProvider)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 Timeout (org.junit.jupiter.api.Timeout)3 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)3 Mock (org.mockito.Mock)3 Mockito.when (org.mockito.Mockito.when)3 GuardedBy (io.opentelemetry.api.internal.GuardedBy)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 Map (java.util.Map)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2