-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Per suggestion: open-telemetry/opentelemetry-java#4900 (review)
- Loading branch information
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
plugins { | ||
id("otel.javaagent-testing") | ||
} | ||
|
||
dependencies { | ||
testLibrary("io.opentelemetry:opentelemetry-opencensus-shim") | ||
testCompileOnly("io.opentelemetry:opentelemetry-api") | ||
} |
55 changes: 55 additions & 0 deletions
55
instrumentation/opencensus-shim/testing/src/test/java/Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; | ||
|
||
import io.opencensus.trace.AttributeValue; | ||
import io.opencensus.trace.Tracing; | ||
import io.opentelemetry.api.common.AttributeKey; | ||
import io.opentelemetry.api.trace.Span; | ||
import io.opentelemetry.api.trace.SpanKind; | ||
import io.opentelemetry.api.trace.Tracer; | ||
import io.opentelemetry.context.Scope; | ||
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; | ||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
|
||
public class Test { | ||
|
||
@RegisterExtension | ||
static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); | ||
|
||
@org.junit.jupiter.api.Test | ||
void test() { | ||
Tracer tracer = testing.getOpenTelemetry().getTracer("test"); | ||
Span span = tracer.spanBuilder("otel-span").setSpanKind(SpanKind.INTERNAL).startSpan(); | ||
Scope scope = span.makeCurrent(); | ||
try { | ||
io.opencensus.trace.Tracer ocTracer = Tracing.getTracer(); | ||
io.opencensus.trace.Span internal = ocTracer.spanBuilder("oc-span").startSpan(); | ||
io.opencensus.common.Scope ocScope = ocTracer.withSpan(internal); | ||
try { | ||
ocTracer | ||
.getCurrentSpan() | ||
.putAttribute("present-on-oc", AttributeValue.booleanAttributeValue(true)); | ||
} finally { | ||
ocScope.close(); | ||
} | ||
internal.end(); | ||
} finally { | ||
scope.close(); | ||
} | ||
span.end(); | ||
|
||
// will pass when the opencensus shim is correctly proxying calls to the ApplicationSpanImpl instance emitted by the javaagent-configured GlobalOpenTelemetry Tracer | ||
testing | ||
.waitAndAssertTraces( | ||
traceAssert -> | ||
traceAssert.hasSpansSatisfyingExactly( | ||
spanAssert -> spanAssert.hasName("otel-span").hasNoParent(), | ||
spanAssert -> | ||
spanAssert | ||
.hasName("oc-span") | ||
.hasParentSpanId(span.getSpanContext().getSpanId()) | ||
.hasAttributesSatisfyingExactly( | ||
equalTo(AttributeKey.booleanKey("present-on-oc"), true)))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters