Skip to content

Commit 74fe718

Browse files
authored
Merge branch 'master' into smola/unique-onrootspanfinished
2 parents 0a1311d + f89dfd6 commit 74fe718

File tree

24 files changed

+262
-112
lines changed

24 files changed

+262
-112
lines changed

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/jdbc/DBInfo.java

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public class DBInfo {
1313
private final String db;
1414
private final String host;
1515
private final Integer port;
16+
private final String warehouse;
17+
private final String schema;
1618

1719
DBInfo(
1820
String type,
@@ -23,7 +25,9 @@ public class DBInfo {
2325
String instance,
2426
String db,
2527
String host,
26-
Integer port) {
28+
Integer port,
29+
String warehouse,
30+
String schema) {
2731
this.type = type;
2832
this.subtype = subtype;
2933
this.fullPropagationSupport = fullPropagationSupport;
@@ -33,6 +37,8 @@ public class DBInfo {
3337
this.db = db;
3438
this.host = host;
3539
this.port = port;
40+
this.warehouse = warehouse;
41+
this.schema = schema;
3642
}
3743

3844
public static class Builder {
@@ -45,6 +51,8 @@ public static class Builder {
4551
private String user;
4652
private String instance;
4753
private String db;
54+
private String warehouse;
55+
private String schema;
4856
private String host;
4957
private Integer port;
5058

@@ -59,7 +67,9 @@ public static class Builder {
5967
String instance,
6068
String db,
6169
String host,
62-
Integer port) {
70+
Integer port,
71+
String warehouse,
72+
String schema) {
6373
this.type = type;
6474
this.subtype = subtype;
6575
this.fullPropagationSupport = fullPropagationSupport;
@@ -69,6 +79,8 @@ public static class Builder {
6979
this.db = db;
7080
this.host = host;
7181
this.port = port;
82+
this.warehouse = warehouse;
83+
this.schema = schema;
7284
}
7385

7486
public Builder type(String type) {
@@ -109,6 +121,16 @@ public Builder db(String db) {
109121
return this;
110122
}
111123

124+
public Builder warehouse(String warehouse) {
125+
this.warehouse = warehouse;
126+
return this;
127+
}
128+
129+
public Builder schema(String schema) {
130+
this.schema = schema;
131+
return this;
132+
}
133+
112134
public Builder host(String host) {
113135
this.host = host;
114136
return this;
@@ -120,7 +142,18 @@ public Builder port(Integer port) {
120142
}
121143

122144
public DBInfo build() {
123-
return new DBInfo(type, subtype, fullPropagationSupport, url, user, instance, db, host, port);
145+
return new DBInfo(
146+
type,
147+
subtype,
148+
fullPropagationSupport,
149+
url,
150+
user,
151+
instance,
152+
db,
153+
host,
154+
port,
155+
warehouse,
156+
schema);
124157
}
125158
}
126159

@@ -160,8 +193,27 @@ public Integer getPort() {
160193
return port;
161194
}
162195

196+
public String getWarehouse() {
197+
return warehouse;
198+
}
199+
200+
public String getSchema() {
201+
return schema;
202+
}
203+
163204
public Builder toBuilder() {
164-
return new Builder(type, subtype, fullPropagationSupport, url, user, instance, db, host, port);
205+
return new Builder(
206+
type,
207+
subtype,
208+
fullPropagationSupport,
209+
url,
210+
user,
211+
instance,
212+
db,
213+
host,
214+
port,
215+
warehouse,
216+
schema);
165217
}
166218

167219
@Override
@@ -177,11 +229,24 @@ public boolean equals(Object o) {
177229
&& Objects.equals(instance, dbInfo.instance)
178230
&& Objects.equals(db, dbInfo.db)
179231
&& Objects.equals(host, dbInfo.host)
180-
&& Objects.equals(port, dbInfo.port);
232+
&& Objects.equals(port, dbInfo.port)
233+
&& Objects.equals(warehouse, dbInfo.warehouse)
234+
&& Objects.equals(schema, dbInfo.schema);
181235
}
182236

183237
@Override
184238
public int hashCode() {
185-
return Objects.hash(type, subtype, fullPropagationSupport, url, user, instance, db, host, port);
239+
return Objects.hash(
240+
type,
241+
subtype,
242+
fullPropagationSupport,
243+
url,
244+
user,
245+
instance,
246+
db,
247+
host,
248+
port,
249+
warehouse,
250+
schema);
186251
}
187252
}

dd-java-agent/agent-bootstrap/src/main/java/datadog/trace/bootstrap/instrumentation/jdbc/JDBCConnectionUrlParser.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,17 @@ DBInfo.Builder doParse(String jdbcUrl, DBInfo.Builder builder) {
770770
}
771771
return builder;
772772
}
773+
},
774+
775+
SNOWFLAKE("snowflake") {
776+
@Override
777+
DBInfo.Builder doParse(String jdbcUrl, DBInfo.Builder builder) {
778+
String url = jdbcUrl;
779+
if (url.startsWith("jdbc:")) {
780+
url = url.substring(5);
781+
}
782+
return GENERIC_URL_LIKE.doParse(url, builder);
783+
}
773784
};
774785

775786
private static final Map<String, JDBCConnectionUrlParser> typeParsers = new HashMap<>();
@@ -876,7 +887,15 @@ private static void populateStandardProperties(
876887
if (props.containsKey("databaseName")) {
877888
builder.db((String) props.get("databaseName"));
878889
}
879-
890+
if (props.containsKey("db")) {
891+
builder.db((String) props.get("db"));
892+
}
893+
if (props.containsKey("warehouse")) {
894+
builder.warehouse((String) props.get("warehouse"));
895+
}
896+
if (props.containsKey("schema")) {
897+
builder.schema((String) props.get("schema"));
898+
}
880899
if (props.containsKey("servername")) {
881900
builder.host((String) props.get("servername"));
882901
}

dd-java-agent/agent-builder/src/main/java/datadog/trace/agent/tooling/bytebuddy/matcher/DDElementMatchers.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@ public static void registerAsSupplier() {
2323
@Override
2424
@SuppressForbidden
2525
public ElementMatcher.Junction<TypeDescription> declaresAnnotation(
26-
ElementMatcher.Junction<? super NamedElement> matcher) {
26+
ElementMatcher<? super NamedElement> matcher) {
2727
return ElementMatchers.isAnnotatedWith(matcher);
2828
}
2929

3030
@Override
3131
@SuppressForbidden
3232
public ElementMatcher.Junction<TypeDescription> declaresField(
33-
ElementMatcher.Junction<? super FieldDescription> matcher) {
33+
ElementMatcher<? super FieldDescription> matcher) {
3434
return ElementMatchers.declaresField(matcher);
3535
}
3636

3737
@Override
3838
@SuppressForbidden
3939
public ElementMatcher.Junction<TypeDescription> declaresMethod(
40-
ElementMatcher.Junction<? super MethodDescription> matcher) {
40+
ElementMatcher<? super MethodDescription> matcher) {
4141
return ElementMatchers.declaresMethod(matcher);
4242
}
4343

@@ -49,31 +49,31 @@ public ElementMatcher.Junction<TypeDescription> concreteClass() {
4949

5050
@Override
5151
public ElementMatcher.Junction<TypeDescription> extendsClass(
52-
ElementMatcher.Junction<? super TypeDescription> matcher) {
52+
ElementMatcher<? super TypeDescription> matcher) {
5353
return new SafeHasSuperTypeMatcher<>(matcher, false, true, false);
5454
}
5555

5656
@Override
5757
public ElementMatcher.Junction<TypeDescription> implementsInterface(
58-
ElementMatcher.Junction<? super TypeDescription> matcher) {
58+
ElementMatcher<? super TypeDescription> matcher) {
5959
return new SafeHasSuperTypeMatcher<>(matcher, true, true, true);
6060
}
6161

6262
@Override
6363
public ElementMatcher.Junction<TypeDescription> hasInterface(
64-
ElementMatcher.Junction<? super TypeDescription> matcher) {
64+
ElementMatcher<? super TypeDescription> matcher) {
6565
return new SafeHasSuperTypeMatcher<>(matcher, true, false, true);
6666
}
6767

6868
@Override
6969
public ElementMatcher.Junction<TypeDescription> hasSuperType(
70-
ElementMatcher.Junction<? super TypeDescription> matcher) {
70+
ElementMatcher<? super TypeDescription> matcher) {
7171
return new SafeHasSuperTypeMatcher<>(matcher, false, true, true);
7272
}
7373

7474
@Override
7575
public ElementMatcher.Junction<MethodDescription> hasSuperMethod(
76-
ElementMatcher.Junction<? super MethodDescription> matcher) {
76+
ElementMatcher<? super MethodDescription> matcher) {
7777
return new HasSuperMethodMatcher<>(matcher);
7878
}
7979

dd-java-agent/agent-debugger/debugger-el/src/main/java/com/datadog/debugger/el/expressions/BinaryExpression.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public BinaryExpression(
2121

2222
@Override
2323
public Boolean evaluate(ValueReferenceResolver valueRefResolver) {
24-
return operator.apply(left.evaluate(valueRefResolver), right.evaluate(valueRefResolver));
24+
return operator.apply(left, right, valueRefResolver);
2525
}
2626

2727
@Override

dd-java-agent/agent-debugger/debugger-el/src/main/java/com/datadog/debugger/el/expressions/BinaryOperator.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
package com.datadog.debugger.el.expressions;
22

33
import com.datadog.debugger.el.Visitor;
4+
import datadog.trace.bootstrap.debugger.el.ValueReferenceResolver;
45

56
public enum BinaryOperator {
67
AND("&&") {
78
@Override
8-
public Boolean apply(Boolean left, Boolean right) {
9-
return left && right;
9+
public Boolean apply(
10+
BooleanExpression left, BooleanExpression right, ValueReferenceResolver resolver) {
11+
return left.evaluate(resolver) && right.evaluate(resolver);
1012
}
1113
},
1214
OR("||") {
1315
@Override
14-
public Boolean apply(Boolean left, Boolean right) {
15-
return left || right;
16+
public Boolean apply(
17+
BooleanExpression left, BooleanExpression right, ValueReferenceResolver resolver) {
18+
return left.evaluate(resolver) || right.evaluate(resolver);
1619
}
1720
};
1821

@@ -22,7 +25,8 @@ public Boolean apply(Boolean left, Boolean right) {
2225
this.symbol = symbol;
2326
}
2427

25-
public abstract Boolean apply(Boolean left, Boolean right);
28+
public abstract Boolean apply(
29+
BooleanExpression left, BooleanExpression right, ValueReferenceResolver resolver);
2630

2731
public <R> R accept(Visitor<R> visitor) {
2832
return visitor.visit(this);

dd-java-agent/agent-debugger/debugger-el/src/test/java/com/datadog/debugger/el/expressions/BinaryExpressionTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
import static com.datadog.debugger.el.PrettyPrintVisitor.print;
44
import static org.junit.jupiter.api.Assertions.assertEquals;
55
import static org.junit.jupiter.api.Assertions.assertFalse;
6+
import static org.junit.jupiter.api.Assertions.assertTrue;
67

78
import com.datadog.debugger.el.RefResolverHelper;
9+
import org.junit.jupiter.api.Assertions;
810
import org.junit.jupiter.api.Test;
911

1012
class BinaryExpressionTest {
@@ -23,4 +25,26 @@ void testRightNull() {
2325
assertFalse(expression.evaluate(RefResolverHelper.createResolver(this)));
2426
assertEquals("true && false", print(expression));
2527
}
28+
29+
@Test
30+
void testShortCircuitAnd() {
31+
BinaryExpression expression =
32+
new BinaryExpression(
33+
BooleanExpression.FALSE,
34+
valueRefResolver -> Assertions.fail("should not reach"),
35+
BinaryOperator.AND);
36+
assertFalse(expression.evaluate(RefResolverHelper.createResolver(this)));
37+
assertEquals("false && null", print(expression));
38+
}
39+
40+
@Test
41+
void testShortCircuitOr() {
42+
BinaryExpression expression =
43+
new BinaryExpression(
44+
BooleanExpression.TRUE,
45+
valueRefResolver -> Assertions.fail("should not reach"),
46+
BinaryOperator.OR);
47+
assertTrue(expression.evaluate(RefResolverHelper.createResolver(this)));
48+
assertEquals("true || null", print(expression));
49+
}
2650
}

dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/agent/CapturedSnapshotTest.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,29 @@ public void nullCondition() throws IOException, URISyntaxException {
11211121
"Cannot dereference to field: fld", evaluationErrors.get(0).getMessage());
11221122
}
11231123

1124+
@Test
1125+
public void shortCircuitingCondition() throws IOException, URISyntaxException {
1126+
final String CLASS_NAME = "CapturedSnapshot08";
1127+
LogProbe logProbes =
1128+
createProbeBuilder(PROBE_ID, CLASS_NAME, "doit", "int (java.lang.String)")
1129+
.when(
1130+
new ProbeCondition(
1131+
DSL.when(
1132+
DSL.and(
1133+
DSL.isDefined(DSL.ref("@exception")),
1134+
DSL.contains(
1135+
DSL.getMember(DSL.ref("@exception"), "detailMessage"),
1136+
new StringValue("closed")))),
1137+
"isDefined(@exception) && contains(@exception.detailMessage, 'closed')"))
1138+
.build();
1139+
TestSnapshotListener listener = installProbes(CLASS_NAME, logProbes);
1140+
Class<?> testClass = compileAndLoadClass(CLASS_NAME);
1141+
int result = Reflect.onClass(testClass).call("main", "1").get();
1142+
assertEquals(3, result);
1143+
// no snapshot, no eval error, isDefined returns false and do not evaluate the second part
1144+
assertEquals(0, listener.snapshots.size());
1145+
}
1146+
11241147
@Test
11251148
public void wellKnownClassesCondition() throws IOException, URISyntaxException {
11261149
final String CLASS_NAME = "CapturedSnapshot08";

dd-java-agent/agent-debugger/src/test/java/com/datadog/debugger/exception/ExceptionProbeInstrumentationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void before() {
8181
ProbeRateLimiter.setSamplerSupplier(rate -> rate < 101 ? probeSampler : globalSampler);
8282
ProbeRateLimiter.setGlobalSnapshotRate(1000);
8383
// to activate the call to DebuggerContext.handleException
84-
setFieldInConfig(Config.get(), "debuggerEnabled", true);
84+
setFieldInConfig(Config.get(), "debuggerExceptionEnabled", true);
8585
}
8686

8787
@AfterEach

0 commit comments

Comments
 (0)