Enable OTLP logs exporter (#10055)

This commit is contained in:
Mateusz Rzeszutek 2023-12-13 17:22:08 +01:00 committed by GitHub
parent 1a054a53ad
commit 4123a639fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 28 additions and 21 deletions

View File

@ -31,6 +31,7 @@ import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.Network;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.containers.wait.strategy.WaitStrategy;
import org.testcontainers.utility.MountableFile;
abstract class SmokeTest {
@ -46,6 +47,8 @@ abstract class SmokeTest {
protected abstract String getTargetImage(int jdk);
protected abstract WaitStrategy getTargetWaitStrategy();
/** Subclasses can override this method to customise target application's environment */
protected Map<String, String> getExtraEnv() {
return Collections.emptyMap();
@ -80,7 +83,8 @@ abstract class SmokeTest {
.withEnv("OTEL_BSP_MAX_EXPORT_BATCH", "1")
.withEnv("OTEL_BSP_SCHEDULE_DELAY", "10")
.withEnv("OTEL_PROPAGATORS", "tracecontext,baggage,demo")
.withEnv(getExtraEnv());
.withEnv(getExtraEnv())
.waitingFor(getTargetWaitStrategy());
target.start();
}

View File

@ -8,6 +8,7 @@ package com.example.javaagent.smoketest;
import io.opentelemetry.api.trace.TraceId;
import io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest;
import java.io.IOException;
import java.time.Duration;
import java.util.Collection;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
@ -15,6 +16,8 @@ import okhttp3.Request;
import okhttp3.Response;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.containers.wait.strategy.WaitStrategy;
class SpringBootSmokeTest extends SmokeTest {
@ -25,6 +28,12 @@ class SpringBootSmokeTest extends SmokeTest {
+ "-20211213.1570880324";
}
@Override
protected WaitStrategy getTargetWaitStrategy() {
return Wait.forLogMessage(".*Started SpringbootApplication in.*", 1)
.withStartupTimeout(Duration.ofMinutes(1));
}
@Test
public void springBootSmokeTestOnJDK() throws IOException, InterruptedException {
startTarget(8);

View File

@ -31,6 +31,7 @@ import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.Network;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.containers.wait.strategy.WaitStrategy;
import org.testcontainers.utility.MountableFile;
abstract class IntegrationTest {
@ -51,6 +52,8 @@ abstract class IntegrationTest {
protected abstract String getTargetImage(int jdk);
protected abstract WaitStrategy getTargetWaitStrategy();
/** Subclasses can override this method to customise target application's environment */
protected Map<String, String> getExtraEnv() {
return Collections.emptyMap();
@ -98,7 +101,8 @@ abstract class IntegrationTest {
.withEnv("OTEL_BSP_MAX_EXPORT_BATCH", "1")
.withEnv("OTEL_BSP_SCHEDULE_DELAY", "10")
.withEnv("OTEL_PROPAGATORS", "tracecontext,baggage,demo")
.withEnv(getExtraEnv());
.withEnv(getExtraEnv())
.waitingFor(getTargetWaitStrategy());
// If external extensions are requested
if (extensionLocation != null) {
// Asks instrumentation agent to include extensions from given location into its runtime

View File

@ -8,6 +8,7 @@ package com.example.javaagent.smoketest;
import io.opentelemetry.api.trace.TraceId;
import io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceRequest;
import java.io.IOException;
import java.time.Duration;
import java.util.Collection;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
@ -15,6 +16,8 @@ import okhttp3.Request;
import okhttp3.Response;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.containers.wait.strategy.WaitStrategy;
class SpringBootIntegrationTest extends IntegrationTest {
@ -25,6 +28,12 @@ class SpringBootIntegrationTest extends IntegrationTest {
+ "-20211213.1570880324";
}
@Override
protected WaitStrategy getTargetWaitStrategy() {
return Wait.forLogMessage(".*Started SpringbootApplication in.*", 1)
.withStartupTimeout(Duration.ofMinutes(1));
}
@Test
public void extensionsAreLoadedFromJar() throws IOException, InterruptedException {
startTarget("/opentelemetry-extensions.jar");

View File

@ -5,8 +5,6 @@
package io.opentelemetry.javaagent.tooling;
import static java.util.Collections.singletonMap;
import io.opentelemetry.javaagent.bootstrap.OpenTelemetrySdkAccess;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk;
@ -28,9 +26,6 @@ public final class OpenTelemetryInstaller {
AutoConfiguredOpenTelemetrySdk.builder()
.setResultAsGlobal()
.setServiceClassLoader(extensionClassLoader)
// disable the logs exporter by default for the time being
// FIXME remove this in the 2.x branch
.addPropertiesSupplier(() -> singletonMap("otel.logs.exporter", "none"))
.build();
OpenTelemetrySdk sdk = autoConfiguredSdk.getOpenTelemetrySdk();

View File

@ -31,13 +31,4 @@ class OpenTelemetryInstallerTest extends Specification {
GlobalOpenTelemetry.get() != OpenTelemetry.noop()
}
def "should disable the logs exporter by default"() {
when:
def autoConfiguredSdk = OpenTelemetryInstaller.installOpenTelemetrySdk(OpenTelemetryInstaller.classLoader)
then:
autoConfiguredSdk != null
autoConfiguredSdk.config.getString("otel.logs.exporter") == "none"
}
}

View File

@ -20,11 +20,6 @@ class LogsSmokeTest extends SmokeTest {
"ghcr.io/open-telemetry/opentelemetry-java-instrumentation/smoke-test-spring-boot:jdk$jdk-20211213.1570880324"
}
@Override
protected Map<String, String> getExtraEnv() {
return Map.of("OTEL_LOGS_EXPORTER", "otlp")
}
@Override
protected TargetWaitStrategy getWaitStrategy() {
return new TargetWaitStrategy.Log(Duration.ofMinutes(1), ".*Started SpringbootApplication in.*")