Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enrich JDBC spans with db.operation and db.sql.table #2425

Merged
merged 1 commit into from Feb 27, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -7,10 +7,12 @@

import static io.opentelemetry.javaagent.instrumentation.jdbc.JdbcUtils.connectionFromStatement;

import io.opentelemetry.api.trace.SpanBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.tracer.DatabaseClientTracer;
import io.opentelemetry.javaagent.instrumentation.api.db.SqlStatementInfo;
import io.opentelemetry.javaagent.instrumentation.api.db.SqlStatementSanitizer;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.net.InetSocketAddress;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
Expand Down Expand Up @@ -87,12 +89,28 @@ protected InetSocketAddress peerAddress(DbInfo dbInfo) {
return null;
}

@Override
protected void onStatement(
SpanBuilder span, DbInfo connection, String statement, SqlStatementInfo sanitizedStatement) {
super.onStatement(span, connection, statement, sanitizedStatement);
String table = sanitizedStatement.getTable();
if (table != null) {
span.setAttribute(SemanticAttributes.DB_SQL_TABLE, table);
}
}

@Override
protected String dbStatement(
DbInfo connection, String statement, SqlStatementInfo sanitizedStatement) {
return sanitizedStatement.getFullStatement();
}

@Override
protected String dbOperation(
DbInfo connection, String statement, SqlStatementInfo sanitizedStatement) {
return sanitizedStatement.getOperation();
}

private DbInfo extractDbInfo(Connection connection) {
DbInfo dbInfo = JdbcMaps.connectionInfo.get(connection);
/*
Expand Down