Skip to content

Commit

Permalink
switched to setClientInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
nenadnoveljic committed Dec 12, 2024
1 parent f159cd9 commit 98f0164
Showing 1 changed file with 1 addition and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import datadog.trace.bootstrap.instrumentation.jdbc.DBInfo;
import datadog.trace.bootstrap.instrumentation.jdbc.DBQueryInfo;
import datadog.trace.bootstrap.instrumentation.jdbc.JDBCConnectionUrlParser;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.sql.Connection;
Expand All @@ -30,7 +29,6 @@
import java.sql.Statement;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -50,8 +48,6 @@ public class JDBCDecorator extends DatabaseClientDecorator<DBInfo> {
SpanNaming.instance().namingSchema().database().service("jdbc");
public static final String DBM_PROPAGATION_MODE_STATIC = "service";
public static final String DBM_PROPAGATION_MODE_FULL = "full";
private static final Pattern traceParentPattern =
Pattern.compile("^00-[a-f0-9]{32}-[a-f0-9]{16}-[a-f0-9]{2}$");

public static final String DBM_PROPAGATION_MODE = Config.get().getDBMPropagationMode();
public static final boolean INJECT_COMMENT =
Expand Down Expand Up @@ -333,9 +329,6 @@ public long setContextInfo(Connection connection, DBInfo dbInfo) {
* @param span The span of the instrumented statement
* @param connection The same connection as the one that will be used for the actual statement
*/
@SuppressFBWarnings(
value = "SQL_NONCONSTANT_STRING_PASSED_TO_EXECUTE",
justification = "Prepared statement not possible with SET")
public void setApplicationName(AgentSpan span, Connection connection) {
final long startTime = System.currentTimeMillis();
try {
Expand All @@ -345,15 +338,9 @@ public void setApplicationName(AgentSpan span, Connection connection) {
return;
}
final String traceParent = DECORATE.traceParent(span, priority);
if (traceParent == null || !traceParentPattern.matcher(traceParent).matches()) {
throw new IllegalArgumentException("Invalid trace parent: " + traceParent);
}
final String traceContext = "_DD_" + traceParent;

// SET doesn't work with parameters
try (Statement statement = connection.createStatement()) {
statement.execute("SET application_name = '" + traceContext + "';");
}
connection.setClientInfo("ApplicationName", traceContext);
} catch (Throwable e) {
if (log.isDebugEnabled()) {
log.debug(
Expand Down

0 comments on commit 98f0164

Please sign in to comment.