Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.vertx.sqlclient.SqlConnectOptions;
import io.vertx.sqlclient.impl.PreparedStatement;
import io.vertx.sqlclient.impl.QueryExecutorUtil;
import java.util.Collection;
import javax.annotation.Nullable;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
Expand Down Expand Up @@ -73,7 +74,7 @@ private AdviceScope(
this.scope = scope;
}

public static AdviceScope start(Object queryExecutor, Object[] arguments) {
public static AdviceScope start(Object queryExecutor, String methodName, Object[] arguments) {
CallDepth callDepth = CallDepth.forClass(queryExecutor.getClass());
if (callDepth.getAndIncrement() > 0) {
return new AdviceScope(callDepth);
Expand All @@ -86,6 +87,7 @@ public static AdviceScope start(Object queryExecutor, Object[] arguments) {
String sql = null;
boolean preparedStatement = false;
PromiseInternal<?> promiseInternal = null;
Long batchSize = null;
for (Object argument : arguments) {
if (sql == null) {
if (argument instanceof String) {
Expand All @@ -97,6 +99,10 @@ public static AdviceScope start(Object queryExecutor, Object[] arguments) {
} else if (argument instanceof PromiseInternal) {
promiseInternal = (PromiseInternal<?>) argument;
}
if (methodName.equals("executeBatchQuery") && argument instanceof Collection) {
int size = ((Collection<?>) argument).size();
batchSize = size > 1 ? (long) size : null;
}
}
if (sql == null || promiseInternal == null) {
return new AdviceScope(callDepth);
Expand All @@ -116,7 +122,7 @@ public static AdviceScope start(Object queryExecutor, Object[] arguments) {
dbSystem = VertxSqlClientUtil.getDbSystemNameFromClassName(connectOptions);
}
VertxSqlClientRequest otelRequest =
new VertxSqlClientRequest(sql, connectOptions, preparedStatement, dbSystem);
new VertxSqlClientRequest(sql, connectOptions, preparedStatement, dbSystem, batchSize);
Context parentContext = Context.current();
if (!instrumenter().shouldStart(parentContext, otelRequest)) {
return new AdviceScope(callDepth);
Expand Down Expand Up @@ -145,8 +151,10 @@ public void end(@Nullable Throwable throwable) {

@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
public static AdviceScope onEnter(
@Advice.This Object queryExecutor, @Advice.AllArguments Object[] arguments) {
return AdviceScope.start(queryExecutor, arguments);
@Advice.This Object queryExecutor,
@Advice.Origin("#m") String methodName,
@Advice.AllArguments Object[] arguments) {
return AdviceScope.start(queryExecutor, methodName, arguments);
}

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class, inline = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
import static io.opentelemetry.semconv.DbAttributes.DB_NAMESPACE;
import static io.opentelemetry.semconv.DbAttributes.DB_OPERATION_BATCH_SIZE;
import static io.opentelemetry.semconv.DbAttributes.DB_QUERY_SUMMARY;
import static io.opentelemetry.semconv.DbAttributes.DB_SYSTEM_NAME;
import static io.opentelemetry.semconv.ErrorAttributes.ERROR_TYPE;
Expand Down Expand Up @@ -296,7 +297,10 @@ void testBatch() throws Exception {
trace.hasSpansSatisfyingExactly(
span -> span.hasName("parent").hasKind(SpanKind.INTERNAL),
span ->
span.hasName(emitStableDatabaseSemconv() ? "insert test" : "INSERT tempdb.test")
span.hasName(
emitStableDatabaseSemconv()
? "BATCH insert test"
: "INSERT tempdb.test")
.hasKind(SpanKind.CLIENT)
.hasParent(trace.getSpan(0))
.hasAttributesSatisfyingExactly(
Expand All @@ -310,7 +314,9 @@ void testBatch() throws Exception {
"insert into test values ($1, $2) returning *"),
equalTo(
DB_QUERY_SUMMARY,
emitStableDatabaseSemconv() ? "insert test" : null),
emitStableDatabaseSemconv() ? "BATCH insert test" : null),
equalTo(
DB_OPERATION_BATCH_SIZE, emitStableDatabaseSemconv() ? 2L : null),
equalTo(
maybeStable(DB_OPERATION),
emitStableDatabaseSemconv() ? null : "INSERT"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.vertx.sqlclient.SqlConnectOptions;
import io.vertx.sqlclient.impl.QueryExecutorUtil;
import io.vertx.sqlclient.internal.PreparedStatement;
import java.util.Collection;
import javax.annotation.Nullable;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
Expand Down Expand Up @@ -72,7 +73,7 @@ private AdviceScope(
this.scope = scope;
}

public static AdviceScope start(Object queryExecutor, Object[] arguments) {
public static AdviceScope start(Object queryExecutor, String methodName, Object[] arguments) {
CallDepth callDepth = CallDepth.forClass(queryExecutor.getClass());
if (callDepth.getAndIncrement() > 0) {
return new AdviceScope(callDepth);
Expand All @@ -85,6 +86,7 @@ public static AdviceScope start(Object queryExecutor, Object[] arguments) {
String sql = null;
boolean preparedStatement = false;
PromiseInternal<?> promiseInternal = null;
Long batchSize = null;
for (Object argument : arguments) {
if (sql == null) {
if (argument instanceof String) {
Expand All @@ -96,6 +98,10 @@ public static AdviceScope start(Object queryExecutor, Object[] arguments) {
} else if (argument instanceof PromiseInternal) {
promiseInternal = (PromiseInternal<?>) argument;
}
if (methodName.equals("executeBatchQuery") && argument instanceof Collection) {
int size = ((Collection<?>) argument).size();
batchSize = size > 1 ? (long) size : null;
}
}
if (sql == null || promiseInternal == null) {
return new AdviceScope(callDepth);
Expand All @@ -110,7 +116,7 @@ public static AdviceScope start(Object queryExecutor, Object[] arguments) {
}
String dbSystem = VertxSqlClientSingletons.getConnectOptionsDbSystem(connectOptions);
VertxSqlClientRequest otelRequest =
new VertxSqlClientRequest(sql, connectOptions, preparedStatement, dbSystem);
new VertxSqlClientRequest(sql, connectOptions, preparedStatement, dbSystem, batchSize);
Context parentContext = Context.current();
if (!instrumenter().shouldStart(parentContext, otelRequest)) {
return new AdviceScope(callDepth);
Expand Down Expand Up @@ -139,8 +145,10 @@ public void end(@Nullable Throwable throwable) {

@Advice.OnMethodEnter(suppress = Throwable.class, inline = false)
public static AdviceScope onEnter(
@Advice.This Object queryExecutor, @Advice.AllArguments Object[] arguments) {
return AdviceScope.start(queryExecutor, arguments);
@Advice.This Object queryExecutor,
@Advice.Origin("#m") String methodName,
@Advice.AllArguments Object[] arguments) {
return AdviceScope.start(queryExecutor, methodName, arguments);
}

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class, inline = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.satisfies;
import static io.opentelemetry.semconv.DbAttributes.DB_NAMESPACE;
import static io.opentelemetry.semconv.DbAttributes.DB_OPERATION_BATCH_SIZE;
import static io.opentelemetry.semconv.DbAttributes.DB_QUERY_SUMMARY;
import static io.opentelemetry.semconv.DbAttributes.DB_SYSTEM_NAME;
import static io.opentelemetry.semconv.ErrorAttributes.ERROR_TYPE;
Expand Down Expand Up @@ -297,7 +298,10 @@ void testBatch() throws Exception {
trace.hasSpansSatisfyingExactly(
span -> span.hasName("parent").hasKind(SpanKind.INTERNAL),
span ->
span.hasName(emitStableDatabaseSemconv() ? "insert test" : "INSERT tempdb.test")
span.hasName(
emitStableDatabaseSemconv()
? "BATCH insert test"
: "INSERT tempdb.test")
.hasKind(SpanKind.CLIENT)
.hasParent(trace.getSpan(0))
.hasAttributesSatisfyingExactly(
Expand All @@ -311,7 +315,9 @@ void testBatch() throws Exception {
"insert into test values ($1, $2) returning *"),
equalTo(
DB_QUERY_SUMMARY,
emitStableDatabaseSemconv() ? "insert test" : null),
emitStableDatabaseSemconv() ? "BATCH insert test" : null),
equalTo(
DB_OPERATION_BATCH_SIZE, emitStableDatabaseSemconv() ? 2L : null),
equalTo(
maybeStable(DB_OPERATION),
emitStableDatabaseSemconv() ? null : "INSERT"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ public Collection<String> getRawQueryTexts(VertxSqlClientRequest request) {
return singleton(request.getQueryText());
}

@Nullable
@Override
public Long getDbOperationBatchSize(VertxSqlClientRequest request) {
return request.getOperationBatchSize();
}

@Nullable
@Override
public String getErrorType(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@ public class VertxSqlClientRequest {
@Nullable private final SqlConnectOptions sqlConnectOptions;
private final boolean parameterizedQuery;
private final String dbSystemName;
@Nullable private final Long operationBatchSize;

public VertxSqlClientRequest(
String queryText,
@Nullable SqlConnectOptions sqlConnectOptions,
boolean parameterizedQuery,
String dbSystemName) {
String dbSystemName,
@Nullable Long operationBatchSize) {
this.queryText = queryText;
this.sqlConnectOptions = sqlConnectOptions;
this.parameterizedQuery = parameterizedQuery;
this.dbSystemName = dbSystemName;
this.operationBatchSize = operationBatchSize;
}

public String getQueryText() {
Expand Down Expand Up @@ -57,4 +60,9 @@ public boolean isParameterizedQuery() {
public String getDbSystemName() {
return dbSystemName;
}

@Nullable
public Long getOperationBatchSize() {
return operationBatchSize;
}
}
Loading