Auto value
* SqlStatementInfo as AutoValue
* RequestMeta as AutoValue
* DbInfo as AutoValue
* After merge compilation fix
* CouchbaseQuerySanitizer compilation fix
* JdbcConnectionUrlParserTest compilation fix
* Revert "RequestMeta as AutoValue"
This reverts commit
MODIFY
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/db/SqlStatementInfo.java
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/db/SqlStatementInfo.java
package io.opentelemetry.instrumentation.api.db;
-import java.util.Objects;
+import com.google.auto.value.AutoValue;
import java.util.function.Function;
import org.checkerframework.checker.nullness.qual.Nullable;
-public final class SqlStatementInfo {
- @Nullable private final String fullStatement;
- @Nullable private final String operation;
- @Nullable private final String table;
+@AutoValue
+public abstract class SqlStatementInfo {
- public SqlStatementInfo(
+ public static SqlStatementInfo create(
@Nullable String fullStatement, @Nullable String operation, @Nullable String table) {
- this.fullStatement = fullStatement;
- this.operation = operation;
- this.table = table;
+ return new AutoValue_SqlStatementInfo(fullStatement, operation, table);
}
public SqlStatementInfo mapTable(Function<String, String> mapper) {
- return new SqlStatementInfo(fullStatement, operation, mapper.apply(table));
+ return SqlStatementInfo.create(getFullStatement(), getOperation(), mapper.apply(getTable()));
}
@Nullable
- public String getFullStatement() {
- return fullStatement;
- }
+ public abstract String getFullStatement();
@Nullable
- public String getOperation() {
- return operation;
- }
+ public abstract String getOperation();
@Nullable
- public String getTable() {
- return table;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == this) {
- return true;
- }
- if (!(obj instanceof SqlStatementInfo)) {
- return false;
- }
- SqlStatementInfo other = (SqlStatementInfo) obj;
- return Objects.equals(fullStatement, other.fullStatement)
- && Objects.equals(operation, other.operation)
- && Objects.equals(table, other.table);
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(fullStatement, operation, table);
- }
+ public abstract String getTable();
}

MODIFY
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/db/SqlStatementSanitizer.java
instrumentation-api/src/main/java/io/opentelemetry/instrumentation/api/db/SqlStatementSanitizer.java
@@ -23,7 +23,7 @@ public final class SqlStatementSanitizer {
public static SqlStatementInfo sanitize(String statement) {
if (!isStatementSanitizationEnabled() || statement == null) {
- return new SqlStatementInfo(statement, null, null);
+ return SqlStatementInfo.create(statement, null, null);
}
return sqlToStatementInfoCache.computeIfAbsent(
statement,

MODIFY
instrumentation-api/src/main/jflex/SqlSanitizer.flex
instrumentation-api/src/main/jflex/SqlSanitizer.flex
@@ -43,7 +43,7 @@ WHITESPACE = [ \t\r\n]+
return sanitizer.getResult();
} catch (java.io.IOException e) {
// should never happen
- return new SqlStatementInfo(null, null, null);
+ return SqlStatementInfo.create(null, null, null);
}
}
@@ -107,7 +107,7 @@ WHITESPACE = [ \t\r\n]+
}
SqlStatementInfo getResult(String fullStatement) {
- return new SqlStatementInfo(fullStatement, getClass().getSimpleName().toUpperCase(), mainTable);
+ return SqlStatementInfo.create(fullStatement, getClass().getSimpleName().toUpperCase(), mainTable);
}
}
@@ -115,7 +115,7 @@ WHITESPACE = [ \t\r\n]+
static final Operation INSTANCE = new NoOp();
SqlStatementInfo getResult(String fullStatement) {
- return new SqlStatementInfo(fullStatement, null, null);
+ return SqlStatementInfo.create(fullStatement, null, null);
}
}

MODIFY
instrumentation/couchbase/couchbase-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseQuerySanitizer.java
instrumentation/couchbase/couchbase-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/couchbase/v2_0/CouchbaseQuerySanitizer.java
@@ -83,7 +83,7 @@ public final class CouchbaseQuerySanitizer {
String queryClassName = query.getClass().getName();
if (queryClassName.equals("com.couchbase.client.java.view.ViewQuery")
|| queryClassName.equals("com.couchbase.client.java.view.SpatialViewQuery")) {
- return new SqlStatementInfo(query.toString(), null, null);
+ return SqlStatementInfo.create(query.toString(), null, null);
}
// N1qlQuery is present starting from Couchbase 2.2.0
if (N1QL_QUERY_CLASS != null && N1QL_QUERY_CLASS.isAssignableFrom(query.getClass())) {
@@ -99,7 +99,7 @@ public final class CouchbaseQuerySanitizer {
return sanitizeString(statement);
}
}
- return new SqlStatementInfo(query.getClass().getSimpleName(), null, null);
+ return SqlStatementInfo.create(query.getClass().getSimpleName(), null, null);
}
private static String getStatementString(MethodHandle handle, Object query) {

MODIFY
instrumentation/jdbc/javaagent-unittests/src/test/groovy/JdbcConnectionUrlParserTest.groovy
instrumentation/jdbc/javaagent-unittests/src/test/groovy/JdbcConnectionUrlParserTest.groovy
@@ -200,6 +200,6 @@ class JdbcConnectionUrlParserTest extends Specification {
"jdbc:derby:jar:/derbydb;user=derbyuser;password=pw" | null | "derby:jar:" | "derby" | "jar" | "derbyuser" | null | null | "/derbydb" | null
"jdbc:derby:jar:(~/path/to/db.jar)/other/derbydb;user=derbyuser;password=pw" | null | "derby:jar:" | "derby" | "jar" | "derbyuser" | null | null | "(~/path/to/db.jar)/other/derbydb" | null
- expected = new DbInfo.Builder().system(system).subtype(subtype).user(user).name(name).db(db).host(host).port(port).shortUrl(shortUrl).build()
+ expected = DbInfo.builder().system(system).subtype(subtype).user(user).name(name).db(db).host(host).port(port).shortUrl(shortUrl).build()
}
}

