Wrap log statements using varargs to avoid object allocation (DataDog/dd-trace-java#1466)
MODIFY
agent-bootstrap/src/main/java/io/opentelemetry/auto/bootstrap/instrumentation/java/concurrent/State.java
agent-bootstrap/src/main/java/io/opentelemetry/auto/bootstrap/instrumentation/java/concurrent/State.java
@@ -38,6 +38,7 @@ public class State {
public void setParentSpan(final Span parentSpan) {
final boolean result = parentSpanRef.compareAndSet(null, parentSpan);
if (!result && parentSpanRef.get() != parentSpan) {
+ if (log.isDebugEnabled()) {
log.debug(
"Failed to set parent span because another parent span is already set {}: new: {}, old: {}",
this,
@@ -45,6 +46,7 @@ public class State {
parentSpanRef.get());
}
}
+ }
public void clearParentSpan() {
parentSpanRef.set(null);

MODIFY
agent-tooling/src/main/java/io/opentelemetry/auto/tooling/AgentInstaller.java
agent-tooling/src/main/java/io/opentelemetry/auto/tooling/AgentInstaller.java
@@ -207,12 +207,14 @@ public class AgentInstaller {
final JavaModule module,
final boolean loaded,
final Throwable throwable) {
+ if (log.isDebugEnabled()) {
log.debug(
"Failed to handle {} for transformation on classloader {}: {}",
typeName,
classLoader,
throwable.getMessage());
}
+ }
@Override
public void onTransformation(

MODIFY
agent-tooling/src/main/java/io/opentelemetry/auto/tooling/HelperInjector.java
agent-tooling/src/main/java/io/opentelemetry/auto/tooling/HelperInjector.java
@@ -142,12 +142,14 @@ public class HelperInjector implements Transformer {
helperModules.add(new WeakReference<>(javaModule.unwrap()));
}
} catch (final Exception e) {
+ if (log.isErrorEnabled()) {
log.error(
"Error preparing helpers while processing {} for {}. Failed to inject helper classes into instance {}",
typeDescription,
requestingName,
classLoader,
e);
+ }
throw new RuntimeException(e);
}
@@ -166,7 +168,7 @@ public class HelperInjector implements Transformer {
// a reference count -- but for now, starting simple.
// Failures to create a tempDir are propagated as IOException and handled by transform
- File tempDir = createTempDir();
+ final File tempDir = createTempDir();
try {
return ClassInjector.UsingInstrumentation.of(
tempDir,
@@ -206,15 +208,15 @@ public class HelperInjector implements Transformer {
}
}
- private static final File createTempDir() throws IOException {
+ private static File createTempDir() throws IOException {
return Files.createTempDirectory("opentelemetry-temp-jars").toFile();
}
- private static final void deleteTempDir(final File file) {
+ private static void deleteTempDir(final File file) {
// Not using Files.delete for deleting the directory because failures
// create Exceptions which may prove expensive. Instead using the
// older File API which simply returns a boolean.
- boolean deleted = file.delete();
+ final boolean deleted = file.delete();
if (!deleted) {
file.deleteOnExit();
}

MODIFY
agent-tooling/src/main/java/io/opentelemetry/auto/tooling/Instrumenter.java
agent-tooling/src/main/java/io/opentelemetry/auto/tooling/Instrumenter.java
@@ -160,22 +160,26 @@ public interface Instrumenter {
if (log.isDebugEnabled()) {
final List<Reference.Mismatch> mismatches =
muzzle.getMismatchedReferenceSources(classLoader);
+ if (log.isDebugEnabled()) {
log.debug(
"Instrumentation muzzled: {} -- {} on {}",
instrumentationNames,
Instrumenter.Default.this.getClass().getName(),
classLoader);
+ }
for (final Reference.Mismatch mismatch : mismatches) {
log.debug("-- {}", mismatch);
}
}
} else {
+ if (log.isDebugEnabled()) {
log.debug(
"Applying instrumentation: {} -- {} on {}",
instrumentationPrimaryName,
Instrumenter.Default.this.getClass().getName(),
classLoader);
}
+ }
return isMatch;
}
return true;

MODIFY
agent-tooling/src/main/java/io/opentelemetry/auto/tooling/VersionLogger.java
agent-tooling/src/main/java/io/opentelemetry/auto/tooling/VersionLogger.java
@@ -30,6 +30,7 @@ public class VersionLogger {
"opentelemetry-auto - version: {}",
getVersionString(
ClassLoader.getSystemClassLoader().getResourceAsStream("opentelemetry-auto.version")));
+ if (log.isDebugEnabled()) {
log.debug(
"Running on Java {}. JVM {} - {} - {}",
System.getProperty("java.version"),
@@ -37,6 +38,7 @@ public class VersionLogger {
System.getProperty("java.vm.vendor"),
System.getProperty("java.vm.version"));
}
+ }
private static String getVersionString(final InputStream stream) {
String v;

MODIFY
agent-tooling/src/main/java/io/opentelemetry/auto/tooling/bytebuddy/matcher/SafeErasureMatcher.java
agent-tooling/src/main/java/io/opentelemetry/auto/tooling/bytebuddy/matcher/SafeErasureMatcher.java
@@ -62,11 +62,13 @@ class SafeErasureMatcher<T extends TypeDefinition> extends ElementMatcher.Juncti
try {
return typeDefinition.asErasure();
} catch (final Exception e) {
+ if (log.isDebugEnabled()) {
log.debug(
"{} trying to get erasure for target {}: {}",
e.getClass().getSimpleName(),
safeTypeDefinitionName(typeDefinition),
e.getMessage());
+ }
return null;
}
}

MODIFY
agent-tooling/src/main/java/io/opentelemetry/auto/tooling/bytebuddy/matcher/SafeHasSuperTypeMatcher.java
agent-tooling/src/main/java/io/opentelemetry/auto/tooling/bytebuddy/matcher/SafeHasSuperTypeMatcher.java
@@ -119,12 +119,14 @@ class SafeHasSuperTypeMatcher<T extends TypeDescription>
interfaceTypes.add(interfaceIter.next());
}
} catch (final Exception e) {
+ if (log.isDebugEnabled()) {
log.debug(
"{} trying to get interfaces for target {}: {}",
e.getClass().getSimpleName(),
safeTypeDefinitionName(typeDefinition),
e.getMessage());
}
+ }
return interfaceTypes;
}
@@ -132,11 +134,13 @@ class SafeHasSuperTypeMatcher<T extends TypeDescription>
try {
return typeDefinition.getSuperClass();
} catch (final Exception e) {
+ if (log.isDebugEnabled()) {
log.debug(
"{} trying to get super class for target {}: {}",
e.getClass().getSimpleName(),
safeTypeDefinitionName(typeDefinition),
e.getMessage());
+ }
return null;
}
}

MODIFY
agent-tooling/src/main/java/io/opentelemetry/auto/tooling/context/FieldBackedProvider.java
agent-tooling/src/main/java/io/opentelemetry/auto/tooling/context/FieldBackedProvider.java
@@ -229,11 +229,13 @@ public class FieldBackedProvider implements InstrumentationContextProvider {
final String keyClassName = ((Type) stack[1]).getClassName();
final TypeDescription contextStoreImplementationClass =
getContextStoreImplementation(keyClassName, contextClassName);
+ if (log.isDebugEnabled()) {
log.debug(
"Rewriting context-store map fetch for instrumenter {}: {} -> {}",
instrumenter.getClass().getName(),
keyClassName,
contextClassName);
+ }
if (contextStoreImplementationClass == null) {
throw new IllegalStateException(
String.format(

Wrap log statements using varargs to avoid object allocation (DataDog/dd-trace-java#1466)