Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.tools.JavaCompiler;
import javax.tools.ToolProvider;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand All @@ -41,47 +43,81 @@ public class ConfigLoggingAgentListenerTest {

private static String agentJarFile;
private static File testTargetClass;
private static File testTargetCompiledClass;

@BeforeAll
public static void setup() throws IOException {
agentJarFile = getAgentJarFile();
testTargetClass = createTestTarget();
compileTestTarget(testTargetClass);
testTargetCompiledClass = new File(testTargetClass.getParent(), TARGET_CLASS_NAME + ".class");
}

@AfterAll
public static void teardown() throws IOException {
testTargetClass.delete();
testTargetCompiledClass.delete();
}

@Test
public void checkLogConfigPresent() throws IOException {
String output = executeCommand(createTestTargetCommand(true), 20);
String output =
filterOutUpstreamDebugConfigLine(executeCommand(createTestTargetCommand(true), 120));
for (String identifyingString : identifyingStrings) {
assertThat(output).contains(identifyingString);
}
}

@Test
public void checkLogConfigAbsent() throws IOException {
String output = executeCommand(createTestTargetCommand(false), 20);
String output =
filterOutUpstreamDebugConfigLine(executeCommand(createTestTargetCommand(false), 120));
for (String identifyingString : identifyingStrings) {
assertThat(output).doesNotContain(identifyingString);
}
}

static String filterOutUpstreamDebugConfigLine(String line) {
// remove the debug level AutoConfiguredOpenTelemetrySdkBuilder output as this has the same
// content apart from being from AutoConfiguredOpenTelemetrySdkBuilder
if (line.contains(
"AutoConfiguredOpenTelemetrySdkBuilder - Global OpenTelemetry set to OpenTelemetrySdk")) {
return line.replaceFirst(
"[\r\n].*?AutoConfiguredOpenTelemetrySdkBuilder - Global OpenTelemetry set to OpenTelemetrySdk.*?[\r\n]",
"");
}
return line;
}

static List<String> createTestTargetCommand(boolean logConfig) throws IOException {
List<String> command = new ArrayList<>();
command.add("java");
command.add("-Xmx32m");
command.add("-Dotel.javaagent.logging=application");
command.add("-Dotel.javaagent.debug=false");
command.add("-Dotel.service.name=ConfigLoggingAgentListenerTest:" + logConfig);
command.add("-Dotel.traces.exporter=none");
command.add("-Dotel.resource.providers.aws.enabled=false");
command.add("-Dotel.resource.providers.gcp.enabled=false");
command.add("-Dotel.resource.providers.azure.enabled=false");
command.add("-javaagent:" + agentJarFile);
// Only on false, ie test the 'true' default with no option
if (!logConfig) {
command.add("-D" + ConfigLoggingAgentListener.LOG_THE_CONFIG + "=false");
}
command.add(testTargetClass.getAbsolutePath());
command.add("-cp");
command.add(testTargetCompiledClass.getParentFile().getAbsolutePath());
command.add(TARGET_CLASS_NAME);
return command;
}

static void compileTestTarget(File sourceFile) throws IOException {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
if (compiler.run(null, null, null, sourceFile.getAbsolutePath()) != 0) {
throw new IOException("Failed to compile test target");
}
}

static File createTestTarget() throws IOException {
String targetClass =
"public class "
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ opentelemetryProto = "1.3.2-alpha"

# otel agent, we rely on the '*-alpha' and get the non-alpha dependencies transitively
# updated from upstream agent with gradle/update-upstream.sh
opentelemetryJavaagentAlpha = "2.21.0-alpha"
opentelemetryJavaagentAlpha = "2.22.0-alpha"

# otel contrib
# updated from upstream agent with gradle/update-upstream.sh
opentelemetryContribAlpha = "1.51.0-alpha"
opentelemetryContribAlpha = "1.52.0-alpha"

# otel semconv
# updated from upstream agent with gradle/update-upstream.sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package co.elastic.otel.logging;

import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.bootstrap.InternalLogger;
import io.opentelemetry.javaagent.tooling.LoggingCustomizer;
import io.opentelemetry.javaagent.tooling.config.EarlyInitAgentConfig;
import java.util.Optional;
Expand All @@ -41,9 +40,6 @@ public void init(EarlyInitAgentConfig earlyConfig) {
// trigger loading the slf4j provider from the agent CL, this should load log4j implementation
LoggerFactory.getILoggerFactory();

// make the agent internal logger delegate to slf4j, which will delegate to log4j
InternalLogger.initialize(Slf4jInternalLogger::create);

boolean upstreamDebugEnabled = earlyConfig.getBoolean(AgentLog.OTEL_JAVAAGENT_DEBUG, false);
Level level;
if (upstreamDebugEnabled) {
Expand Down
Loading