Turn on the logging span exporter if agent debug is enabled.
MODIFY
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/config/Config.java
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/config/Config.java
@@ -159,4 +159,8 @@ public abstract class Config {
properties.putAll(getAllProperties());
return properties;
}
+
+ public boolean isAgentDebugEnabled() {
+ return getBooleanProperty("otel.javaagent.debug", false);
+ }
}

MODIFY
instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/config/ConfigTest.groovy
instrumentation-api/src/test/groovy/io/opentelemetry/instrumentation/api/config/ConfigTest.groovy
@@ -99,4 +99,20 @@ class ConfigTest extends Specification {
expect:
config.getMapProperty("property.map").isEmpty()
}
+
+ def "should expose if agent debug is enabled"() {
+ given:
+ def config = new ConfigBuilder().readProperties([
+ "otel.javaagent.debug": value
+ ]).build()
+
+ expect:
+ config.isAgentDebugEnabled() == result
+
+ where:
+ value | result
+ "true" | true
+ "blather" | false
+ null | false
+ }
}

MODIFY
javaagent-bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap/AgentInitializer.java
javaagent-bootstrap/src/main/java/io/opentelemetry/javaagent/bootstrap/AgentInitializer.java
@@ -47,6 +47,7 @@ public class AgentInitializer {
// fields must be managed under class lock
private static ClassLoader AGENT_CLASSLOADER = null;
+ // called via reflection in the OpenTelemetryAgent class
public static void initialize(Instrumentation inst, URL bootstrapUrl) {
startAgent(inst, bootstrapUrl);
}

MODIFY
javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/AgentTracerProviderConfigurer.java
javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/AgentTracerProviderConfigurer.java
@@ -7,6 +7,7 @@ package io.opentelemetry.javaagent.tooling;
import com.google.auto.service.AutoService;
import io.opentelemetry.api.metrics.GlobalMetricsProvider;
+import io.opentelemetry.exporter.logging.LoggingSpanExporter;
import io.opentelemetry.instrumentation.api.config.Config;
import io.opentelemetry.javaagent.spi.exporter.MetricExporterFactory;
import io.opentelemetry.javaagent.spi.exporter.SpanExporterFactory;
@@ -17,6 +18,7 @@ import io.opentelemetry.sdk.metrics.export.MetricExporter;
import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder;
import io.opentelemetry.sdk.trace.SpanProcessor;
import io.opentelemetry.sdk.trace.export.BatchSpanProcessor;
+import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
import io.opentelemetry.sdk.trace.export.SpanExporter;
import java.io.File;
import java.net.MalformedURLException;
@@ -44,6 +46,20 @@ public class AgentTracerProviderConfigurer implements SdkTracerProviderConfigure
sdkTracerProviderBuilder.addSpanProcessor(new AddThreadDetailsSpanProcessor());
maybeConfigureExporterJar(sdkTracerProviderBuilder);
+ maybeEnableLoggingExporter(sdkTracerProviderBuilder);
+ }
+
+ private static void maybeEnableLoggingExporter(SdkTracerProviderBuilder builder) {
+ if (Config.get().isAgentDebugEnabled()) {
+ // don't install another instance if the user has already explicitly requested it.
+ if (loggingExporterIsNotAlreadyConfigured()) {
+ builder.addSpanProcessor(SimpleSpanProcessor.create(new LoggingSpanExporter()));
+ }
+ }
+ }
+
+ private static boolean loggingExporterIsNotAlreadyConfigured() {
+ return !Config.get().getProperty("otel.traces.exporter", "").equalsIgnoreCase("logging");
}
private static void maybeConfigureExporterJar(SdkTracerProviderBuilder sdkTracerProviderBuilder) {
@@ -72,7 +88,7 @@ public class AgentTracerProviderConfigurer implements SdkTracerProviderConfigure
getExporterFactory(SpanExporterFactory.class, exporterLoader);
if (spanExporterFactory != null) {
- installExporter(spanExporterFactory, config, builder);
+ installSpanExporter(spanExporterFactory, config, builder);
} else {
log.warn("No span exporter found in {}", exporterJar);
log.warn("No valid exporter found. Tracing will run but spans are dropped");
@@ -81,7 +97,7 @@ public class AgentTracerProviderConfigurer implements SdkTracerProviderConfigure
MetricExporterFactory metricExporterFactory =
getExporterFactory(MetricExporterFactory.class, exporterLoader);
if (metricExporterFactory != null) {
- installExporter(metricExporterFactory, config);
+ installMetricExporter(metricExporterFactory, config);
}
}
@@ -100,7 +116,7 @@ public class AgentTracerProviderConfigurer implements SdkTracerProviderConfigure
return null;
}
- private static void installExporter(
+ private static void installSpanExporter(
SpanExporterFactory spanExporterFactory,
Properties config,
SdkTracerProviderBuilder builder) {
@@ -110,7 +126,7 @@ public class AgentTracerProviderConfigurer implements SdkTracerProviderConfigure
log.info("Installed span exporter: " + spanExporter.getClass().getName());
}
- private static void installExporter(
+ private static void installMetricExporter(
MetricExporterFactory metricExporterFactory, Properties config) {
MetricExporter metricExporter = metricExporterFactory.fromConfig(config);
IntervalMetricReader.builder()

Turn on the logging span exporter if agent debug is enabled. (#2270)