|
@@ -7,6 +7,7 @@ package io.opentelemetry.instrumentation.api.instrumenter;
|
|
|
|
|
|
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat;
|
|
|
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
|
|
|
+import static java.util.Collections.emptyMap;
|
|
|
import static org.assertj.core.api.Assertions.entry;
|
|
|
import static org.mockito.Mockito.when;
|
|
|
|
|
@@ -361,6 +362,58 @@ class InstrumenterTest {
|
|
|
.hasParentSpanId("090a0b0c0d0e0f00")));
|
|
|
}
|
|
|
|
|
|
+ @Test
|
|
|
+ void upstream_customSpanKind() {
|
|
|
+ Instrumenter<Map<String, String>, Map<String, String>> instrumenter =
|
|
|
+ Instrumenter.<Map<String, String>, Map<String, String>>builder(
|
|
|
+ otelTesting.getOpenTelemetry(), "test", unused -> "span")
|
|
|
+ .buildUpstreamInstrumenter(new MapGetter(), SpanKindExtractor.alwaysInternal());
|
|
|
+
|
|
|
+ Map<String, String> request = new HashMap<>();
|
|
|
+ request.put("traceparent", "00-ff01020304050600ff0a0b0c0d0e0f00-090a0b0c0d0e0f00-01");
|
|
|
+ Context context = instrumenter.start(Context.root(), request);
|
|
|
+
|
|
|
+ SpanContext spanContext = Span.fromContext(context).getSpanContext();
|
|
|
+ assertThat(spanContext.isValid()).isTrue();
|
|
|
+
|
|
|
+ instrumenter.end(context, request, emptyMap(), null);
|
|
|
+
|
|
|
+ otelTesting
|
|
|
+ .assertTraces()
|
|
|
+ .hasTracesSatisfyingExactly(
|
|
|
+ trace ->
|
|
|
+ trace.hasSpansSatisfyingExactly(
|
|
|
+ span ->
|
|
|
+ span.hasName("span")
|
|
|
+ .hasKind(SpanKind.INTERNAL)
|
|
|
+ .hasTraceId("ff01020304050600ff0a0b0c0d0e0f00")
|
|
|
+ .hasParentSpanId("090a0b0c0d0e0f00")));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void downstream_customSpanKind() {
|
|
|
+ Instrumenter<Map<String, String>, Map<String, String>> instrumenter =
|
|
|
+ Instrumenter.<Map<String, String>, Map<String, String>>builder(
|
|
|
+ otelTesting.getOpenTelemetry(), "test", unused -> "span")
|
|
|
+ .buildDownstreamInstrumenter(Map::put, SpanKindExtractor.alwaysInternal());
|
|
|
+
|
|
|
+ Map<String, String> request = new HashMap<>();
|
|
|
+ Context context = instrumenter.start(Context.root(), request);
|
|
|
+
|
|
|
+ SpanContext spanContext = Span.fromContext(context).getSpanContext();
|
|
|
+ assertThat(spanContext.isValid()).isTrue();
|
|
|
+ assertThat(request).containsKey("traceparent");
|
|
|
+
|
|
|
+ instrumenter.end(context, request, emptyMap(), null);
|
|
|
+
|
|
|
+ otelTesting
|
|
|
+ .assertTraces()
|
|
|
+ .hasTracesSatisfyingExactly(
|
|
|
+ trace ->
|
|
|
+ trace.hasSpansSatisfyingExactly(
|
|
|
+ span -> span.hasName("span").hasKind(SpanKind.INTERNAL)));
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
void operationListeners() {
|
|
|
AtomicReference<Boolean> startContext = new AtomicReference<>();
|
|
@@ -486,10 +539,10 @@ class InstrumenterTest {
|
|
|
Instrumenter<Map<String, String>, Map<String, String>> instrumenter =
|
|
|
builder.buildInstrumenter();
|
|
|
|
|
|
- Context context = instrumenter.start(Context.root(), Collections.emptyMap());
|
|
|
+ Context context = instrumenter.start(Context.root(), emptyMap());
|
|
|
assertThat(Span.fromContext(context)).isNotNull();
|
|
|
|
|
|
- instrumenter.end(context, Collections.emptyMap(), Collections.emptyMap(), null);
|
|
|
+ instrumenter.end(context, emptyMap(), emptyMap(), null);
|
|
|
|
|
|
// see the test-instrumentation.properties file
|
|
|
InstrumentationScopeInfo expectedLibraryInfo =
|
|
@@ -511,10 +564,10 @@ class InstrumenterTest {
|
|
|
.setInstrumentationVersion("1.0")
|
|
|
.buildInstrumenter();
|
|
|
|
|
|
- Context context = instrumenter.start(Context.root(), Collections.emptyMap());
|
|
|
+ Context context = instrumenter.start(Context.root(), emptyMap());
|
|
|
assertThat(Span.fromContext(context)).isNotNull();
|
|
|
|
|
|
- instrumenter.end(context, Collections.emptyMap(), Collections.emptyMap(), null);
|
|
|
+ instrumenter.end(context, emptyMap(), emptyMap(), null);
|
|
|
|
|
|
otelTesting
|
|
|
.assertTraces()
|
|
@@ -537,10 +590,10 @@ class InstrumenterTest {
|
|
|
.setSchemaUrl("https://opentelemetry.io/schemas/1.0.0")
|
|
|
.buildInstrumenter();
|
|
|
|
|
|
- Context context = instrumenter.start(Context.root(), Collections.emptyMap());
|
|
|
+ Context context = instrumenter.start(Context.root(), emptyMap());
|
|
|
assertThat(Span.fromContext(context)).isNotNull();
|
|
|
|
|
|
- instrumenter.end(context, Collections.emptyMap(), Collections.emptyMap(), null);
|
|
|
+ instrumenter.end(context, emptyMap(), emptyMap(), null);
|
|
|
|
|
|
InstrumentationScopeInfo expectedLibraryInfo =
|
|
|
InstrumentationScopeInfo.builder("test")
|