Skip to content

Commit 4f2f209

Browse files
committed
Make DDSpan, NoopSpan, and BlackHoleSpan each SelfScopedContexts to further reduce allocations
1 parent eb9effc commit 4f2f209

4 files changed

Lines changed: 7 additions & 3 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;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package datadog.trace.bootstrap.instrumentation.api;
22

3+
import datadog.context.SelfScopedContext;
34
import datadog.trace.api.DDSpanId;
45
import datadog.trace.api.DDTraceId;
56
import datadog.trace.api.TagMap;
@@ -8,7 +9,7 @@
89
import datadog.trace.api.gateway.RequestContext;
910
import datadog.trace.api.sampling.PrioritySampling;
1011

11-
class NoopSpan extends ImmutableSpan implements AgentSpan {
12+
class NoopSpan extends ImmutableSpan implements AgentSpan, SelfScopedContext {
1213
static final NoopSpan INSTANCE = new NoopSpan();
1314

1415
NoopSpan() {}

0 commit comments

Comments
 (0)