MODIFY
instrumentation/jdbc/javaagent/jdbc-javaagent.gradle
instrumentation/jdbc/javaagent/jdbc-javaagent.gradle
@@ -7,6 +7,10 @@ muzzle {
}
dependencies {
+
+ compileOnly deps.autoValueAnnotations
+ annotationProcessor deps.autoValue
+
// jdbc unit testing
testLibrary group: 'com.h2database', name: 'h2', version: '1.3.169'
// first version jdk 1.6 compatible

MODIFY
instrumentation/jdbc/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jdbc/DbInfo.java
instrumentation/jdbc/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jdbc/DbInfo.java
package io.opentelemetry.javaagent.instrumentation.jdbc;
-import java.util.Objects;
-
-public class DbInfo {
-
- public static final DbInfo DEFAULT = new Builder().build();
-
- private final String system;
- private final String subtype;
- private final String shortUrl; // "type:[subtype:]//host:port"
- private final String user;
- private final String name;
- private final String db;
- private final String host;
- private final Integer port;
-
- public DbInfo(
- String system,
- String subtype,
- String shortUrl,
- String user,
- String name,
- String db,
- String host,
- Integer port) {
- this.system = system;
- this.subtype = subtype;
- this.shortUrl = shortUrl;
- this.user = user;
- this.name = name;
- this.db = db;
- this.host = host;
- this.port = port;
- }
+import com.google.auto.value.AutoValue;
+import javax.annotation.Nullable;
- public String getSystem() {
- return system;
- }
+@AutoValue
+public abstract class DbInfo {
- public String getSubtype() {
- return subtype;
- }
+ public static final DbInfo DEFAULT = builder().build();
- public String getShortUrl() {
- return shortUrl;
+ public static DbInfo.Builder builder() {
+ return new AutoValue_DbInfo.Builder();
}
- public String getUser() {
- return user;
- }
+ @Nullable
+ public abstract String getSystem();
- public String getName() {
- return name;
- }
+ @Nullable
+ public abstract String getSubtype();
- public String getDb() {
- return db;
- }
+ // "type:[subtype:]//host:port"
+ @Nullable
+ public abstract String getShortUrl();
- public String getHost() {
- return host;
- }
+ @Nullable
+ public abstract String getUser();
- public Integer getPort() {
- return port;
- }
+ @Nullable
+ public abstract String getName();
- public Builder toBuilder() {
- return new Builder()
- .system(system)
- .subtype(subtype)
- .shortUrl(shortUrl)
- .user(user)
- .name(name)
- .db(db)
- .host(host)
- .port(port);
- }
+ @Nullable
+ public abstract String getDb();
- @Override
- public boolean equals(Object obj) {
- if (obj == this) {
- return true;
- }
- if (!(obj instanceof DbInfo)) {
- return false;
- }
- DbInfo other = (DbInfo) obj;
- return Objects.equals(system, other.system)
- && Objects.equals(subtype, other.subtype)
- && Objects.equals(shortUrl, other.shortUrl)
- && Objects.equals(user, other.user)
- && Objects.equals(name, other.name)
- && Objects.equals(db, other.db)
- && Objects.equals(host, other.host)
- && Objects.equals(port, other.port);
- }
+ @Nullable
+ public abstract String getHost();
- @Override
- public int hashCode() {
- return Objects.hash(system, subtype, shortUrl, user, name, db, host, port);
- }
+ @Nullable
+ public abstract Integer getPort();
- public static class Builder {
- private String system;
- private String subtype;
- private String shortUrl;
- private String user;
- private String name;
- private String db;
- private String host;
- private Integer port;
-
- public Builder system(String system) {
- this.system = system;
- return this;
+ public Builder toBuilder() {
+ return builder()
+ .system(getSystem())
+ .subtype(getSubtype())
+ .shortUrl(getShortUrl())
+ .user(getUser())
+ .name(getName())
+ .db(getDb())
+ .host(getHost())
+ .port(getPort());
}
- public Builder subtype(String subtype) {
- this.subtype = subtype;
- return this;
- }
+ @AutoValue.Builder
+ public abstract static class Builder {
- public Builder shortUrl(String shortUrl) {
- this.shortUrl = shortUrl;
- return this;
- }
+ public abstract Builder system(String system);
- public Builder user(String user) {
- this.user = user;
- return this;
- }
+ public abstract Builder subtype(String subtype);
- public Builder name(String name) {
- this.name = name;
- return this;
- }
+ public abstract Builder shortUrl(String shortUrl);
- public Builder db(String db) {
- this.db = db;
- return this;
- }
+ public abstract Builder user(String user);
- public Builder host(String host) {
- this.host = host;
- return this;
- }
+ public abstract Builder name(String name);
- public Builder port(Integer port) {
- this.port = port;
- return this;
- }
+ public abstract Builder db(String db);
- public DbInfo build() {
- return new DbInfo(system, subtype, shortUrl, user, name, db, host, port);
- }
+ public abstract Builder host(String host);
+
+ public abstract Builder port(Integer port);
+
+ public abstract DbInfo build();
}
}

MODIFY
javaagent-api/javaagent-api.gradle
javaagent-api/javaagent-api.gradle
@@ -11,6 +11,8 @@ dependencies {
compileOnly deps.opentelemetrySdk
implementation deps.slf4j
implementation project(':instrumentation-api')
+ compileOnly deps.autoValueAnnotations
+ annotationProcessor deps.autoValue
testImplementation project(':testing-common')
testImplementation deps.mockito

Auto value (#2494)

* SqlStatementInfo as AutoValue

* RequestMeta as AutoValue

* DbInfo as AutoValue

* After merge compilation fix

* CouchbaseQuerySanitizer compilation fix

* JdbcConnectionUrlParserTest compilation fix

* Revert "RequestMeta as AutoValue"

This reverts commit 609b57ee48997ed284cb554793909f6ada94614d.