Skip to content

Commit 9fd6c53

Browse files
committed
address review comment
1 parent 5427829 commit 9fd6c53

File tree

8 files changed

+27
-16
lines changed

8 files changed

+27
-16
lines changed

instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/internal/SqlCommenter.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,24 @@ public static SqlCommenter noop() {
3636
return builder().build();
3737
}
3838

39-
public String processQuery(Object connection, String sql, boolean safe) {
39+
/**
40+
* Augments the given SQL query with comment containing tracing context.
41+
*
42+
* @param connection connection object, e.g. JDBC connection or R2DBC connection, that is used to
43+
* execute the query
44+
* @param sql original query
45+
* @param executed whether the query is immediately executed after being processed, e.g. {@link
46+
* java.sql.Statement#execute(String)}, or may be executed later, e.g. {@link
47+
* java.sql.Connection#prepareStatement(String)}
48+
* @return modified query
49+
*/
50+
public String processQuery(Object connection, String sql, boolean executed) {
4051
if (!enabled) {
4152
return sql;
4253
}
4354

4455
return SqlCommenterUtil.processQuery(
45-
sql, propagator.apply(connection, safe), prepend.test(connection));
56+
sql, propagator.apply(connection, executed), prepend.test(connection));
4657
}
4758

4859
public boolean isEnabled() {

instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/internal/SqlCommenterBuilder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ public SqlCommenterBuilder setPropagator(TextMapPropagator propagator) {
7070
* Context propagator.
7171
*
7272
* @param propagator a function that receives the database connection and whether the query is
73-
* executed only once or could be reused. Connection may be a jdbc Connection, R2DBC
74-
* Connection, or any other connection type used by the data access framework performing the
73+
* executed only once or could be reused. Connection may be a JDBC connection, R2DBC
74+
* connection, or any other connection type used by the data access framework performing the
7575
* operation. If the second argument to the function is true, the query is executed only once
76-
* (e.g. JDBC {@link Statement#execute(String)}). If false, the query could be reused (e.g.
77-
* JDBC {@link Connection#prepareStatement(String)}).
76+
* (e.g. JDBC {@link Statement#execute(String)}) immediately after processing. If false, the
77+
* query could be reused (e.g. JDBC {@link Connection#prepareStatement(String)}).
7878
*/
7979
@CanIgnoreReturnValue
8080
public SqlCommenterBuilder setPropagator(

instrumentation-api-incubator/src/main/java/io/opentelemetry/instrumentation/api/incubator/semconv/db/internal/SqlCommenterUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
final class SqlCommenterUtil {
1818

1919
/**
20-
* Append comment containing tracing information at the end of the query. See <a
20+
* Append comment containing tracing information to the query. See <a
2121
* href="https://google.github.io/sqlcommenter/spec/">sqlcommenter</a> for the description of the
2222
* algorithm.
2323
*/

instrumentation/jdbc/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jdbc/ConnectionInstrumentation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public static Object[] processSql(
104104
Context context = Java8BytecodeBridge.currentContext();
105105
if (PrepareContext.get(context) == null) {
106106
// process sql only in the outermost prepare call and save the original sql in context
107-
String processSql = JdbcSingletons.processSql(connection, sql, true);
107+
String processSql = JdbcSingletons.processSql(connection, sql, false);
108108
Scope scope = PrepareContext.init(context, sql).makeCurrent();
109109
return new Object[] {processSql, scope};
110110
} else {

instrumentation/jdbc/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jdbc/JdbcSingletons.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,19 @@ private static SqlCommenter configureSqlCommenter() {
114114
return builder.build();
115115
}
116116

117-
public static String processSql(Statement statement, String sql, boolean safe) {
117+
public static String processSql(Statement statement, String sql, boolean executed) {
118118
Connection connection;
119119
try {
120120
connection = statement.getConnection();
121121
} catch (SQLException exception) {
122122
// connection was already closed
123123
return sql;
124124
}
125-
return processSql(connection, sql, safe);
125+
return processSql(connection, sql, executed);
126126
}
127127

128-
public static String processSql(Connection connection, String sql, boolean safe) {
129-
return SQL_COMMENTER.processQuery(connection, sql, safe);
128+
public static String processSql(Connection connection, String sql, boolean executed) {
129+
return SQL_COMMENTER.processQuery(connection, sql, executed);
130130
}
131131

132132
private JdbcSingletons() {}

instrumentation/jdbc/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jdbc/StatementInstrumentation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static Object[] onEnter(
6969
return new Object[] {null, sql};
7070
}
7171

72-
String processedSql = JdbcSingletons.processSql(statement, sql, false);
72+
String processedSql = JdbcSingletons.processSql(statement, sql, true);
7373
return new Object[] {
7474
JdbcAdviceScope.startStatement(CallDepth.forClass(Statement.class), sql, statement),
7575
processedSql
@@ -101,7 +101,7 @@ public static String addBatch(
101101
}
102102

103103
JdbcData.addStatementBatch(statement, sql);
104-
return JdbcSingletons.processSql(statement, sql, false);
104+
return JdbcSingletons.processSql(statement, sql, true);
105105
}
106106
}
107107

instrumentation/jdbc/library/src/main/java/io/opentelemetry/instrumentation/jdbc/internal/OpenTelemetryStatement.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class OpenTelemetryStatement<S extends Statement> implements Statement {
7171
}
7272

7373
private String processQuery(String sql) {
74-
return sqlCommenter.processQuery(connection.delegate, sql, false);
74+
return sqlCommenter.processQuery(connection.delegate, sql, true);
7575
}
7676

7777
@Override

instrumentation/r2dbc-1.0/library/src/main/java/io/opentelemetry/instrumentation/r2dbc/v1_0/internal/R2dbcSqlCommenterUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static void configure(ProxyConfig proxyConfig, SqlCommenter sqlCommenter)
3030
public String onCreateStatement(String query, StatementInfo info) {
3131
Connection connection =
3232
unwapConnection(info.getConnectionInfo().getOriginalConnection());
33-
String modifiedQuery = sqlCommenter.processQuery(connection, query, true);
33+
String modifiedQuery = sqlCommenter.processQuery(connection, query, false);
3434
if (!modifiedQuery.equals(query)) {
3535
// We store mapping from the modified query to original query on the connection
3636
// the assumption here is that since the connection is not thread safe it won't be

0 commit comments

Comments
 (0)