Skip to content

Commit 5db793a

Browse files
authored
In JDBC instrumentation, use singleSpanBuilder instead of buildSpan (#9927)
* Using singleSpanBuilder instead of buildSpan * spotless
1 parent 1397f25 commit 5db793a

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/AbstractPreparedStatementInstrumentation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public static AgentScope onEnter(@Advice.This final Statement statement) {
8686
// The span ID is pre-determined so that we can reference it when setting the context
8787
final long spanID = DECORATE.setContextInfo(connection, dbInfo);
8888
// we then force that pre-determined span ID for the span covering the actual query
89-
span = AgentTracer.get().buildSpan(DATABASE_QUERY).withSpanId(spanID).start();
89+
span = AgentTracer.get().singleSpanBuilder(DATABASE_QUERY).withSpanId(spanID).start();
9090
span.setTag(DBM_TRACE_INJECTED, true);
9191
} else if (DECORATE.isPostgres(dbInfo) && DBM_TRACE_PREPARED_STATEMENTS) {
9292
span = startSpan(DATABASE_QUERY);

dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/JDBCDecorator.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,10 @@ public long setContextInfo(Connection connection, DBInfo dbInfo) {
319319
final long spanID = Config.get().getIdGenerationStrategy().generateSpanId();
320320
// potentially get build span like here
321321
AgentSpan instrumentationSpan =
322-
AgentTracer.get().buildSpan("set context_info").withTag("dd.instrumentation", true).start();
322+
AgentTracer.get()
323+
.singleSpanBuilder("set context_info")
324+
.withTag("dd.instrumentation", true)
325+
.start();
323326
DECORATE.afterStart(instrumentationSpan);
324327
DECORATE.onConnection(instrumentationSpan, dbInfo);
325328
try (AgentScope scope = activateSpan(instrumentationSpan)) {

dd-java-agent/instrumentation/jdbc/src/main/java/datadog/trace/instrumentation/jdbc/StatementInstrumentation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public static AgentScope onEnter(
9494
// The span ID is pre-determined so that we can reference it when setting the context
9595
final long spanID = DECORATE.setContextInfo(connection, dbInfo);
9696
// we then force that pre-determined span ID for the span covering the actual query
97-
span = AgentTracer.get().buildSpan(DATABASE_QUERY).withSpanId(spanID).start();
97+
span = AgentTracer.get().singleSpanBuilder(DATABASE_QUERY).withSpanId(spanID).start();
9898
} else if (isOracle) {
9999
span = startSpan(DATABASE_QUERY);
100100
DECORATE.setAction(span, connection);

internal-api/src/main/java/datadog/trace/bootstrap/instrumentation/api/AgentTracer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,11 @@ default SpanBuilder buildSpan(CharSequence spanName) {
373373
return buildSpan(DEFAULT_INSTRUMENTATION_NAME, spanName);
374374
}
375375

376+
@Deprecated
377+
default SpanBuilder singleSpanBuilder(CharSequence spanName) {
378+
return singleSpanBuilder(DEFAULT_INSTRUMENTATION_NAME, spanName);
379+
}
380+
376381
/**
377382
* Returns a SpanBuilder that can be used to produce multiple spans. To minimize overhead, use
378383
* of {@link #singleSpanBuilder(String, CharSequence)} is preferred when only a single span is

0 commit comments

Comments
 (0)