Skip to content

Commit 82f6cdc

Browse files
authored
Merge branch 'master' into joey/aws-sns
2 parents 6aa6c6d + 58edd35 commit 82f6cdc

File tree

5 files changed

+108
-7
lines changed

5 files changed

+108
-7
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/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/JDBCDecorator.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package datadog.trace.instrumentation.jdbc;
22

33
import static datadog.trace.bootstrap.instrumentation.api.Tags.DB_OPERATION;
4+
import static datadog.trace.bootstrap.instrumentation.api.Tags.DB_SCHEMA;
5+
import static datadog.trace.bootstrap.instrumentation.api.Tags.DB_WAREHOUSE;
46

57
import datadog.trace.api.Config;
68
import datadog.trace.api.DDSpanId;
@@ -119,9 +121,18 @@ protected String dbHostname(final DBInfo info) {
119121
return info.getHost();
120122
}
121123

124+
private void setTagIfPresent(final AgentSpan span, final String key, final String value) {
125+
if (value != null && !value.isEmpty()) {
126+
span.setTag(key, value);
127+
}
128+
}
129+
122130
public AgentSpan onConnection(final AgentSpan span, DBInfo dbInfo) {
123131
if (dbInfo != null) {
124132
processDatabaseType(span, dbInfo.getType());
133+
134+
setTagIfPresent(span, DB_WAREHOUSE, dbInfo.getWarehouse());
135+
setTagIfPresent(span, DB_SCHEMA, dbInfo.getSchema());
125136
}
126137
return super.onConnection(span, dbInfo);
127138
}

dd-java-agent/instrumentation/jdbc/src/test/groovy/JDBCConnectionUrlParserTest.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ class JDBCConnectionUrlParserTest extends AgentTestRunner {
5151

5252
where:
5353
url | props | type | subtype | user | host | port | instance | db
54+
// snowflake
55+
"jdbc:snowflake://sza96462.us-east-1.snowflakecomputing.com:443/?db=DATA_OBSERVABILITY_SANDBOX&user=user" | null | "snowflake" | null | "user" | "sza96462.us-east-1.snowflakecomputing.com" | 443 | null | "data_observability_sandbox"
56+
5457
// https://jdbc.postgresql.org/documentation/94/connect.html
5558
"jdbc:postgresql:///" | null | "postgresql" | null | null | "localhost" | 5432 | null | null
5659
"jdbc:postgresql:///" | stdProps | "postgresql" | null | "stdUserName" | "stdServerName" | 9999 | null | "stdDatabaseName"

internal-api/src/main/java/datadog/trace/bootstrap/instrumentation/api/Tags.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ public class Tags {
4242
public static final String DB_USER = "db.user";
4343
public static final String DB_OPERATION = "db.operation";
4444
public static final String DB_STATEMENT = "db.statement";
45+
public static final String DB_WAREHOUSE = "db.warehouse";
46+
public static final String DB_HOST = "db.host";
47+
public static final String DB_SCHEMA = "db.schema";
4548
public static final String MESSAGE_BUS_DESTINATION = "message_bus.destination";
4649

4750
public static final String TEST_MODULE = "test.module";

0 commit comments

Comments
 (0)