Skip to content
Open
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 @@ -5,14 +5,19 @@ import com.datadog.iast.IastSystem
import com.datadog.iast.model.Range
import com.datadog.iast.taint.TaintedObject
import com.datadog.iast.taint.TaintedObjects
import datadog.trace.api.gateway.*
import datadog.trace.api.gateway.CallbackProvider
import datadog.trace.api.gateway.EventType
import datadog.trace.api.gateway.Events
import datadog.trace.api.gateway.Flow
import datadog.trace.api.gateway.IGSpanInfo
import datadog.trace.api.gateway.RequestContext
import datadog.trace.api.gateway.RequestContextSlot
import datadog.trace.api.iast.InstrumentationBridge
import datadog.trace.bootstrap.instrumentation.api.AgentTracer
import org.slf4j.Logger
import org.slf4j.LoggerFactory

import java.util.function.BiFunction
import java.util.function.Supplier
import org.slf4j.Logger
import org.slf4j.LoggerFactory

trait IastRequestContextPreparationTrait {

Expand Down Expand Up @@ -73,7 +78,9 @@ trait IastRequestContextPreparationTrait {

private static Logger withLogger(final String name) {
final logger = LoggerFactory.getLogger(name)
if (logger instanceof ch.qos.logback.classic.Logger) {

// Check logger class by name to avoid NoClassDefFoundError at runtime for tests without Logback.
if (logger.class.name == "ch.qos.logback.classic.Logger") {
((ch.qos.logback.classic.Logger) logger).level = ch.qos.logback.classic.Level.DEBUG
}
return logger
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
apply from: "$rootDir/gradle/java.gradle"
// Use slf4j-simple as default; logback has a high chance of getting stuck in a deadlock on CI.
apply from: "$rootDir/gradle/slf4j-simple.gradle"

testJvmConstraints {
// TODO Java 17: This version of vertx-web doesn't support Java 17
Expand Down Expand Up @@ -49,3 +51,4 @@ dependencies {
latestDepTestImplementation group: 'io.vertx', name: 'vertx-web', version: '3.+'
latestDepTestImplementation group: 'io.vertx', name: 'vertx-web-client', version: '3.+'
}

29 changes: 17 additions & 12 deletions internal-api/src/main/java/datadog/trace/api/iast/Taintable.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,23 @@ class DebugLogger {
private static final Logger LOGGER;

static {
try {
LOGGER = LoggerFactory.getLogger("Taintable tainted objects");
Class<?> levelCls = Class.forName("ch.qos.logback.classic.Level");
Method setLevel = LOGGER.getClass().getMethod("setLevel", levelCls);
Object debugLevel = levelCls.getField("DEBUG").get(null);
setLevel.invoke(LOGGER, debugLevel);
} catch (IllegalAccessException
| NoSuchFieldException
| ClassNotFoundException
| NoSuchMethodException
| InvocationTargetException e) {
throw new RuntimeException(e);
LOGGER = LoggerFactory.getLogger("Taintable tainted objects");

// Check logger class by name to avoid NoClassDefFoundError at runtime
// for tests without Logback.
if (LOGGER.getClass().getName().equals("ch.qos.logback.classic.Logger")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try {
Class<?> levelCls = Class.forName("ch.qos.logback.classic.Level");
Method setLevel = LOGGER.getClass().getMethod("setLevel", levelCls);
Object debugLevel = levelCls.getField("DEBUG").get(null);
setLevel.invoke(LOGGER, debugLevel);
} catch (IllegalAccessException
| NoSuchFieldException
| ClassNotFoundException
| NoSuchMethodException
| InvocationTargetException e) {
throw new RuntimeException(e);
}
}
}

Expand Down