Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
switched to setClientInfo
  • Loading branch information
nenadnoveljic committed Dec 12, 2024
commit 98f01640f3d3bba144befa3bd2d00aa29fe59620
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