Skip to content

Commit bd26491

Browse files
committed
Make DDSpan a SelfScopedContext to further reduce allocations
1 parent eb9effc commit bd26491

3 files changed

Lines changed: 5 additions & 2 deletions

File tree

components/context/src/main/java/datadog/context/SelfScopedContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package datadog.context;
22

33
/** Context that acts as its own unattached scope. */
4-
interface SelfScopedContext extends Context, ContextScope {
4+
public interface SelfScopedContext extends Context, ContextScope {
55
@Override
66
default ContextScope asScope() {
77
return this; // acts as no-op scope, avoiding allocation

dd-trace-core/src/main/java/datadog/trace/core/DDSpan.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import static java.util.concurrent.TimeUnit.MILLISECONDS;
1010
import static java.util.concurrent.TimeUnit.NANOSECONDS;
1111

12+
import datadog.context.SelfScopedContext;
1213
import datadog.trace.api.Config;
1314
import datadog.trace.api.DDSpanId;
1415
import datadog.trace.api.DDTags;
@@ -50,7 +51,8 @@
5051
* <p>Spans are created by the {@link CoreTracer#buildSpan}. This implementation adds some features
5152
* according to the DD agent.
5253
*/
53-
public class DDSpan implements AgentSpan, CoreSpan<DDSpan>, AttachableWrapper {
54+
@SuppressWarnings("resource")
55+
public class DDSpan implements AgentSpan, CoreSpan<DDSpan>, AttachableWrapper, SelfScopedContext {
5456
private static final Logger log = LoggerFactory.getLogger(DDSpan.class);
5557

5658
static DDSpan create(

dd-trace-core/src/main/java/datadog/trace/core/PendingTrace.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ private void trackRunningTrace(final DDSpan span) {
210210
}
211211

212212
Integer evaluateSamplingPriority() {
213+
@SuppressWarnings("resource")
213214
DDSpan span = spans.peek();
214215
if (span == null) {
215216
return null;

0 commit comments

Comments
 (0)