Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package datadog.trace.instrumentation.opentelemetry;

import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopScope;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopSpanContext;

Expand All @@ -16,12 +15,10 @@
public class TypeConverter {
private final Span noopSpanWrapper;
private final SpanContext noopContextWrapper;
private final OtelScope noopScopeWrapper;

public TypeConverter() {
noopSpanWrapper = new OtelSpan(noopSpan(), this);
noopContextWrapper = new OtelSpanContext(noopSpanContext());
noopScopeWrapper = new OtelScope(noopScope());
}

public AgentSpan toAgentSpan(final Span span) {
Expand Down Expand Up @@ -55,9 +52,6 @@ public Scope toScope(final AgentScope scope) {
if (scope == null) {
return null;
}
if (scope == noopScope()) {
return noopScopeWrapper;
}
return new OtelScope(scope);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import datadog.trace.core.PendingTrace
import datadog.trace.core.propagation.PropagationTags
import datadog.trace.instrumentation.opentelemetry.TypeConverter

import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopScope
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopSpan
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopSpanContext

Expand Down Expand Up @@ -39,12 +38,6 @@ class TypeConverterTest extends InstrumentationSpecification {
typeConverter.toSpanContext(noopContext) is typeConverter.toSpanContext(noopContext)
}

def "should avoid the noop scope wrapper allocation"() {
def noopScope = noopScope()
expect:
typeConverter.toScope(noopScope) is typeConverter.toScope(noopScope)
}

def createTestSpanContext() {
def trace = Stub(PendingTrace)
return new DDSpanContext(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package datadog.trace.instrumentation.opentracing31;

import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopScope;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopSpanContext;

Expand All @@ -18,13 +17,11 @@ public class TypeConverter {
private final LogHandler logHandler;
private final OTSpan noopSpanWrapper;
private final OTSpanContext noopContextWrapper;
private final OTScopeManager.OTScope noopScopeWrapper;

public TypeConverter(final LogHandler logHandler) {
this.logHandler = logHandler;
noopSpanWrapper = new OTSpan(noopSpan(), this, logHandler);
noopContextWrapper = new OTSpanContext(noopSpanContext());
noopScopeWrapper = new OTScopeManager.OTScope(noopScope(), false, this);
}

public AgentSpan toAgentSpan(final Span span) {
Expand Down Expand Up @@ -58,9 +55,6 @@ public Scope toScope(final AgentScope scope, final boolean finishSpanOnClose) {
if (scope == null) {
return null;
}
if (scope == noopScope()) {
return noopScopeWrapper;
}
return new OTScopeManager.OTScope(scope, finishSpanOnClose, this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import datadog.trace.core.DDSpanContext
import datadog.trace.core.PendingTrace
import datadog.trace.core.propagation.PropagationTags
import datadog.trace.instrumentation.opentracing.DefaultLogHandler
import datadog.trace.bootstrap.instrumentation.api.AgentScope
import datadog.trace.instrumentation.opentracing31.TypeConverter

import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopScope
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopSpan
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopSpanContext

Expand Down Expand Up @@ -40,14 +40,14 @@ class TypeConverterTest extends InstrumentationSpecification {
typeConverter.toSpanContext(noopContext) is typeConverter.toSpanContext(noopContext)
}

def "should avoid the noop scope wrapper allocation"() {
def noopScope = noopScope()
def "should reuse the noop span wrapper via scope"() {
def noopScope = Stub(AgentScope) {
span() >> noopSpan()
}
def noopSpanWrapper = typeConverter.toSpan(noopSpan())
expect:
typeConverter.toScope(noopScope, true) is typeConverter.toScope(noopScope, true)
typeConverter.toScope(noopScope, false) is typeConverter.toScope(noopScope, false)
// noop scopes expected to be the same despite the finishSpanOnClose flag
typeConverter.toScope(noopScope, true) is typeConverter.toScope(noopScope, false)
typeConverter.toScope(noopScope, false) is typeConverter.toScope(noopScope, true)
typeConverter.toScope(noopScope, true).span() is noopSpanWrapper
typeConverter.toScope(noopScope, false).span() is noopSpanWrapper
}

def createTestSpanContext() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package datadog.trace.instrumentation.opentracing32;

import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopScope;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopSpanContext;

Expand All @@ -18,13 +17,11 @@ public class TypeConverter {
private final LogHandler logHandler;
private final OTSpan noopSpanWrapper;
private final OTSpanContext noopContextWrapper;
private final OTScopeManager.OTScope noopScopeWrapper;

public TypeConverter(final LogHandler logHandler) {
this.logHandler = logHandler;
noopSpanWrapper = new OTSpan(noopSpan(), this, logHandler);
noopContextWrapper = new OTSpanContext(noopSpanContext());
noopScopeWrapper = new OTScopeManager.OTScope(noopScope(), false, this);
}

public AgentSpan toAgentSpan(final Span span) {
Expand Down Expand Up @@ -58,9 +55,6 @@ public Scope toScope(final AgentScope scope, final boolean finishSpanOnClose) {
if (scope == null) {
return null;
}
if (scope == noopScope()) {
return noopScopeWrapper;
}
return new OTScopeManager.OTScope(scope, finishSpanOnClose, this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import datadog.trace.core.DDSpanContext
import datadog.trace.core.PendingTrace
import datadog.trace.core.propagation.PropagationTags
import datadog.trace.instrumentation.opentracing.DefaultLogHandler
import datadog.trace.bootstrap.instrumentation.api.AgentScope
import datadog.trace.instrumentation.opentracing32.TypeConverter

import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopScope
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopSpan
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopSpanContext

Expand Down Expand Up @@ -40,14 +40,14 @@ class TypeConverterTest extends InstrumentationSpecification {
typeConverter.toSpanContext(noopContext) is typeConverter.toSpanContext(noopContext)
}

def "should avoid the noop scope wrapper allocation"() {
def noopScope = noopScope()
def "should reuse the noop span wrapper via scope"() {
def noopScope = Stub(AgentScope) {
span() >> noopSpan()
}
def noopSpanWrapper = typeConverter.toSpan(noopSpan())
expect:
typeConverter.toScope(noopScope, true) is typeConverter.toScope(noopScope, true)
typeConverter.toScope(noopScope, false) is typeConverter.toScope(noopScope, false)
// noop scopes expected to be the same despite the finishSpanOnClose flag
typeConverter.toScope(noopScope, true) is typeConverter.toScope(noopScope, false)
typeConverter.toScope(noopScope, false) is typeConverter.toScope(noopScope, true)
typeConverter.toScope(noopScope, true).span() is noopSpanWrapper
typeConverter.toScope(noopScope, false).span() is noopSpanWrapper
}

def createTestSpanContext() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package datadog.opentracing;

import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopScope;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopSpanContext;

Expand All @@ -17,13 +16,11 @@ class TypeConverter {
private final LogHandler logHandler;
private final OTSpan noopSpanWrapper;
private final OTSpanContext noopContextWrapper;
private final OTScopeManager.OTScope noopScopeWrapper;

public TypeConverter(final LogHandler logHandler) {
this.logHandler = logHandler;
noopSpanWrapper = new OTSpan(noopSpan(), this, logHandler);
noopContextWrapper = new OTSpanContext(noopSpanContext());
noopScopeWrapper = new OTScopeManager.OTScope(noopScope(), false, this);
}

public AgentSpan toAgentSpan(final Span span) {
Expand Down Expand Up @@ -61,9 +58,6 @@ public Scope toScope(final AgentScope scope, final boolean finishSpanOnClose) {
if (scope == null) {
return null;
}
if (scope == noopScope()) {
return noopScopeWrapper;
}
return new OTScopeManager.OTScope(scope, finishSpanOnClose, this);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package datadog.opentracing;

import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopScope;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopSpan;
import static datadog.trace.bootstrap.instrumentation.api.AgentTracer.noopSpanContext;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import datadog.trace.bootstrap.instrumentation.api.AgentScope;
import datadog.trace.bootstrap.instrumentation.api.AgentSpan;
import datadog.trace.common.writer.ListWriter;
import datadog.trace.core.CoreTracer;
Expand Down Expand Up @@ -45,20 +47,11 @@ void shouldAvoidTheNoopContextWrapperAllocation() {
}

@Test
void shouldAvoidTheNoopScopeWrapperAllocation() {
datadog.trace.bootstrap.instrumentation.api.AgentScope noopScopeInstance = noopScope();
assertSame(
typeConverter.toScope(noopScopeInstance, true),
typeConverter.toScope(noopScopeInstance, true));
assertSame(
typeConverter.toScope(noopScopeInstance, false),
typeConverter.toScope(noopScopeInstance, false));
// noop scopes expected to be the same despite the finishSpanOnClose flag
assertSame(
typeConverter.toScope(noopScopeInstance, true),
typeConverter.toScope(noopScopeInstance, false));
assertSame(
typeConverter.toScope(noopScopeInstance, false),
typeConverter.toScope(noopScopeInstance, true));
void shouldReuseNoopSpanWrapperViaScope() {
AgentScope noopScope = mock(AgentScope.class);
when(noopScope.span()).thenReturn(noopSpan());
OTSpan noopSpanWrapper = typeConverter.toSpan(noopSpan());
assertSame(typeConverter.toScope(noopScope, true).span(), noopSpanWrapper);
assertSame(typeConverter.toScope(noopScope, false).span(), noopSpanWrapper);
}
}
Loading