Skip to content

Commit 127aa83

Browse files
committed
Support sanitize the influxSQL
1 parent 710ead6 commit 127aa83

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

instrumentation/influxdb-2.4/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/influxdb/v2_4/InfluxDbAttributesGetter.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,19 @@
77

88
import io.opentelemetry.api.internal.StringUtils;
99
import io.opentelemetry.instrumentation.api.incubator.semconv.db.DbClientAttributesGetter;
10+
import io.opentelemetry.instrumentation.api.incubator.semconv.db.SqlStatementSanitizer;
11+
import io.opentelemetry.javaagent.bootstrap.internal.CommonConfig;
1012
import javax.annotation.Nullable;
1113

1214
final class InfluxDbAttributesGetter implements DbClientAttributesGetter<InfluxDbRequest> {
1315

16+
private static final SqlStatementSanitizer sanitizer =
17+
SqlStatementSanitizer.create(CommonConfig.get().isStatementSanitizationEnabled());
18+
1419
@Nullable
1520
@Override
1621
public String getStatement(InfluxDbRequest request) {
17-
return request.getSql();
22+
return sanitizer.sanitize(request.getSql()).getFullStatement();
1823
}
1924

2025
@Nullable

instrumentation/influxdb-2.4/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/influxdb/v2_4/InfluxDbClientTest.java

+18-6
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ void testQueryAndModifyWithOneArgument() {
147147

148148
@Test
149149
void testQueryWithTwoArguments() {
150-
Query query = new Query("SELECT * FROM cpu_load", databaseName);
150+
Query query = new Query("SELECT * FROM cpu_load where test1 = 'influxDb'", databaseName);
151151
influxDb.query(query, TimeUnit.MILLISECONDS);
152152

153153
testing.waitAndAssertTraces(
@@ -158,12 +158,17 @@ void testQueryWithTwoArguments() {
158158
.hasKind(SpanKind.CLIENT)
159159
.hasAttributesSatisfying(
160160
attributeAssertions(
161-
"SELECT * FROM cpu_load", "SELECT", databaseName))));
161+
"SELECT * FROM cpu_load where test1 = ?",
162+
"SELECT",
163+
databaseName))));
162164
}
163165

164166
@Test
165167
void testQueryWithThreeArguments() throws InterruptedException {
166-
Query query = new Query("SELECT * FROM cpu_load", databaseName);
168+
Query query =
169+
new Query(
170+
"SELECT * FROM cpu_load where time >= '2022-01-01T08:00:00Z' AND time <= '2022-01-01T20:00:00Z'",
171+
databaseName);
167172
BlockingQueue<QueryResult> queue = new LinkedBlockingQueue<>();
168173

169174
influxDb.query(query, 2, result -> queue.add(result));
@@ -178,7 +183,9 @@ void testQueryWithThreeArguments() throws InterruptedException {
178183
.hasKind(SpanKind.CLIENT)
179184
.hasAttributesSatisfying(
180185
attributeAssertions(
181-
"SELECT * FROM cpu_load", "SELECT", databaseName))));
186+
"SELECT * FROM cpu_load where time >= ? AND time <= ?",
187+
"SELECT",
188+
databaseName))));
182189
}
183190

184191
@Test
@@ -205,7 +212,10 @@ void testQueryWithThreeArgumentsCallback() throws InterruptedException {
205212
void testQueryWithFiveArguments() throws InterruptedException {
206213
CountDownLatch countDownLatch = new CountDownLatch(1);
207214
CountDownLatch countDownLatchFailure = new CountDownLatch(1);
208-
Query query = new Query("SELECT * FROM cpu_load", databaseName);
215+
Query query =
216+
new Query(
217+
"SELECT MEAN(water_level) FROM h2o_feet where time = '2022-01-01T08:00:00Z'; SELECT water_level FROM h2o_feet LIMIT 2",
218+
databaseName);
209219
influxDb.query(
210220
query,
211221
10,
@@ -227,7 +237,9 @@ void testQueryWithFiveArguments() throws InterruptedException {
227237
.hasKind(SpanKind.CLIENT)
228238
.hasAttributesSatisfying(
229239
attributeAssertions(
230-
"SELECT * FROM cpu_load", "SELECT", databaseName))));
240+
"SELECT MEAN(water_level) FROM h2o_feet where time = ?; SELECT water_level FROM h2o_feet LIMIT ?",
241+
"SELECT",
242+
databaseName))));
231243
}
232244

233245
@Test

0 commit comments

Comments
 (0)