8000 clean up PR, rename variables and refactor test logic for readability · DataDog/dd-trace-java@69b16cc · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

8000
Appearance settings

Commit 69b16cc

Browse files
committed
clean up PR, rename variables and refactor test logic for readability
1 parent d94a746 commit 69b16cc

File tree

2 files changed

+20
-47
lines changed

2 files changed

+20
-47
lines changed

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

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class SQLCommenter {
1919
private static final String DATABASE_SERVICE = encode("dddbs");
2020
private static final String DD_HOSTNAME = encode("ddh");
2121
private static final String DD_DB_NAME = encode("dddb");
22-
private static final String DD_DB_INSTANCE = "ddprs";
22+
private static final String DD_PEER_SERVICE = "ddprs";
2323
private static final String DD_ENV = encode("dde");
2424
private static final String DD_VERSION = encode("ddpv");
2525
private static final String TRACEPARENT = encode("traceparent");
@@ -100,9 +100,9 @@ public static String inject(
100100
}
101101

102102
AgentSpan currSpan = activeSpan();
103-
Object peerService = null;
103+
Object peerServiceObj = null;
104104
if (currSpan != null) {
105-
peerService = currSpan.getTag(Tags.PEER_SERVICE);
105+
peerServiceObj = currSpan.getTag(Tags.PEER_SERVICE);
106106
}
107107

108108
final Config config = Config.get();
@@ -112,7 +112,7 @@ public static String inject(
112112
final int commentSize = capacity(traceParent, parentService, dbService, env, version);
113113
StringBuilder sb = new StringBuilder(sql.length() + commentSize);
114114
boolean commentAdded = false;
115-
String peerServiceString = peerService != null ? peerService.toString() : null;
115+
String peerService = peerServiceObj != null ? peerServiceObj.toString() : null;
116116

117117
if (appendComment) {
118118
sb.append(sql);
@@ -126,7 +126,7 @@ public static String inject(
126126
dbService,
127127
hostname,
128128
dbName,
129-
peerServiceString,
129+
peerService,
130130
env,
131131
version,
132132
traceParent);
@@ -141,7 +141,7 @@ public static String inject(
141141
dbService,
142142
hostname,
143143
dbName,
144-
peerServiceString,
144+
peerService,
145145
env,
146146
version,
147147
traceParent);
@@ -208,38 +208,14 @@ private static String encode(final String val) {
208208
return val;
209209
}
210210

211-
/*
212211
protected static boolean toComment(
213212
StringBuilder sb,
214213
final boolean injectTrace,
215214
final String parentService,
216215
final String dbService,
217216
final String hostname,
218217
final String dbName,
219-
final String env,
220-
final String version,
221-
final String traceparent) {
222-
int emptySize = sb.length();
223-
append(sb, PARENT_SERVICE, parentService, false);
224-
append(sb, DATABASE_SERVICE, dbService, sb.length() > emptySize);
225-
append(sb, DD_HOSTNAME, hostname, sb.length() > emptySize);
226-
append(sb, DD_DB_NAME, dbName, sb.length() > emptySize);
227-
append(sb, DD_ENV, env, sb.length() > emptySize);
228-
append(sb, DD_VERSION, version, sb.length() > emptySize);
229-
if (injectTrace) {
230-
append(sb, TRACEPARENT, traceparent, sb.length() > emptySize);
231-
}
232-
return sb.length() > emptySize;
233-
}*/
234-
235-
protected static boolean toComment(
236-
StringBuilder sb,
237-
final boolean injectTrace,
238-
final String parentService,
239-
final String dbService,
240-
final String hostname,
241-
final String dbName,
242-
final String dbInstance,
218+
final String peerService,
243219
final String env,
244220
final String version,
245221
final String traceparent) {
@@ -249,8 +225,8 @@ protected static boolean toComment(
249225
append(sb, DATABASE_SERVICE, dbService, sb.length() > emptySize);
250226
append(sb, DD_HOSTNAME, hostname, sb.length() > emptySize);
251227
append(sb, DD_DB_NAME, dbName, sb.length() > emptySize);
252-
if (dbInstance != null) {
253-
append(sb, DD_DB_INSTANCE, dbInstance, sb.length() > emptySize);
228+
if (peerService != null) {
229+
append(sb, DD_PEER_SERVICE, peerService, sb.length() > emptySize);
254230
}
255231
append(sb, DD_ENV, env, sb.length() > emptySize);
256232
append(sb, DD_VERSION, version, sb.length() > emptySize);

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

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,13 @@ class SQLCommenterTest extends AgentTestRunner {
4141
String sqlWithComment = ""
4242
if (injectTrace) {
4343
sqlWithComment = SQLCommenter.inject(query, dbService, dbType, host, dbName, traceParent, true, appendComment)
44-
} else {
45-
if (appendComment) {
46-
sqlWithComment = SQLCommenter.append(query, dbService, dbType, host, dbName)
47-
} else {
48-
sqlWithComment = SQLCommenter.prepend(query, dbService, dbType, host, dbName)
49-
}
44+
} else if (appendComment) {
45+
sqlWithComment = SQLCommenter.append(query, dbService, dbType, host, dbName)
46+
}
47+
else {
48+
sqlWithComment = SQLCommenter.prepend(query, dbService, dbType, host, dbName)
5049
}
5150

52-
sqlWithComment == expected
5351

5452
then:
5553
sqlWithComment == expected
@@ -126,15 +124,14 @@ class SQLCommenterTest extends AgentTestRunner {
126124

127125
if (injectTrace) {
128126
sqlWithComment = SQLCommenter.inject(query, dbService, dbType, host, dbName, traceParent, true, appendComment)
129-
} else {
130-
if (appendComment) {
131-
sqlWithComment = SQLCommenter.append(query, dbService, dbType, host, dbName)
132-
} else {
133-
sqlWithComment = SQLCommenter.prepend(query, dbService, dbType, host, dbName)
134-
}
127+
}
128+
else if (appendComment) {
129+
sqlWithComment = SQLCommenter.append(query, dbService, dbType, host, dbName)
130+
}
131+
else {
132+
sqlWithComment = SQLCommenter.prepend(query, dbService, dbType, host, dbName)
135133
}
136134
}
137-
sqlWithComment == expected
138135

139136
then:
140137
sqlWithComment == expected

0 commit comments

Comments
 (0)
0