Start using real java8 in tests. (#1352)
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
This commit is contained in:
parent
f4c175d5df
commit
76ef38955a
|
|
@ -45,11 +45,9 @@ public class DefaultTracerBenchmarks {
|
|||
@Warmup(iterations = 5, time = 1)
|
||||
public void measureFullSpanLifecycle() {
|
||||
span = tracer.spanBuilder("span").startSpan();
|
||||
io.opentelemetry.context.Scope ignored = tracer.withSpan(span);
|
||||
try {
|
||||
try (io.opentelemetry.context.Scope ignored = tracer.withSpan(span)) {
|
||||
// no-op
|
||||
} finally {
|
||||
ignored.close();
|
||||
span.end();
|
||||
}
|
||||
}
|
||||
|
|
@ -72,11 +70,8 @@ public class DefaultTracerBenchmarks {
|
|||
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||
@Warmup(iterations = 5, time = 1)
|
||||
public void measureScopeLifecycle() {
|
||||
io.opentelemetry.context.Scope ignored = tracer.withSpan(span);
|
||||
try {
|
||||
try (io.opentelemetry.context.Scope ignored = tracer.withSpan(span)) {
|
||||
// no-op
|
||||
} finally {
|
||||
ignored.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ import static io.opentelemetry.common.AttributeValue.doubleAttributeValue;
|
|||
import static io.opentelemetry.common.AttributeValue.longAttributeValue;
|
||||
import static io.opentelemetry.common.AttributeValue.stringAttributeValue;
|
||||
|
||||
import io.opentelemetry.common.ReadableKeyValuePairs.KeyValueConsumer;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
|
@ -44,13 +43,7 @@ public class AttributesTest {
|
|||
"key1", stringAttributeValue("value1"),
|
||||
"key2", AttributeValue.longAttributeValue(333));
|
||||
|
||||
attributes.forEach(
|
||||
new KeyValueConsumer<AttributeValue>() {
|
||||
@Override
|
||||
public void consume(String key, AttributeValue value) {
|
||||
entriesSeen.put(key, value);
|
||||
}
|
||||
});
|
||||
attributes.forEach((key, value) -> entriesSeen.put(key, value));
|
||||
|
||||
assertThat(entriesSeen)
|
||||
.containsExactly("key1", stringAttributeValue("value1"), "key2", longAttributeValue(333));
|
||||
|
|
@ -61,13 +54,7 @@ public class AttributesTest {
|
|||
final Map<String, AttributeValue> entriesSeen = new HashMap<>();
|
||||
|
||||
Attributes attributes = Attributes.of("key", stringAttributeValue("value"));
|
||||
attributes.forEach(
|
||||
new KeyValueConsumer<AttributeValue>() {
|
||||
@Override
|
||||
public void consume(String key, AttributeValue value) {
|
||||
entriesSeen.put(key, value);
|
||||
}
|
||||
});
|
||||
attributes.forEach((key, value) -> entriesSeen.put(key, value));
|
||||
assertThat(entriesSeen).containsExactly("key", stringAttributeValue("value"));
|
||||
}
|
||||
|
||||
|
|
@ -75,13 +62,7 @@ public class AttributesTest {
|
|||
public void forEach_empty() {
|
||||
final AtomicBoolean sawSomething = new AtomicBoolean(false);
|
||||
Attributes emptyAttributes = Attributes.empty();
|
||||
emptyAttributes.forEach(
|
||||
new KeyValueConsumer<AttributeValue>() {
|
||||
@Override
|
||||
public void consume(String key, AttributeValue value) {
|
||||
sawSomething.set(true);
|
||||
}
|
||||
});
|
||||
emptyAttributes.forEach((key, value) -> sawSomething.set(true));
|
||||
assertThat(sawSomething.get()).isFalse();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ package io.opentelemetry.common;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import io.opentelemetry.common.ReadableKeyValuePairs.KeyValueConsumer;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
|
@ -39,13 +38,7 @@ public class LabelsTest {
|
|||
"key1", "value1",
|
||||
"key2", "value2");
|
||||
|
||||
labels.forEach(
|
||||
new KeyValueConsumer<String>() {
|
||||
@Override
|
||||
public void consume(String key, String value) {
|
||||
entriesSeen.put(key, value);
|
||||
}
|
||||
});
|
||||
labels.forEach((key, value) -> entriesSeen.put(key, value));
|
||||
|
||||
assertThat(entriesSeen).containsExactly("key1", "value1", "key2", "value2");
|
||||
}
|
||||
|
|
@ -55,13 +48,7 @@ public class LabelsTest {
|
|||
final Map<String, String> entriesSeen = new HashMap<>();
|
||||
|
||||
Labels labels = Labels.of("key", "value");
|
||||
labels.forEach(
|
||||
new KeyValueConsumer<String>() {
|
||||
@Override
|
||||
public void consume(String key, String value) {
|
||||
entriesSeen.put(key, value);
|
||||
}
|
||||
});
|
||||
labels.forEach((key, value) -> entriesSeen.put(key, value));
|
||||
|
||||
assertThat(entriesSeen).containsExactly("key", "value");
|
||||
}
|
||||
|
|
@ -70,13 +57,7 @@ public class LabelsTest {
|
|||
public void forEach_empty() {
|
||||
final AtomicBoolean sawSomething = new AtomicBoolean(false);
|
||||
Labels emptyLabels = Labels.empty();
|
||||
emptyLabels.forEach(
|
||||
new KeyValueConsumer<String>() {
|
||||
@Override
|
||||
public void consume(String key, String value) {
|
||||
sawSomething.set(true);
|
||||
}
|
||||
});
|
||||
emptyLabels.forEach((key, value) -> sawSomething.set(true));
|
||||
assertThat(sawSomething.get()).isFalse();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -81,12 +81,9 @@ public final class DefaultCorrelationContextManagerTest {
|
|||
public void withContext() {
|
||||
assertThat(defaultCorrelationContextManager.getCurrentContext())
|
||||
.isSameInstanceAs(EmptyCorrelationContext.getInstance());
|
||||
Scope wtm = defaultCorrelationContextManager.withContext(DIST_CONTEXT);
|
||||
try {
|
||||
try (Scope wtm = defaultCorrelationContextManager.withContext(DIST_CONTEXT)) {
|
||||
assertThat(defaultCorrelationContextManager.getCurrentContext())
|
||||
.isSameInstanceAs(DIST_CONTEXT);
|
||||
} finally {
|
||||
wtm.close();
|
||||
}
|
||||
assertThat(defaultCorrelationContextManager.getCurrentContext())
|
||||
.isSameInstanceAs(EmptyCorrelationContext.getInstance());
|
||||
|
|
@ -96,12 +93,9 @@ public final class DefaultCorrelationContextManagerTest {
|
|||
public void withContext_nullContext() {
|
||||
assertThat(defaultCorrelationContextManager.getCurrentContext())
|
||||
.isSameInstanceAs(EmptyCorrelationContext.getInstance());
|
||||
Scope wtm = defaultCorrelationContextManager.withContext(null);
|
||||
try {
|
||||
try (Scope wtm = defaultCorrelationContextManager.withContext(null)) {
|
||||
assertThat(defaultCorrelationContextManager.getCurrentContext())
|
||||
.isSameInstanceAs(EmptyCorrelationContext.getInstance());
|
||||
} finally {
|
||||
wtm.close();
|
||||
}
|
||||
assertThat(defaultCorrelationContextManager.getCurrentContext())
|
||||
.isSameInstanceAs(EmptyCorrelationContext.getInstance());
|
||||
|
|
@ -110,22 +104,15 @@ public final class DefaultCorrelationContextManagerTest {
|
|||
@Test
|
||||
public void withContextUsingWrap() {
|
||||
Runnable runnable;
|
||||
Scope wtm = defaultCorrelationContextManager.withContext(DIST_CONTEXT);
|
||||
try {
|
||||
try (Scope wtm = defaultCorrelationContextManager.withContext(DIST_CONTEXT)) {
|
||||
assertThat(defaultCorrelationContextManager.getCurrentContext())
|
||||
.isSameInstanceAs(DIST_CONTEXT);
|
||||
runnable =
|
||||
Context.current()
|
||||
.wrap(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
() ->
|
||||
assertThat(defaultCorrelationContextManager.getCurrentContext())
|
||||
.isSameInstanceAs(DIST_CONTEXT);
|
||||
}
|
||||
});
|
||||
} finally {
|
||||
wtm.close();
|
||||
.isSameInstanceAs(DIST_CONTEXT));
|
||||
}
|
||||
assertThat(defaultCorrelationContextManager.getCurrentContext())
|
||||
.isSameInstanceAs(EmptyCorrelationContext.getInstance());
|
||||
|
|
|
|||
|
|
@ -19,8 +19,6 @@ package io.opentelemetry.metrics;
|
|||
import io.opentelemetry.OpenTelemetry;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.internal.StringUtils;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.Callback;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.DoubleResult;
|
||||
import java.util.Arrays;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
|
@ -108,10 +106,6 @@ public class DoubleSumObserverTest {
|
|||
.setUnit(UNIT)
|
||||
.setConstantLabels(CONSTANT_LABELS)
|
||||
.build();
|
||||
doubleSumObserver.setCallback(
|
||||
new Callback<DoubleResult>() {
|
||||
@Override
|
||||
public void update(DoubleResult result) {}
|
||||
});
|
||||
doubleSumObserver.setCallback(result -> {});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,8 +19,6 @@ package io.opentelemetry.metrics;
|
|||
import io.opentelemetry.OpenTelemetry;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.internal.StringUtils;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.Callback;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.DoubleResult;
|
||||
import java.util.Arrays;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
|
@ -109,10 +107,6 @@ public class DoubleUpDownSumObserverTest {
|
|||
.setUnit(UNIT)
|
||||
.setConstantLabels(CONSTANT_LABELS)
|
||||
.build();
|
||||
doubleUpDownSumObserver.setCallback(
|
||||
new Callback<DoubleResult>() {
|
||||
@Override
|
||||
public void update(DoubleResult result) {}
|
||||
});
|
||||
doubleUpDownSumObserver.setCallback(result -> {});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,8 +19,6 @@ package io.opentelemetry.metrics;
|
|||
import io.opentelemetry.OpenTelemetry;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.internal.StringUtils;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.Callback;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.DoubleResult;
|
||||
import java.util.Arrays;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
|
@ -108,10 +106,6 @@ public class DoubleValueObserverTest {
|
|||
.setUnit(UNIT)
|
||||
.setConstantLabels(CONSTANT_LABELS)
|
||||
.build();
|
||||
doubleValueObserver.setCallback(
|
||||
new Callback<DoubleResult>() {
|
||||
@Override
|
||||
public void update(DoubleResult result) {}
|
||||
});
|
||||
doubleValueObserver.setCallback(result -> {});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,8 +19,6 @@ package io.opentelemetry.metrics;
|
|||
import io.opentelemetry.OpenTelemetry;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.internal.StringUtils;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.Callback;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.LongResult;
|
||||
import java.util.Arrays;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
|
@ -109,10 +107,6 @@ public class LongSumObserverTest {
|
|||
.setUnit(UNIT)
|
||||
.setConstantLabels(CONSTANT_LABELS)
|
||||
.build();
|
||||
longSumObserver.setCallback(
|
||||
new Callback<LongResult>() {
|
||||
@Override
|
||||
public void update(LongResult result) {}
|
||||
});
|
||||
longSumObserver.setCallback(result -> {});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,8 +19,6 @@ package io.opentelemetry.metrics;
|
|||
import io.opentelemetry.OpenTelemetry;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.internal.StringUtils;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.Callback;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.LongResult;
|
||||
import java.util.Arrays;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
|
@ -110,10 +108,6 @@ public class LongUpDownSumObserverTest {
|
|||
.setUnit(UNIT)
|
||||
.setConstantLabels(CONSTANT_LABELS)
|
||||
.build();
|
||||
longUpDownSumObserver.setCallback(
|
||||
new Callback<LongResult>() {
|
||||
@Override
|
||||
public void update(LongResult result) {}
|
||||
});
|
||||
longUpDownSumObserver.setCallback(result -> {});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,8 +19,6 @@ package io.opentelemetry.metrics;
|
|||
import io.opentelemetry.OpenTelemetry;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.internal.StringUtils;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.Callback;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.LongResult;
|
||||
import java.util.Arrays;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
|
@ -109,10 +107,6 @@ public class LongValueObserverTest {
|
|||
.setUnit(UNIT)
|
||||
.setConstantLabels(CONSTANT_LABELS)
|
||||
.build();
|
||||
longValueObserver.setCallback(
|
||||
new Callback<LongResult>() {
|
||||
@Override
|
||||
public void update(LongResult result) {}
|
||||
});
|
||||
longValueObserver.setCallback(result -> {});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,11 +54,8 @@ public class DefaultTracerTest {
|
|||
@Test
|
||||
public void getCurrentSpan_WithSpan() {
|
||||
assertThat(defaultTracer.getCurrentSpan()).isInstanceOf(DefaultSpan.class);
|
||||
Scope ws = defaultTracer.withSpan(DefaultSpan.createRandom());
|
||||
try {
|
||||
try (Scope ws = defaultTracer.withSpan(DefaultSpan.createRandom())) {
|
||||
assertThat(defaultTracer.getCurrentSpan()).isInstanceOf(DefaultSpan.class);
|
||||
} finally {
|
||||
ws.close();
|
||||
}
|
||||
assertThat(defaultTracer.getCurrentSpan()).isInstanceOf(DefaultSpan.class);
|
||||
}
|
||||
|
|
@ -77,19 +74,14 @@ public class DefaultTracerTest {
|
|||
@Test
|
||||
public void testInProcessContext() {
|
||||
Span span = defaultTracer.spanBuilder(SPAN_NAME).startSpan();
|
||||
Scope scope = defaultTracer.withSpan(span);
|
||||
try {
|
||||
try (Scope scope = defaultTracer.withSpan(span)) {
|
||||
assertThat(defaultTracer.getCurrentSpan()).isEqualTo(span);
|
||||
Span secondSpan = defaultTracer.spanBuilder(SPAN_NAME).startSpan();
|
||||
Scope secondScope = defaultTracer.withSpan(secondSpan);
|
||||
try {
|
||||
try (Scope secondScope = defaultTracer.withSpan(secondSpan)) {
|
||||
assertThat(defaultTracer.getCurrentSpan()).isEqualTo(secondSpan);
|
||||
} finally {
|
||||
secondScope.close();
|
||||
assertThat(defaultTracer.getCurrentSpan()).isEqualTo(span);
|
||||
}
|
||||
} finally {
|
||||
scope.close();
|
||||
}
|
||||
assertThat(defaultTracer.getCurrentSpan()).isInstanceOf(DefaultSpan.class);
|
||||
}
|
||||
|
|
@ -111,12 +103,9 @@ public class DefaultTracerTest {
|
|||
@Test
|
||||
public void testSpanContextPropagationCurrentSpan() {
|
||||
DefaultSpan parent = new DefaultSpan(spanContext);
|
||||
Scope scope = defaultTracer.withSpan(parent);
|
||||
try {
|
||||
try (Scope scope = defaultTracer.withSpan(parent)) {
|
||||
Span span = defaultTracer.spanBuilder(SPAN_NAME).startSpan();
|
||||
assertThat(span.getContext()).isSameInstanceAs(spanContext);
|
||||
} finally {
|
||||
scope.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -124,12 +113,9 @@ public class DefaultTracerTest {
|
|||
public void testSpanContextPropagationCurrentSpanContext() {
|
||||
Context context =
|
||||
TracingContextUtils.withSpan(DefaultSpan.create(spanContext), Context.current());
|
||||
Scope scope = ContextUtils.withScopedContext(context);
|
||||
try {
|
||||
try (Scope scope = ContextUtils.withScopedContext(context)) {
|
||||
Span span = defaultTracer.spanBuilder(SPAN_NAME).startSpan();
|
||||
assertThat(span.getContext()).isSameInstanceAs(spanContext);
|
||||
} finally {
|
||||
scope.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* Copyright 2019, OpenTelemetry Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package io.opentelemetry.trace;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/** Common utilities for tests. */
|
||||
public final class TestUtils {
|
||||
|
||||
TestUtils() {}
|
||||
|
||||
/**
|
||||
* Generates a random {@link TraceId}.
|
||||
*
|
||||
* @param random seed {@code Random}.
|
||||
* @return a {@link TraceId}.
|
||||
*/
|
||||
public static TraceId generateRandomTraceId(Random random) {
|
||||
return TraceId.generateRandomId(random);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a random {@link SpanId}.
|
||||
*
|
||||
* @param random seed {@code Random}.
|
||||
* @return a {@link SpanId}.
|
||||
*/
|
||||
public static SpanId generateRandomSpanId(Random random) {
|
||||
return SpanId.generateRandomId(random);
|
||||
}
|
||||
}
|
||||
|
|
@ -289,6 +289,12 @@ configure(opentelemetryProjects) {
|
|||
animalsnifferTest {
|
||||
enabled = false
|
||||
}
|
||||
// If JMH enabled ignore animalsniffer.
|
||||
plugins.withId("me.champeau.gradle.jmh") {
|
||||
animalsnifferJmh {
|
||||
enabled = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
plugins.withId("me.champeau.gradle.jmh") {
|
||||
|
|
|
|||
|
|
@ -43,22 +43,16 @@ public class ContextUtilsTest {
|
|||
public void withScopedContext() {
|
||||
Context prevCtx = Context.current();
|
||||
Context ctx = Context.current().withValue(SIMPLE_KEY, "value1");
|
||||
Scope scope = ContextUtils.withScopedContext(ctx);
|
||||
try {
|
||||
try (Scope scope = ContextUtils.withScopedContext(ctx)) {
|
||||
assertThat(scope).isNotNull();
|
||||
assertThat(Context.current()).isEqualTo(ctx);
|
||||
|
||||
Context ctx2 = Context.current().withValue(SIMPLE_KEY, "value2");
|
||||
Scope scope2 = ContextUtils.withScopedContext(ctx2);
|
||||
try {
|
||||
try (Scope scope2 = ContextUtils.withScopedContext(ctx2)) {
|
||||
assertThat(scope2).isNotNull();
|
||||
assertThat(Context.current()).isEqualTo(ctx2);
|
||||
} finally {
|
||||
scope2.close();
|
||||
}
|
||||
assertThat(Context.current()).isEqualTo(ctx);
|
||||
} finally {
|
||||
scope.close();
|
||||
}
|
||||
assertThat(Context.current()).isEqualTo(prevCtx);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -313,7 +313,7 @@ public class AdapterTest {
|
|||
.setStartEpochNanos(TimeUnit.MILLISECONDS.toNanos(startMs))
|
||||
.setEndEpochNanos(TimeUnit.MILLISECONDS.toNanos(endMs))
|
||||
.setAttributes(Attributes.of("valueB", valueB))
|
||||
.setEvents(Collections.<Event>singletonList(getTimedEvent()))
|
||||
.setEvents(Collections.singletonList(getTimedEvent()))
|
||||
.setTotalRecordedEvents(1)
|
||||
.setLinks(Collections.singletonList(link))
|
||||
.setTotalRecordedLinks(1)
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ import io.opentelemetry.exporters.jaeger.proto.api_v2.CollectorServiceGrpc;
|
|||
import io.opentelemetry.exporters.jaeger.proto.api_v2.Model;
|
||||
import io.opentelemetry.sdk.extensions.otproto.TraceProtoUtils;
|
||||
import io.opentelemetry.sdk.trace.data.SpanData;
|
||||
import io.opentelemetry.sdk.trace.data.SpanData.Link;
|
||||
import io.opentelemetry.sdk.trace.data.test.TestSpanData;
|
||||
import io.opentelemetry.trace.Span.Kind;
|
||||
import io.opentelemetry.trace.SpanId;
|
||||
|
|
@ -91,7 +90,7 @@ public class JaegerGrpcSpanExporterTest {
|
|||
.setEndEpochNanos(TimeUnit.MILLISECONDS.toNanos(endMs))
|
||||
.setStatus(Status.OK)
|
||||
.setKind(Kind.CONSUMER)
|
||||
.setLinks(Collections.<Link>emptyList())
|
||||
.setLinks(Collections.emptyList())
|
||||
.setTotalRecordedLinks(0)
|
||||
.setTotalRecordedEvents(0)
|
||||
.build();
|
||||
|
|
@ -102,10 +101,7 @@ public class JaegerGrpcSpanExporterTest {
|
|||
exporter.export(Collections.singletonList(span));
|
||||
|
||||
// verify
|
||||
verify(service)
|
||||
.postSpans(
|
||||
requestCaptor.capture(),
|
||||
ArgumentMatchers.<StreamObserver<Collector.PostSpansResponse>>any());
|
||||
verify(service).postSpans(requestCaptor.capture(), ArgumentMatchers.any());
|
||||
|
||||
Model.Batch batch = requestCaptor.getValue().getBatch();
|
||||
assertEquals(1, batch.getSpansCount());
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ import io.opentelemetry.trace.Tracer;
|
|||
import io.restassured.http.ContentType;
|
||||
import io.restassured.response.Response;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.annotation.Nullable;
|
||||
import org.awaitility.Awaitility;
|
||||
|
|
@ -71,7 +70,9 @@ public class JaegerIntegrationTest {
|
|||
Assume.assumeNotNull(jaegerContainer);
|
||||
setupJaegerExporter();
|
||||
imitateWork();
|
||||
Awaitility.await().atMost(30, TimeUnit.SECONDS).until(assertJaegerHaveTrace());
|
||||
Awaitility.await()
|
||||
.atMost(30, TimeUnit.SECONDS)
|
||||
.until(JaegerIntegrationTest::assertJaegerHaveTrace);
|
||||
}
|
||||
|
||||
private static void setupJaegerExporter() {
|
||||
|
|
@ -100,31 +101,26 @@ public class JaegerIntegrationTest {
|
|||
span.end();
|
||||
}
|
||||
|
||||
private static Callable<Boolean> assertJaegerHaveTrace() {
|
||||
return new Callable<Boolean>() {
|
||||
@Override
|
||||
public Boolean call() {
|
||||
try {
|
||||
String url =
|
||||
String.format(
|
||||
"%s/api/traces?service=%s",
|
||||
String.format(JAEGER_URL + ":%d", jaegerContainer.getMappedPort(QUERY_PORT)),
|
||||
SERVICE_NAME);
|
||||
Response response =
|
||||
given()
|
||||
.headers("Content-Type", ContentType.JSON, "Accept", ContentType.JSON)
|
||||
.when()
|
||||
.get(url)
|
||||
.then()
|
||||
.contentType(ContentType.JSON)
|
||||
.extract()
|
||||
.response();
|
||||
Map<String, String> path = response.jsonPath().getMap("data[0]");
|
||||
return path.get("traceID") != null;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
private static boolean assertJaegerHaveTrace() {
|
||||
try {
|
||||
String url =
|
||||
String.format(
|
||||
"%s/api/traces?service=%s",
|
||||
String.format(JAEGER_URL + ":%d", jaegerContainer.getMappedPort(QUERY_PORT)),
|
||||
SERVICE_NAME);
|
||||
Response response =
|
||||
given()
|
||||
.headers("Content-Type", ContentType.JSON, "Accept", ContentType.JSON)
|
||||
.when()
|
||||
.get(url)
|
||||
.then()
|
||||
.contentType(ContentType.JSON)
|
||||
.extract()
|
||||
.response();
|
||||
Map<String, String> path = response.jsonPath().getMap("data[0]");
|
||||
return path.get("traceID") != null;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
|
|||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor.Type;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.DoublePoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.LongPoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Point;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.SummaryPoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.ValueAtPercentile;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
|
|
@ -75,7 +74,7 @@ public class LoggingMetricExporterTest {
|
|||
Labels.of("foo", "bar", "baz", "zoom")),
|
||||
resource,
|
||||
instrumentationLibraryInfo,
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
SummaryPoint.create(
|
||||
nowEpochNanos,
|
||||
nowEpochNanos + 245,
|
||||
|
|
@ -94,7 +93,7 @@ public class LoggingMetricExporterTest {
|
|||
Labels.of("alpha", "aleph", "beta", "bet")),
|
||||
resource,
|
||||
instrumentationLibraryInfo,
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
LongPoint.create(
|
||||
nowEpochNanos, nowEpochNanos + 245, Labels.of("z", "y", "x", "w"), 1010))),
|
||||
MetricData.create(
|
||||
|
|
@ -106,7 +105,7 @@ public class LoggingMetricExporterTest {
|
|||
Labels.of("uno", "eins", "dos", "zwei")),
|
||||
resource,
|
||||
instrumentationLibraryInfo,
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
DoublePoint.create(
|
||||
nowEpochNanos,
|
||||
nowEpochNanos + 245,
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import io.opentelemetry.common.AttributeValue;
|
|||
import io.opentelemetry.common.Attributes;
|
||||
import io.opentelemetry.sdk.trace.data.EventImpl;
|
||||
import io.opentelemetry.sdk.trace.data.SpanData;
|
||||
import io.opentelemetry.sdk.trace.data.SpanData.Event;
|
||||
import io.opentelemetry.sdk.trace.data.test.TestSpanData;
|
||||
import io.opentelemetry.sdk.trace.export.SpanExporter.ResultCode;
|
||||
import io.opentelemetry.trace.Span.Kind;
|
||||
|
|
@ -70,7 +69,7 @@ public class LoggingSpanExporterTest {
|
|||
.setName("testSpan")
|
||||
.setKind(Kind.INTERNAL)
|
||||
.setEvents(
|
||||
Collections.<Event>singletonList(
|
||||
Collections.singletonList(
|
||||
EventImpl.create(
|
||||
epochNanos + 500,
|
||||
"somethingHappenedHere",
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ import io.opentelemetry.proto.metrics.v1.SummaryDataPoint.ValueAtPercentile;
|
|||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Point;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.util.Collections;
|
||||
import org.junit.Test;
|
||||
|
|
@ -75,10 +74,7 @@ public class MetricAdapterTest {
|
|||
|
||||
@Test
|
||||
public void toProtoValueAtPercentiles() {
|
||||
assertThat(
|
||||
MetricAdapter.toProtoValueAtPercentiles(
|
||||
Collections.<MetricData.ValueAtPercentile>emptyList()))
|
||||
.isEmpty();
|
||||
assertThat(MetricAdapter.toProtoValueAtPercentiles(Collections.emptyList())).isEmpty();
|
||||
assertThat(
|
||||
MetricAdapter.toProtoValueAtPercentiles(
|
||||
Collections.singletonList(MetricData.ValueAtPercentile.create(0.9, 1.1))))
|
||||
|
|
@ -95,11 +91,10 @@ public class MetricAdapterTest {
|
|||
|
||||
@Test
|
||||
public void toInt64DataPoints() {
|
||||
assertThat(MetricAdapter.toInt64DataPoints(Collections.<MetricData.Point>emptyList()))
|
||||
.isEmpty();
|
||||
assertThat(MetricAdapter.toInt64DataPoints(Collections.emptyList())).isEmpty();
|
||||
assertThat(
|
||||
MetricAdapter.toInt64DataPoints(
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
MetricData.LongPoint.create(123, 456, Labels.of("k", "v"), 5))))
|
||||
.containsExactly(
|
||||
Int64DataPoint.newBuilder()
|
||||
|
|
@ -112,7 +107,7 @@ public class MetricAdapterTest {
|
|||
.build());
|
||||
assertThat(
|
||||
MetricAdapter.toInt64DataPoints(
|
||||
ImmutableList.<Point>of(
|
||||
ImmutableList.of(
|
||||
MetricData.LongPoint.create(123, 456, Labels.empty(), 5),
|
||||
MetricData.LongPoint.create(321, 654, Labels.of("k", "v"), 7))))
|
||||
.containsExactly(
|
||||
|
|
@ -133,11 +128,10 @@ public class MetricAdapterTest {
|
|||
|
||||
@Test
|
||||
public void toDoubleDataPoints() {
|
||||
assertThat(MetricAdapter.toDoubleDataPoints(Collections.<MetricData.Point>emptyList()))
|
||||
.isEmpty();
|
||||
assertThat(MetricAdapter.toDoubleDataPoints(Collections.emptyList())).isEmpty();
|
||||
assertThat(
|
||||
MetricAdapter.toDoubleDataPoints(
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
MetricData.DoublePoint.create(123, 456, Labels.of("k", "v"), 5.1))))
|
||||
.containsExactly(
|
||||
DoubleDataPoint.newBuilder()
|
||||
|
|
@ -150,7 +144,7 @@ public class MetricAdapterTest {
|
|||
.build());
|
||||
assertThat(
|
||||
MetricAdapter.toDoubleDataPoints(
|
||||
ImmutableList.<Point>of(
|
||||
ImmutableList.of(
|
||||
MetricData.DoublePoint.create(123, 456, Labels.empty(), 5.1),
|
||||
MetricData.DoublePoint.create(321, 654, Labels.of("k", "v"), 7.1))))
|
||||
.containsExactly(
|
||||
|
|
@ -171,11 +165,10 @@ public class MetricAdapterTest {
|
|||
|
||||
@Test
|
||||
public void toSummaryDataPoints() {
|
||||
assertThat(MetricAdapter.toSummaryDataPoints(Collections.<MetricData.Point>emptyList()))
|
||||
.isEmpty();
|
||||
assertThat(MetricAdapter.toSummaryDataPoints(Collections.emptyList())).isEmpty();
|
||||
assertThat(
|
||||
MetricAdapter.toSummaryDataPoints(
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
MetricData.SummaryPoint.create(
|
||||
123,
|
||||
456,
|
||||
|
|
@ -198,14 +191,9 @@ public class MetricAdapterTest {
|
|||
.build());
|
||||
assertThat(
|
||||
MetricAdapter.toSummaryDataPoints(
|
||||
ImmutableList.<Point>of(
|
||||
ImmutableList.of(
|
||||
MetricData.SummaryPoint.create(
|
||||
123,
|
||||
456,
|
||||
Labels.empty(),
|
||||
7,
|
||||
15.3,
|
||||
Collections.<MetricData.ValueAtPercentile>emptyList()),
|
||||
123, 456, Labels.empty(), 7, 15.3, Collections.emptyList()),
|
||||
MetricData.SummaryPoint.create(
|
||||
321,
|
||||
654,
|
||||
|
|
@ -283,7 +271,7 @@ public class MetricAdapterTest {
|
|||
Labels.of("k", "v")),
|
||||
Resource.getEmpty(),
|
||||
InstrumentationLibraryInfo.getEmpty(),
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
MetricData.LongPoint.create(123, 456, Labels.of("k", "v"), 5)))))
|
||||
.isEqualTo(
|
||||
Metric.newBuilder()
|
||||
|
|
@ -319,7 +307,7 @@ public class MetricAdapterTest {
|
|||
Labels.of("k", "v")),
|
||||
Resource.getEmpty(),
|
||||
InstrumentationLibraryInfo.getEmpty(),
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
MetricData.DoublePoint.create(123, 456, Labels.of("k", "v"), 5.1)))))
|
||||
.isEqualTo(
|
||||
Metric.newBuilder()
|
||||
|
|
@ -389,25 +377,19 @@ public class MetricAdapterTest {
|
|||
MetricAdapter.toProtoResourceMetrics(
|
||||
ImmutableList.of(
|
||||
MetricData.create(
|
||||
descriptor,
|
||||
resource,
|
||||
instrumentationLibraryInfo,
|
||||
Collections.<Point>emptyList()),
|
||||
descriptor, resource, instrumentationLibraryInfo, Collections.emptyList()),
|
||||
MetricData.create(
|
||||
descriptor,
|
||||
resource,
|
||||
instrumentationLibraryInfo,
|
||||
Collections.<Point>emptyList()),
|
||||
descriptor, resource, instrumentationLibraryInfo, Collections.emptyList()),
|
||||
MetricData.create(
|
||||
descriptor,
|
||||
Resource.getEmpty(),
|
||||
instrumentationLibraryInfo,
|
||||
Collections.<Point>emptyList()),
|
||||
Collections.emptyList()),
|
||||
MetricData.create(
|
||||
descriptor,
|
||||
Resource.getEmpty(),
|
||||
InstrumentationLibraryInfo.getEmpty(),
|
||||
Collections.<Point>emptyList()))))
|
||||
Collections.emptyList()))))
|
||||
.containsExactly(
|
||||
ResourceMetrics.newBuilder()
|
||||
.setResource(resourceProto)
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ import io.opentelemetry.sdk.metrics.data.MetricData;
|
|||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor.Type;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.LongPoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Point;
|
||||
import io.opentelemetry.sdk.metrics.export.MetricExporter.ResultCode;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.io.IOException;
|
||||
|
|
@ -237,7 +236,7 @@ public class OtlpGrpcMetricExporterTest {
|
|||
Descriptor.create("name", "description", "1", Type.MONOTONIC_LONG, Labels.empty()),
|
||||
Resource.getEmpty(),
|
||||
InstrumentationLibraryInfo.getEmpty(),
|
||||
Collections.<Point>singletonList(LongPoint.create(startNs, endNs, Labels.of("k", "v"), 5)));
|
||||
Collections.singletonList(LongPoint.create(startNs, endNs, Labels.of("k", "v"), 5)));
|
||||
}
|
||||
|
||||
private static final class FakeCollector extends MetricsServiceGrpc.MetricsServiceImplBase {
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ import io.opentelemetry.proto.collector.trace.v1.ExportTraceServiceResponse;
|
|||
import io.opentelemetry.proto.collector.trace.v1.TraceServiceGrpc;
|
||||
import io.opentelemetry.proto.trace.v1.ResourceSpans;
|
||||
import io.opentelemetry.sdk.trace.data.SpanData;
|
||||
import io.opentelemetry.sdk.trace.data.SpanData.Link;
|
||||
import io.opentelemetry.sdk.trace.data.test.TestSpanData;
|
||||
import io.opentelemetry.sdk.trace.export.SpanExporter.ResultCode;
|
||||
import io.opentelemetry.trace.Span.Kind;
|
||||
|
|
@ -229,7 +228,7 @@ public class OtlpGrpcSpanExporterTest {
|
|||
.setEndEpochNanos(endNs)
|
||||
.setStatus(Status.OK)
|
||||
.setKind(Kind.SERVER)
|
||||
.setLinks(Collections.<Link>emptyList())
|
||||
.setLinks(Collections.emptyList())
|
||||
.setTotalRecordedLinks(0)
|
||||
.setTotalRecordedEvents(0)
|
||||
.build();
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ import io.opentelemetry.proto.trace.v1.Span.SpanKind;
|
|||
import io.opentelemetry.proto.trace.v1.Status;
|
||||
import io.opentelemetry.proto.trace.v1.Status.StatusCode;
|
||||
import io.opentelemetry.sdk.trace.data.EventImpl;
|
||||
import io.opentelemetry.sdk.trace.data.SpanData.Event;
|
||||
import io.opentelemetry.sdk.trace.data.SpanData.Link;
|
||||
import io.opentelemetry.sdk.trace.data.test.TestSpanData;
|
||||
import io.opentelemetry.trace.Span.Kind;
|
||||
|
|
@ -71,7 +70,7 @@ public class SpanAdapterTest {
|
|||
.setAttributes(Attributes.of("key", AttributeValue.booleanAttributeValue(true)))
|
||||
.setTotalAttributeCount(2)
|
||||
.setEvents(
|
||||
Collections.<Event>singletonList(
|
||||
Collections.singletonList(
|
||||
EventImpl.create(12347, "my_event", Attributes.empty())))
|
||||
.setTotalRecordedEvents(3)
|
||||
.setLinks(Collections.singletonList(Link.create(SPAN_CONTEXT)))
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import io.opentelemetry.common.Labels;
|
|||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Point;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import io.prometheus.client.Collector.MetricFamilySamples;
|
||||
import io.prometheus.client.Collector.MetricFamilySamples.Sample;
|
||||
|
|
@ -59,7 +58,7 @@ public class MetricAdapterTest {
|
|||
"full_name",
|
||||
Descriptor.create(
|
||||
"name", "description", "1", Descriptor.Type.MONOTONIC_LONG, Labels.empty()),
|
||||
Collections.<MetricData.Point>emptyList()))
|
||||
Collections.emptyList()))
|
||||
.isEmpty();
|
||||
|
||||
assertThat(
|
||||
|
|
@ -67,7 +66,7 @@ public class MetricAdapterTest {
|
|||
"full_name",
|
||||
Descriptor.create(
|
||||
"name", "description", "1", Descriptor.Type.NON_MONOTONIC_LONG, Labels.empty()),
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
MetricData.LongPoint.create(123, 456, Labels.of("kp", "vp"), 5))))
|
||||
.containsExactly(
|
||||
new Sample("full_name", ImmutableList.of("kp"), ImmutableList.of("vp"), 5));
|
||||
|
|
@ -81,7 +80,7 @@ public class MetricAdapterTest {
|
|||
"1",
|
||||
Descriptor.Type.NON_MONOTONIC_LONG,
|
||||
Labels.of("kc", "vc")),
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
MetricData.LongPoint.create(123, 456, Labels.of("kp", "vp"), 5))))
|
||||
.containsExactly(
|
||||
new Sample("full_name", ImmutableList.of("kc", "kp"), ImmutableList.of("vc", "vp"), 5));
|
||||
|
|
@ -95,7 +94,7 @@ public class MetricAdapterTest {
|
|||
"1",
|
||||
Descriptor.Type.MONOTONIC_LONG,
|
||||
Labels.of("kc", "vc")),
|
||||
ImmutableList.<Point>of(
|
||||
ImmutableList.of(
|
||||
MetricData.LongPoint.create(123, 456, Labels.empty(), 5),
|
||||
MetricData.LongPoint.create(321, 654, Labels.of("kp", "vp"), 7))))
|
||||
.containsExactly(
|
||||
|
|
@ -114,7 +113,7 @@ public class MetricAdapterTest {
|
|||
"1",
|
||||
Descriptor.Type.NON_MONOTONIC_DOUBLE,
|
||||
Labels.empty()),
|
||||
Collections.<MetricData.Point>emptyList()))
|
||||
Collections.emptyList()))
|
||||
.isEmpty();
|
||||
|
||||
assertThat(
|
||||
|
|
@ -122,7 +121,7 @@ public class MetricAdapterTest {
|
|||
"full_name",
|
||||
Descriptor.create(
|
||||
"name", "description", "1", Descriptor.Type.MONOTONIC_DOUBLE, Labels.empty()),
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
MetricData.DoublePoint.create(123, 456, Labels.of("kp", "vp"), 5))))
|
||||
.containsExactly(
|
||||
new Sample("full_name", ImmutableList.of("kp"), ImmutableList.of("vp"), 5));
|
||||
|
|
@ -136,7 +135,7 @@ public class MetricAdapterTest {
|
|||
"1",
|
||||
Descriptor.Type.NON_MONOTONIC_DOUBLE,
|
||||
Labels.of("kc", "vc")),
|
||||
ImmutableList.<Point>of(
|
||||
ImmutableList.of(
|
||||
MetricData.DoublePoint.create(123, 456, Labels.empty(), 5),
|
||||
MetricData.DoublePoint.create(321, 654, Labels.of("kp", "vp"), 7))))
|
||||
.containsExactly(
|
||||
|
|
@ -151,7 +150,7 @@ public class MetricAdapterTest {
|
|||
"full_name",
|
||||
Descriptor.create(
|
||||
"name", "description", "1", Descriptor.Type.SUMMARY, Labels.empty()),
|
||||
Collections.<MetricData.Point>emptyList()))
|
||||
Collections.emptyList()))
|
||||
.isEmpty();
|
||||
|
||||
assertThat(
|
||||
|
|
@ -159,7 +158,7 @@ public class MetricAdapterTest {
|
|||
"full_name",
|
||||
Descriptor.create(
|
||||
"name", "description", "1", Descriptor.Type.SUMMARY, Labels.empty()),
|
||||
ImmutableList.<Point>of(
|
||||
ImmutableList.of(
|
||||
MetricData.SummaryPoint.create(
|
||||
321,
|
||||
654,
|
||||
|
|
@ -181,14 +180,9 @@ public class MetricAdapterTest {
|
|||
"full_name",
|
||||
Descriptor.create(
|
||||
"name", "description", "1", Descriptor.Type.SUMMARY, Labels.of("kc", "vc")),
|
||||
ImmutableList.<Point>of(
|
||||
ImmutableList.of(
|
||||
MetricData.SummaryPoint.create(
|
||||
123,
|
||||
456,
|
||||
Labels.empty(),
|
||||
7,
|
||||
15.3,
|
||||
Collections.<MetricData.ValueAtPercentile>emptyList()),
|
||||
123, 456, Labels.empty(), 7, 15.3, Collections.emptyList()),
|
||||
MetricData.SummaryPoint.create(
|
||||
321,
|
||||
654,
|
||||
|
|
@ -228,7 +222,7 @@ public class MetricAdapterTest {
|
|||
descriptor,
|
||||
Resource.create(Attributes.of("kr", AttributeValue.stringAttributeValue("vr"))),
|
||||
InstrumentationLibraryInfo.create("full", "version"),
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
MetricData.DoublePoint.create(123, 456, Labels.of("kp", "vp"), 5)));
|
||||
|
||||
assertThat(MetricAdapter.toMetricFamilySamples(metricData))
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ import io.opentelemetry.common.Labels;
|
|||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Point;
|
||||
import io.opentelemetry.sdk.metrics.export.MetricProducer;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import io.prometheus.client.CollectorRegistry;
|
||||
|
|
@ -80,7 +79,7 @@ public class PrometheusCollectorTest {
|
|||
Labels.of("kc", "vc")),
|
||||
Resource.create(Attributes.of("kr", AttributeValue.stringAttributeValue("vr"))),
|
||||
InstrumentationLibraryInfo.create("grpc", "version"),
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
MetricData.LongPoint.create(123, 456, Labels.of("kp", "vp"), 5))),
|
||||
MetricData.create(
|
||||
Descriptor.create(
|
||||
|
|
@ -91,7 +90,7 @@ public class PrometheusCollectorTest {
|
|||
Labels.of("kc", "vc")),
|
||||
Resource.create(Attributes.of("kr", AttributeValue.stringAttributeValue("vr"))),
|
||||
InstrumentationLibraryInfo.create("http", "version"),
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
MetricData.DoublePoint.create(123, 456, Labels.of("kp", "vp"), 3.5))));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ import io.opentelemetry.common.Attributes;
|
|||
import io.opentelemetry.sdk.trace.data.EventImpl;
|
||||
import io.opentelemetry.sdk.trace.data.SpanData;
|
||||
import io.opentelemetry.sdk.trace.data.SpanData.Event;
|
||||
import io.opentelemetry.sdk.trace.data.SpanData.Link;
|
||||
import io.opentelemetry.sdk.trace.data.test.TestSpanData;
|
||||
import io.opentelemetry.sdk.trace.export.SpanExporter;
|
||||
import io.opentelemetry.trace.Span.Kind;
|
||||
|
|
@ -61,7 +60,7 @@ public class ZipkinSpanExporterEndToEndHttpTest {
|
|||
private static final long SENT_TIMESTAMP_NANOS = 1505855799_459486280L;
|
||||
private static final Attributes attributes = Attributes.empty();
|
||||
private static final List<Event> annotations =
|
||||
ImmutableList.<Event>of(
|
||||
ImmutableList.of(
|
||||
EventImpl.create(RECEIVED_TIMESTAMP_NANOS, "RECEIVED", Attributes.empty()),
|
||||
EventImpl.create(SENT_TIMESTAMP_NANOS, "SENT", Attributes.empty()));
|
||||
|
||||
|
|
@ -167,7 +166,7 @@ public class ZipkinSpanExporterEndToEndHttpTest {
|
|||
.setAttributes(attributes)
|
||||
.setTotalAttributeCount(attributes.size())
|
||||
.setEvents(annotations)
|
||||
.setLinks(Collections.<Link>emptyList())
|
||||
.setLinks(Collections.emptyList())
|
||||
.setEndEpochNanos(END_EPOCH_NANOS)
|
||||
.setHasEnded(true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,6 @@ import io.opentelemetry.sdk.resources.ResourceConstants;
|
|||
import io.opentelemetry.sdk.trace.data.EventImpl;
|
||||
import io.opentelemetry.sdk.trace.data.SpanData;
|
||||
import io.opentelemetry.sdk.trace.data.SpanData.Event;
|
||||
import io.opentelemetry.sdk.trace.data.SpanData.Link;
|
||||
import io.opentelemetry.sdk.trace.data.test.TestSpanData;
|
||||
import io.opentelemetry.sdk.trace.export.SpanExporter.ResultCode;
|
||||
import io.opentelemetry.trace.Span.Kind;
|
||||
|
|
@ -70,7 +69,7 @@ public class ZipkinSpanExporterTest {
|
|||
private static final String PARENT_SPAN_ID = "8b03ab423da481c5";
|
||||
private static final Attributes attributes = Attributes.empty();
|
||||
private static final List<Event> annotations =
|
||||
ImmutableList.<Event>of(
|
||||
ImmutableList.of(
|
||||
EventImpl.create(1505855799_433901068L, "RECEIVED", Attributes.empty()),
|
||||
EventImpl.create(1505855799_459486280L, "SENT", Attributes.empty()));
|
||||
|
||||
|
|
@ -228,7 +227,7 @@ public class ZipkinSpanExporterTest {
|
|||
when(mockEncoder.encode(buildZipkinSpan(Span.Kind.SERVER))).thenReturn(someBytes);
|
||||
when(mockSender.sendSpans(Collections.singletonList(someBytes))).thenReturn(mockZipkinCall);
|
||||
ResultCode resultCode =
|
||||
zipkinSpanExporter.export(Collections.<SpanData>singleton(buildStandardSpan().build()));
|
||||
zipkinSpanExporter.export(Collections.singleton(buildStandardSpan().build()));
|
||||
|
||||
verify(mockZipkinCall).execute();
|
||||
assertThat(resultCode).isEqualTo(ResultCode.SUCCESS);
|
||||
|
|
@ -245,7 +244,7 @@ public class ZipkinSpanExporterTest {
|
|||
when(mockZipkinCall.execute()).thenThrow(new IOException());
|
||||
|
||||
ResultCode resultCode =
|
||||
zipkinSpanExporter.export(Collections.<SpanData>singleton(buildStandardSpan().build()));
|
||||
zipkinSpanExporter.export(Collections.singleton(buildStandardSpan().build()));
|
||||
|
||||
assertThat(resultCode).isEqualTo(ResultCode.FAILURE);
|
||||
}
|
||||
|
|
@ -287,7 +286,7 @@ public class ZipkinSpanExporterTest {
|
|||
.setAttributes(attributes)
|
||||
.setTotalAttributeCount(attributes.size())
|
||||
.setEvents(annotations)
|
||||
.setLinks(Collections.<Link>emptyList())
|
||||
.setLinks(Collections.emptyList())
|
||||
.setEndEpochNanos(1505855799_465726528L)
|
||||
.setHasEnded(true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,13 +47,7 @@ public class AwsXRayPropagatorTest {
|
|||
private static final TraceFlags SAMPLED_TRACE_FLAG =
|
||||
TraceFlags.builder().setIsSampled(true).build();
|
||||
|
||||
private static final HttpTextFormat.Setter<Map<String, String>> setter =
|
||||
new HttpTextFormat.Setter<Map<String, String>>() {
|
||||
@Override
|
||||
public void set(Map<String, String> carrier, String key, String value) {
|
||||
carrier.put(key, value);
|
||||
}
|
||||
};
|
||||
private static final HttpTextFormat.Setter<Map<String, String>> setter = Map::put;
|
||||
private static final HttpTextFormat.Getter<Map<String, String>> getter =
|
||||
new HttpTextFormat.Getter<Map<String, String>>() {
|
||||
@Nullable
|
||||
|
|
|
|||
|
|
@ -54,13 +54,7 @@ public class B3PropagatorTest {
|
|||
private static final byte SAMPLED_TRACE_OPTIONS_BYTES = 1;
|
||||
private static final TraceFlags SAMPLED_TRACE_OPTIONS =
|
||||
TraceFlags.fromByte(SAMPLED_TRACE_OPTIONS_BYTES);
|
||||
private static final Setter<Map<String, String>> setter =
|
||||
new Setter<Map<String, String>>() {
|
||||
@Override
|
||||
public void set(Map<String, String> carrier, String key, String value) {
|
||||
carrier.put(key, value);
|
||||
}
|
||||
};
|
||||
private static final Setter<Map<String, String>> setter = Map::put;
|
||||
private static final Getter<Map<String, String>> getter =
|
||||
new Getter<Map<String, String>>() {
|
||||
@Nullable
|
||||
|
|
@ -119,12 +113,7 @@ public class B3PropagatorTest {
|
|||
SpanContext.create(TRACE_ID, SPAN_ID, SAMPLED_TRACE_OPTIONS, TRACE_STATE_DEFAULT),
|
||||
Context.current()),
|
||||
null,
|
||||
new Setter<Map<String, String>>() {
|
||||
@Override
|
||||
public void set(Map<String, String> ignored, String key, String value) {
|
||||
carrier.put(key, value);
|
||||
}
|
||||
});
|
||||
(Setter<Map<String, String>>) (ignored, key, value) -> carrier.put(key, value));
|
||||
assertThat(carrier).containsEntry(B3Propagator.TRACE_ID_HEADER, TRACE_ID_BASE16);
|
||||
assertThat(carrier).containsEntry(B3Propagator.SPAN_ID_HEADER, SPAN_ID_BASE16);
|
||||
assertThat(carrier).containsEntry(B3Propagator.SAMPLED_HEADER, "1");
|
||||
|
|
|
|||
|
|
@ -63,13 +63,7 @@ public class JaegerPropagatorTest {
|
|||
private static final byte SAMPLED_TRACE_OPTIONS_BYTES = 1;
|
||||
private static final TraceFlags SAMPLED_TRACE_OPTIONS =
|
||||
TraceFlags.fromByte(SAMPLED_TRACE_OPTIONS_BYTES);
|
||||
private static final HttpTextFormat.Setter<Map<String, String>> setter =
|
||||
new HttpTextFormat.Setter<Map<String, String>>() {
|
||||
@Override
|
||||
public void set(Map<String, String> carrier, String key, String value) {
|
||||
carrier.put(key, value);
|
||||
}
|
||||
};
|
||||
private static final HttpTextFormat.Setter<Map<String, String>> setter = Map::put;
|
||||
private static final HttpTextFormat.Getter<Map<String, String>> getter =
|
||||
new HttpTextFormat.Getter<Map<String, String>>() {
|
||||
@Nullable
|
||||
|
|
@ -133,12 +127,7 @@ public class JaegerPropagatorTest {
|
|||
SpanContext.create(TRACE_ID, SPAN_ID, SAMPLED_TRACE_OPTIONS, TRACE_STATE_DEFAULT),
|
||||
Context.current()),
|
||||
null,
|
||||
new Setter<Map<String, String>>() {
|
||||
@Override
|
||||
public void set(Map<String, String> ignored, String key, String value) {
|
||||
carrier.put(key, value);
|
||||
}
|
||||
});
|
||||
(Setter<Map<String, String>>) (ignored, key, value) -> carrier.put(key, value));
|
||||
|
||||
assertThat(carrier)
|
||||
.containsEntry(
|
||||
|
|
|
|||
|
|
@ -70,12 +70,9 @@ public class CurrentSpanUtilsTest {
|
|||
public void withSpanRunnable() {
|
||||
assertThat(getCurrentSpan()).isInstanceOf(DefaultSpan.class);
|
||||
Runnable runnable =
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// When we run the runnable we will have the span in the current Context.
|
||||
assertThat(getCurrentSpan()).isSameInstanceAs(span);
|
||||
}
|
||||
() -> {
|
||||
// When we run the runnable we will have the span in the current Context.
|
||||
assertThat(getCurrentSpan()).isSameInstanceAs(span);
|
||||
};
|
||||
CurrentSpanUtils.withSpan(span, false, runnable).run();
|
||||
verifyNoInteractions(span);
|
||||
|
|
@ -86,12 +83,9 @@ public class CurrentSpanUtilsTest {
|
|||
public void withSpanRunnable_EndSpan() {
|
||||
assertThat(getCurrentSpan()).isInstanceOf(DefaultSpan.class);
|
||||
Runnable runnable =
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// When we run the runnable we will have the span in the current Context.
|
||||
assertThat(getCurrentSpan()).isSameInstanceAs(span);
|
||||
}
|
||||
() -> {
|
||||
// When we run the runnable we will have the span in the current Context.
|
||||
assertThat(getCurrentSpan()).isSameInstanceAs(span);
|
||||
};
|
||||
CurrentSpanUtils.withSpan(span, true, runnable).run();
|
||||
verify(span).end();
|
||||
|
|
@ -103,13 +97,10 @@ public class CurrentSpanUtilsTest {
|
|||
final AssertionError error = new AssertionError("MyError");
|
||||
assertThat(getCurrentSpan()).isInstanceOf(DefaultSpan.class);
|
||||
Runnable runnable =
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// When we run the runnable we will have the span in the current Context.
|
||||
assertThat(getCurrentSpan()).isSameInstanceAs(span);
|
||||
throw error;
|
||||
}
|
||||
() -> {
|
||||
// When we run the runnable we will have the span in the current Context.
|
||||
assertThat(getCurrentSpan()).isSameInstanceAs(span);
|
||||
throw error;
|
||||
};
|
||||
executeRunnableAndExpectError(runnable, error);
|
||||
verify(span).setStatus(Status.UNKNOWN.withDescription("MyError"));
|
||||
|
|
@ -122,13 +113,10 @@ public class CurrentSpanUtilsTest {
|
|||
final AssertionError error = new AssertionError();
|
||||
assertThat(getCurrentSpan()).isInstanceOf(DefaultSpan.class);
|
||||
Runnable runnable =
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// When we run the runnable we will have the span in the current Context.
|
||||
assertThat(getCurrentSpan()).isSameInstanceAs(span);
|
||||
throw error;
|
||||
}
|
||||
() -> {
|
||||
// When we run the runnable we will have the span in the current Context.
|
||||
assertThat(getCurrentSpan()).isSameInstanceAs(span);
|
||||
throw error;
|
||||
};
|
||||
executeRunnableAndExpectError(runnable, error);
|
||||
verify(span).setStatus(Status.UNKNOWN.withDescription("AssertionError"));
|
||||
|
|
@ -141,13 +129,10 @@ public class CurrentSpanUtilsTest {
|
|||
final Object ret = new Object();
|
||||
assertThat(getCurrentSpan()).isInstanceOf(DefaultSpan.class);
|
||||
Callable<Object> callable =
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() {
|
||||
// When we run the runnable we will have the span in the current Context.
|
||||
assertThat(getCurrentSpan()).isSameInstanceAs(span);
|
||||
return ret;
|
||||
}
|
||||
() -> {
|
||||
// When we run the runnable we will have the span in the current Context.
|
||||
assertThat(getCurrentSpan()).isSameInstanceAs(span);
|
||||
return ret;
|
||||
};
|
||||
assertThat(CurrentSpanUtils.withSpan(span, false, callable).call()).isEqualTo(ret);
|
||||
verifyNoInteractions(span);
|
||||
|
|
@ -159,13 +144,10 @@ public class CurrentSpanUtilsTest {
|
|||
final Object ret = new Object();
|
||||
assertThat(getCurrentSpan()).isInstanceOf(DefaultSpan.class);
|
||||
Callable<Object> callable =
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() {
|
||||
// When we run the runnable we will have the span in the current Context.
|
||||
assertThat(getCurrentSpan()).isSameInstanceAs(span);
|
||||
return ret;
|
||||
}
|
||||
() -> {
|
||||
// When we run the runnable we will have the span in the current Context.
|
||||
assertThat(getCurrentSpan()).isSameInstanceAs(span);
|
||||
return ret;
|
||||
};
|
||||
assertThat(CurrentSpanUtils.withSpan(span, true, callable).call()).isEqualTo(ret);
|
||||
verify(span).end();
|
||||
|
|
@ -177,13 +159,10 @@ public class CurrentSpanUtilsTest {
|
|||
final Exception exception = new Exception("MyException");
|
||||
assertThat(getCurrentSpan()).isInstanceOf(DefaultSpan.class);
|
||||
Callable<Object> callable =
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
// When we run the runnable we will have the span in the current Context.
|
||||
assertThat(getCurrentSpan()).isSameInstanceAs(span);
|
||||
throw exception;
|
||||
}
|
||||
() -> {
|
||||
// When we run the runnable we will have the span in the current Context.
|
||||
assertThat(getCurrentSpan()).isSameInstanceAs(span);
|
||||
throw exception;
|
||||
};
|
||||
executeCallableAndExpectError(callable, exception);
|
||||
verify(span).setStatus(Status.UNKNOWN.withDescription("MyException"));
|
||||
|
|
@ -196,13 +175,10 @@ public class CurrentSpanUtilsTest {
|
|||
final Exception exception = new Exception();
|
||||
assertThat(getCurrentSpan()).isInstanceOf(DefaultSpan.class);
|
||||
Callable<Object> callable =
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
// When we run the runnable we will have the span in the current Context.
|
||||
assertThat(getCurrentSpan()).isSameInstanceAs(span);
|
||||
throw exception;
|
||||
}
|
||||
() -> {
|
||||
// When we run the runnable we will have the span in the current Context.
|
||||
assertThat(getCurrentSpan()).isSameInstanceAs(span);
|
||||
throw exception;
|
||||
};
|
||||
executeCallableAndExpectError(callable, exception);
|
||||
verify(span).setStatus(Status.UNKNOWN.withDescription("Exception"));
|
||||
|
|
@ -215,13 +191,10 @@ public class CurrentSpanUtilsTest {
|
|||
final AssertionError error = new AssertionError("MyError");
|
||||
assertThat(getCurrentSpan()).isInstanceOf(DefaultSpan.class);
|
||||
Callable<Object> callable =
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() {
|
||||
// When we run the runnable we will have the span in the current Context.
|
||||
assertThat(getCurrentSpan()).isSameInstanceAs(span);
|
||||
throw error;
|
||||
}
|
||||
() -> {
|
||||
// When we run the runnable we will have the span in the current Context.
|
||||
assertThat(getCurrentSpan()).isSameInstanceAs(span);
|
||||
throw error;
|
||||
};
|
||||
executeCallableAndExpectError(callable, error);
|
||||
verify(span).setStatus(Status.UNKNOWN.withDescription("MyError"));
|
||||
|
|
@ -234,13 +207,10 @@ public class CurrentSpanUtilsTest {
|
|||
final AssertionError error = new AssertionError();
|
||||
assertThat(getCurrentSpan()).isInstanceOf(DefaultSpan.class);
|
||||
Callable<Object> callable =
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() {
|
||||
// When we run the runnable we will have the span in the current Context.
|
||||
assertThat(getCurrentSpan()).isSameInstanceAs(span);
|
||||
throw error;
|
||||
}
|
||||
() -> {
|
||||
// When we run the runnable we will have the span in the current Context.
|
||||
assertThat(getCurrentSpan()).isSameInstanceAs(span);
|
||||
throw error;
|
||||
};
|
||||
executeCallableAndExpectError(callable, error);
|
||||
verify(span).setStatus(Status.UNKNOWN.withDescription("AssertionError"));
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import static io.restassured.RestAssured.given;
|
|||
import io.restassured.http.ContentType;
|
||||
import io.restassured.response.Response;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.awaitility.Awaitility;
|
||||
import org.junit.ClassRule;
|
||||
|
|
@ -86,34 +85,31 @@ public class JavaSevenCompatibilityIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void testJaegerExampleAppIntegration() {
|
||||
Awaitility.await().atMost(30, TimeUnit.SECONDS).until(assertJaegerHaveTrace());
|
||||
Awaitility.await()
|
||||
.atMost(30, TimeUnit.SECONDS)
|
||||
.until(JavaSevenCompatibilityIntegrationTest::assertJaegerHaveTrace);
|
||||
}
|
||||
|
||||
private static Callable<Boolean> assertJaegerHaveTrace() {
|
||||
return new Callable<Boolean>() {
|
||||
@Override
|
||||
public Boolean call() {
|
||||
try {
|
||||
String url =
|
||||
String.format(
|
||||
"%s/api/traces?service=%s",
|
||||
String.format(JAEGER_URL + ":%d", jaegerContainer.getMappedPort(QUERY_PORT)),
|
||||
SERVICE_NAME);
|
||||
Response response =
|
||||
given()
|
||||
.headers("Content-Type", ContentType.JSON, "Accept", ContentType.JSON)
|
||||
.when()
|
||||
.get(url)
|
||||
.then()
|
||||
.contentType(ContentType.JSON)
|
||||
.extract()
|
||||
.response();
|
||||
Map<String, String> path = response.jsonPath().getMap("data[0]");
|
||||
return path.get("traceID") != null;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
private static Boolean assertJaegerHaveTrace() {
|
||||
try {
|
||||
String url =
|
||||
String.format(
|
||||
"%s/api/traces?service=%s",
|
||||
String.format(JAEGER_URL + ":%d", jaegerContainer.getMappedPort(QUERY_PORT)),
|
||||
SERVICE_NAME);
|
||||
Response response =
|
||||
given()
|
||||
.headers("Content-Type", ContentType.JSON, "Accept", ContentType.JSON)
|
||||
.when()
|
||||
.get(url)
|
||||
.then()
|
||||
.contentType(ContentType.JSON)
|
||||
.extract()
|
||||
.response();
|
||||
Map<String, String> path = response.jsonPath().getMap("data[0]");
|
||||
return path.get("traceID") != null;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,8 +77,7 @@ public class TracerShimTest {
|
|||
@Test
|
||||
public void extract_nullContext() {
|
||||
SpanContext result =
|
||||
tracerShim.extract(
|
||||
Format.Builtin.TEXT_MAP, new TextMapAdapter(Collections.<String, String>emptyMap()));
|
||||
tracerShim.extract(Format.Builtin.TEXT_MAP, new TextMapAdapter(Collections.emptyMap()));
|
||||
assertNull(result);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import io.opentelemetry.sdk.trace.data.SpanData;
|
|||
import io.opentelemetry.trace.Span.Kind;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Callable;
|
||||
|
|
@ -37,12 +36,7 @@ public final class TestUtils {
|
|||
|
||||
/** Returns the number of finished {@code Span}s in the specified {@code InMemorySpanExporter}. */
|
||||
public static Callable<Integer> finishedSpansSize(final InMemorySpanExporter exporter) {
|
||||
return new Callable<Integer>() {
|
||||
@Override
|
||||
public Integer call() {
|
||||
return exporter.getFinishedSpanItems().size();
|
||||
}
|
||||
};
|
||||
return () -> exporter.getFinishedSpanItems().size();
|
||||
}
|
||||
|
||||
/** Returns a {@code List} with the {@code Span} matching the specified attribute. */
|
||||
|
|
@ -50,35 +44,32 @@ public final class TestUtils {
|
|||
List<SpanData> spans, final String key, final Object value) {
|
||||
return getByCondition(
|
||||
spans,
|
||||
new Condition() {
|
||||
@Override
|
||||
public boolean check(SpanData spanData) {
|
||||
AttributeValue attrValue = spanData.getAttributes().get(key);
|
||||
if (attrValue == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (attrValue.getType()) {
|
||||
case STRING:
|
||||
return value.equals(attrValue.getStringValue());
|
||||
case LONG:
|
||||
return value.equals(attrValue.getLongValue());
|
||||
case BOOLEAN:
|
||||
return value.equals(attrValue.getBooleanValue());
|
||||
case DOUBLE:
|
||||
return value.equals(attrValue.getDoubleValue());
|
||||
case STRING_ARRAY:
|
||||
return value.equals(attrValue.getStringArrayValue());
|
||||
case LONG_ARRAY:
|
||||
return value.equals(attrValue.getLongArrayValue());
|
||||
case BOOLEAN_ARRAY:
|
||||
return value.equals(attrValue.getBooleanArrayValue());
|
||||
case DOUBLE_ARRAY:
|
||||
return value.equals(attrValue.getDoubleArrayValue());
|
||||
}
|
||||
|
||||
spanData -> {
|
||||
AttributeValue attrValue = spanData.getAttributes().get(key);
|
||||
if (attrValue == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (attrValue.getType()) {
|
||||
case STRING:
|
||||
return value.equals(attrValue.getStringValue());
|
||||
case LONG:
|
||||
return value.equals(attrValue.getLongValue());
|
||||
case BOOLEAN:
|
||||
return value.equals(attrValue.getBooleanValue());
|
||||
case DOUBLE:
|
||||
return value.equals(attrValue.getDoubleValue());
|
||||
case STRING_ARRAY:
|
||||
return value.equals(attrValue.getStringArrayValue());
|
||||
case LONG_ARRAY:
|
||||
return value.equals(attrValue.getLongArrayValue());
|
||||
case BOOLEAN_ARRAY:
|
||||
return value.equals(attrValue.getBooleanArrayValue());
|
||||
case DOUBLE_ARRAY:
|
||||
return value.equals(attrValue.getDoubleArrayValue());
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -99,14 +90,7 @@ public final class TestUtils {
|
|||
|
||||
/** Returns a {@code List} with the {@code Span} matching the specified kind. */
|
||||
public static List<SpanData> getByKind(List<SpanData> spans, final Kind kind) {
|
||||
return getByCondition(
|
||||
spans,
|
||||
new Condition() {
|
||||
@Override
|
||||
public boolean check(SpanData span) {
|
||||
return span.getKind() == kind;
|
||||
}
|
||||
});
|
||||
return getByCondition(spans, span -> span.getKind() == kind);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -126,14 +110,7 @@ public final class TestUtils {
|
|||
|
||||
/** Returns a {@code List} with the {@code Span} matching the specified name. */
|
||||
private static List<SpanData> getByName(List<SpanData> spans, final String name) {
|
||||
return getByCondition(
|
||||
spans,
|
||||
new Condition() {
|
||||
@Override
|
||||
public boolean check(SpanData span) {
|
||||
return span.getName().equals(name);
|
||||
}
|
||||
});
|
||||
return getByCondition(spans, span -> span.getName().equals(name));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -193,13 +170,7 @@ public final class TestUtils {
|
|||
public static List<SpanData> sortByStartTime(List<SpanData> spans) {
|
||||
List<SpanData> sortedSpans = new ArrayList<>(spans);
|
||||
Collections.sort(
|
||||
sortedSpans,
|
||||
new Comparator<SpanData>() {
|
||||
@Override
|
||||
public int compare(SpanData o1, SpanData o2) {
|
||||
return Long.compare(o1.getStartEpochNanos(), o2.getStartEpochNanos());
|
||||
}
|
||||
});
|
||||
sortedSpans, (o1, o2) -> Long.compare(o1.getStartEpochNanos(), o2.getStartEpochNanos()));
|
||||
return sortedSpans;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -81,31 +81,28 @@ public class ActiveSpanReplacementTest {
|
|||
private void submitAnotherTask(final Span initialSpan) {
|
||||
|
||||
executor.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Create a new Span for this task
|
||||
Span taskSpan = tracer.buildSpan("task").start();
|
||||
try (Scope scope = tracer.scopeManager().activate(taskSpan)) {
|
||||
() -> {
|
||||
// Create a new Span for this task
|
||||
Span taskSpan = tracer.buildSpan("task").start();
|
||||
try (Scope scope = tracer.scopeManager().activate(taskSpan)) {
|
||||
|
||||
// Simulate work strictly related to the initial Span
|
||||
// and finish it.
|
||||
try (Scope initialScope = tracer.scopeManager().activate(initialSpan)) {
|
||||
sleep(50);
|
||||
} finally {
|
||||
initialSpan.finish();
|
||||
}
|
||||
|
||||
// Restore the span for this task and create a subspan
|
||||
Span subTaskSpan = tracer.buildSpan("subtask").start();
|
||||
try (Scope subTaskScope = tracer.scopeManager().activate(subTaskSpan)) {
|
||||
sleep(50);
|
||||
} finally {
|
||||
subTaskSpan.finish();
|
||||
}
|
||||
// Simulate work strictly related to the initial Span
|
||||
// and finish it.
|
||||
try (Scope initialScope = tracer.scopeManager().activate(initialSpan)) {
|
||||
sleep(50);
|
||||
} finally {
|
||||
taskSpan.finish();
|
||||
initialSpan.finish();
|
||||
}
|
||||
|
||||
// Restore the span for this task and create a subspan
|
||||
Span subTaskSpan = tracer.buildSpan("subtask").start();
|
||||
try (Scope subTaskScope = tracer.scopeManager().activate(subTaskSpan)) {
|
||||
sleep(50);
|
||||
} finally {
|
||||
subTaskSpan.finish();
|
||||
}
|
||||
} finally {
|
||||
taskSpan.finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import io.opentracing.Scope;
|
|||
import io.opentracing.Span;
|
||||
import io.opentracing.Tracer;
|
||||
import io.opentracing.tag.Tags;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
|
@ -49,26 +48,23 @@ final class Actor implements AutoCloseable {
|
|||
final Span parent = tracer.scopeManager().activeSpan();
|
||||
phaser.register();
|
||||
return executor.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Span child =
|
||||
tracer
|
||||
.buildSpan("received")
|
||||
.addReference(References.FOLLOWS_FROM, parent.context())
|
||||
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CONSUMER)
|
||||
.start();
|
||||
try (Scope scope = tracer.activateSpan(child)) {
|
||||
phaser.arriveAndAwaitAdvance(); // child tracer started
|
||||
child.log("received " + message);
|
||||
phaser.arriveAndAwaitAdvance(); // assert size
|
||||
} finally {
|
||||
child.finish();
|
||||
}
|
||||
|
||||
phaser.arriveAndAwaitAdvance(); // child tracer finished
|
||||
() -> {
|
||||
Span child =
|
||||
tracer
|
||||
.buildSpan("received")
|
||||
.addReference(References.FOLLOWS_FROM, parent.context())
|
||||
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CONSUMER)
|
||||
.start();
|
||||
try (Scope scope = tracer.activateSpan(child)) {
|
||||
phaser.arriveAndAwaitAdvance(); // child tracer started
|
||||
child.log("received " + message);
|
||||
phaser.arriveAndAwaitAdvance(); // assert size
|
||||
} finally {
|
||||
child.finish();
|
||||
}
|
||||
|
||||
phaser.arriveAndAwaitAdvance(); // child tracer finished
|
||||
phaser.arriveAndAwaitAdvance(); // assert size
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -77,25 +73,22 @@ final class Actor implements AutoCloseable {
|
|||
phaser.register();
|
||||
Future<String> future =
|
||||
executor.submit(
|
||||
new Callable<String>() {
|
||||
@Override
|
||||
public String call() {
|
||||
Span span =
|
||||
tracer
|
||||
.buildSpan("received")
|
||||
.addReference(References.FOLLOWS_FROM, parent.context())
|
||||
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CONSUMER)
|
||||
.start();
|
||||
try {
|
||||
phaser.arriveAndAwaitAdvance(); // child tracer started
|
||||
phaser.arriveAndAwaitAdvance(); // assert size
|
||||
return "received " + message;
|
||||
} finally {
|
||||
span.finish();
|
||||
() -> {
|
||||
Span span =
|
||||
tracer
|
||||
.buildSpan("received")
|
||||
.addReference(References.FOLLOWS_FROM, parent.context())
|
||||
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CONSUMER)
|
||||
.start();
|
||||
try {
|
||||
phaser.arriveAndAwaitAdvance(); // child tracer started
|
||||
phaser.arriveAndAwaitAdvance(); // assert size
|
||||
return "received " + message;
|
||||
} finally {
|
||||
span.finish();
|
||||
|
||||
phaser.arriveAndAwaitAdvance(); // child tracer finished
|
||||
phaser.arriveAndAwaitAdvance(); // assert size
|
||||
}
|
||||
phaser.arriveAndAwaitAdvance(); // child tracer finished
|
||||
phaser.arriveAndAwaitAdvance(); // assert size
|
||||
}
|
||||
});
|
||||
return future;
|
||||
|
|
|
|||
|
|
@ -44,27 +44,24 @@ public final class BaggageHandlingTest {
|
|||
|
||||
Future<?> f =
|
||||
executor.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
/* Override the previous value... */
|
||||
span.setBaggageItem("key1", "value2");
|
||||
() -> {
|
||||
/* Override the previous value... */
|
||||
span.setBaggageItem("key1", "value2");
|
||||
|
||||
/* add a new baggage item... */
|
||||
span.setBaggageItem("newkey", "newvalue");
|
||||
/* add a new baggage item... */
|
||||
span.setBaggageItem("newkey", "newvalue");
|
||||
|
||||
/* have a child that updates its own baggage
|
||||
* (should not be reflected in the original Span). */
|
||||
Span childSpan = tracer.buildSpan("child").start();
|
||||
try {
|
||||
childSpan.setBaggageItem("key1", "childvalue");
|
||||
} finally {
|
||||
childSpan.finish();
|
||||
}
|
||||
|
||||
/* and finish the Span. */
|
||||
span.finish();
|
||||
/* have a child that updates its own baggage
|
||||
* (should not be reflected in the original Span). */
|
||||
Span childSpan = tracer.buildSpan("child").start();
|
||||
try {
|
||||
childSpan.setBaggageItem("key1", "childvalue");
|
||||
} finally {
|
||||
childSpan.finish();
|
||||
}
|
||||
|
||||
/* and finish the Span. */
|
||||
span.finish();
|
||||
});
|
||||
|
||||
/* Single call, no need to use await() */
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
package io.opentelemetry.opentracingshim.testbed.concurrentcommonrequesthandler;
|
||||
|
||||
import io.opentelemetry.opentracingshim.testbed.TestUtils;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
|
@ -39,35 +38,26 @@ final class Client {
|
|||
public Future<String> send(final Object message) {
|
||||
final Context context = new Context();
|
||||
return executor.submit(
|
||||
new Callable<String>() {
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
logger.info("send {}", message);
|
||||
TestUtils.sleep();
|
||||
executor
|
||||
.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TestUtils.sleep();
|
||||
requestHandler.beforeRequest(message, context);
|
||||
}
|
||||
})
|
||||
.get();
|
||||
() -> {
|
||||
logger.info("send {}", message);
|
||||
TestUtils.sleep();
|
||||
executor
|
||||
.submit(
|
||||
() -> {
|
||||
TestUtils.sleep();
|
||||
requestHandler.beforeRequest(message, context);
|
||||
})
|
||||
.get();
|
||||
|
||||
executor
|
||||
.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TestUtils.sleep();
|
||||
requestHandler.afterResponse(message, context);
|
||||
}
|
||||
})
|
||||
.get();
|
||||
executor
|
||||
.submit(
|
||||
() -> {
|
||||
TestUtils.sleep();
|
||||
requestHandler.afterResponse(message, context);
|
||||
})
|
||||
.get();
|
||||
|
||||
return message + ":response";
|
||||
}
|
||||
return message + ":response";
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -75,16 +75,13 @@ public final class ErrorReportingTest {
|
|||
public void testCallbackError() {
|
||||
final Span span = tracer.buildSpan("one").start();
|
||||
executor.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try (Scope scope = tracer.activateSpan(span)) {
|
||||
throw new RuntimeException("Invalid state");
|
||||
} catch (Exception exc) {
|
||||
Tags.ERROR.set(span, true);
|
||||
} finally {
|
||||
span.finish();
|
||||
}
|
||||
() -> {
|
||||
try (Scope scope = tracer.activateSpan(span)) {
|
||||
throw new RuntimeException("Invalid state");
|
||||
} catch (Exception exc) {
|
||||
Tags.ERROR.set(span, true);
|
||||
} finally {
|
||||
span.finish();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -144,16 +141,13 @@ public final class ErrorReportingTest {
|
|||
// ScopedRunnable captures the active Span at this time.
|
||||
executor.submit(
|
||||
new ScopedRunnable(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
throw new RuntimeException("Invalid state");
|
||||
} catch (Exception exc) {
|
||||
Tags.ERROR.set(tracer.activeSpan(), true);
|
||||
} finally {
|
||||
tracer.activeSpan().finish();
|
||||
}
|
||||
() -> {
|
||||
try {
|
||||
throw new RuntimeException("Invalid state");
|
||||
} catch (Exception exc) {
|
||||
Tags.ERROR.set(tracer.activeSpan(), true);
|
||||
} finally {
|
||||
tracer.activeSpan().finish();
|
||||
}
|
||||
},
|
||||
tracer));
|
||||
|
|
|
|||
|
|
@ -76,33 +76,27 @@ public final class LateSpanFinishTest {
|
|||
private void submitTasks(final Span parentSpan) {
|
||||
|
||||
executor.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
/* Alternative to calling activate() is to pass it manually to asChildOf() for each
|
||||
* created Span. */
|
||||
try (Scope scope = tracer.scopeManager().activate(parentSpan)) {
|
||||
Span childSpan = tracer.buildSpan("task1").start();
|
||||
try (Scope childScope = tracer.scopeManager().activate(childSpan)) {
|
||||
sleep(55);
|
||||
} finally {
|
||||
childSpan.finish();
|
||||
}
|
||||
() -> {
|
||||
/* Alternative to calling activate() is to pass it manually to asChildOf() for each
|
||||
* created Span. */
|
||||
try (Scope scope = tracer.scopeManager().activate(parentSpan)) {
|
||||
Span childSpan = tracer.buildSpan("task1").start();
|
||||
try (Scope childScope = tracer.scopeManager().activate(childSpan)) {
|
||||
sleep(55);
|
||||
} finally {
|
||||
childSpan.finish();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
executor.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try (Scope scope = tracer.scopeManager().activate(parentSpan)) {
|
||||
Span childSpan = tracer.buildSpan("task2").start();
|
||||
try (Scope childScope = tracer.scopeManager().activate(childSpan)) {
|
||||
sleep(85);
|
||||
} finally {
|
||||
childSpan.finish();
|
||||
}
|
||||
() -> {
|
||||
try (Scope scope = tracer.scopeManager().activate(parentSpan)) {
|
||||
Span childSpan = tracer.buildSpan("task2").start();
|
||||
try (Scope childScope = tracer.scopeManager().activate(childSpan)) {
|
||||
sleep(85);
|
||||
} finally {
|
||||
childSpan.finish();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ package io.opentelemetry.opentracingshim.testbed.listenerperrequest;
|
|||
import io.opentracing.Span;
|
||||
import io.opentracing.Tracer;
|
||||
import io.opentracing.tag.Tags;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
|
@ -35,14 +34,11 @@ final class Client {
|
|||
/** Async execution. */
|
||||
private Future<Object> execute(final Object message, final ResponseListener responseListener) {
|
||||
return executor.submit(
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() {
|
||||
// send via wire and get response
|
||||
Object response = message + ":response";
|
||||
responseListener.onResponse(response);
|
||||
return response;
|
||||
}
|
||||
() -> {
|
||||
// send via wire and get response
|
||||
Object response = message + ":response";
|
||||
responseListener.onResponse(response);
|
||||
return response;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import io.opentracing.Scope;
|
|||
import io.opentracing.Span;
|
||||
import io.opentracing.SpanContext;
|
||||
import io.opentracing.Tracer;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
|
@ -45,26 +44,23 @@ class Client {
|
|||
final SpanContext parentSpanContext = tracer.activeSpan().context();
|
||||
|
||||
return executor.submit(
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
logger.info("Child thread with message '{}' started", message);
|
||||
() -> {
|
||||
logger.info("Child thread with message '{}' started", message);
|
||||
|
||||
Span span =
|
||||
tracer
|
||||
.buildSpan("subtask")
|
||||
.addReference(References.FOLLOWS_FROM, parentSpanContext)
|
||||
.start();
|
||||
try (Scope subtaskScope = tracer.activateSpan(span)) {
|
||||
// Simulate work - make sure we finish *after* the parent Span.
|
||||
parentDoneLatch.await();
|
||||
} finally {
|
||||
span.finish();
|
||||
}
|
||||
|
||||
logger.info("Child thread with message '{}' finished", message);
|
||||
return message + "::response";
|
||||
Span span =
|
||||
tracer
|
||||
.buildSpan("subtask")
|
||||
.addReference(References.FOLLOWS_FROM, parentSpanContext)
|
||||
.start();
|
||||
try (Scope subtaskScope = tracer.activateSpan(span)) {
|
||||
// Simulate work - make sure we finish *after* the parent Span.
|
||||
parentDoneLatch.await();
|
||||
} finally {
|
||||
span.finish();
|
||||
}
|
||||
|
||||
logger.info("Child thread with message '{}' finished", message);
|
||||
return message + "::response";
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,34 +73,25 @@ public final class NestedCallbacksTest {
|
|||
private void submitCallbacks(final Span span) {
|
||||
|
||||
executor.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try (Scope scope = tracer.scopeManager().activate(span)) {
|
||||
span.setTag("key1", "1");
|
||||
() -> {
|
||||
try (Scope scope = tracer.scopeManager().activate(span)) {
|
||||
span.setTag("key1", "1");
|
||||
|
||||
executor.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try (Scope scope = tracer.scopeManager().activate(span)) {
|
||||
span.setTag("key2", "2");
|
||||
executor.submit(
|
||||
() -> {
|
||||
try (Scope scope12 = tracer.scopeManager().activate(span)) {
|
||||
span.setTag("key2", "2");
|
||||
|
||||
executor.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try (Scope scope = tracer.scopeManager().activate(span)) {
|
||||
span.setTag("key3", "3");
|
||||
} finally {
|
||||
span.finish();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
executor.submit(
|
||||
() -> {
|
||||
try (Scope scope1 = tracer.scopeManager().activate(span)) {
|
||||
span.setTag("key3", "3");
|
||||
} finally {
|
||||
span.finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,22 +52,19 @@ final class Promise<T> {
|
|||
public void success(final T result) {
|
||||
for (final SuccessCallback<T> callback : successCallbacks) {
|
||||
context.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Span childSpan =
|
||||
tracer
|
||||
.buildSpan("success")
|
||||
.addReference(References.FOLLOWS_FROM, parentSpan.context())
|
||||
.withTag(Tags.COMPONENT.getKey(), "success")
|
||||
.start();
|
||||
try (Scope childScope = tracer.activateSpan(childSpan)) {
|
||||
callback.accept(result);
|
||||
} finally {
|
||||
childSpan.finish();
|
||||
}
|
||||
context.getPhaser().arriveAndAwaitAdvance(); // trace reported
|
||||
() -> {
|
||||
Span childSpan =
|
||||
tracer
|
||||
.buildSpan("success")
|
||||
.addReference(References.FOLLOWS_FROM, parentSpan.context())
|
||||
.withTag(Tags.COMPONENT.getKey(), "success")
|
||||
.start();
|
||||
try (Scope childScope = tracer.activateSpan(childSpan)) {
|
||||
callback.accept(result);
|
||||
} finally {
|
||||
childSpan.finish();
|
||||
}
|
||||
context.getPhaser().arriveAndAwaitAdvance(); // trace reported
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -76,22 +73,19 @@ final class Promise<T> {
|
|||
public void error(final Throwable error) {
|
||||
for (final ErrorCallback callback : errorCallbacks) {
|
||||
context.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Span childSpan =
|
||||
tracer
|
||||
.buildSpan("error")
|
||||
.addReference(References.FOLLOWS_FROM, parentSpan.context())
|
||||
.withTag(Tags.COMPONENT.getKey(), "error")
|
||||
.start();
|
||||
try (Scope childScope = tracer.activateSpan(childSpan)) {
|
||||
callback.accept(error);
|
||||
} finally {
|
||||
childSpan.finish();
|
||||
}
|
||||
context.getPhaser().arriveAndAwaitAdvance(); // trace reported
|
||||
() -> {
|
||||
Span childSpan =
|
||||
tracer
|
||||
.buildSpan("error")
|
||||
.addReference(References.FOLLOWS_FROM, parentSpan.context())
|
||||
.withTag(Tags.COMPONENT.getKey(), "error")
|
||||
.start();
|
||||
try (Scope childScope = tracer.activateSpan(childSpan)) {
|
||||
callback.accept(error);
|
||||
} finally {
|
||||
childSpan.finish();
|
||||
}
|
||||
context.getPhaser().arriveAndAwaitAdvance(); // trace reported
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,33 +71,24 @@ public class PromisePropagationTest {
|
|||
Promise<String> successPromise = new Promise<>(context, tracer);
|
||||
|
||||
successPromise.onSuccess(
|
||||
new Promise.SuccessCallback<String>() {
|
||||
@Override
|
||||
public void accept(String s) {
|
||||
tracer.activeSpan().log("Promised 1 " + s);
|
||||
successResult1.set(s);
|
||||
phaser.arriveAndAwaitAdvance(); // result set
|
||||
}
|
||||
s -> {
|
||||
tracer.activeSpan().log("Promised 1 " + s);
|
||||
successResult1.set(s);
|
||||
phaser.arriveAndAwaitAdvance(); // result set
|
||||
});
|
||||
successPromise.onSuccess(
|
||||
new Promise.SuccessCallback<String>() {
|
||||
@Override
|
||||
public void accept(String s) {
|
||||
tracer.activeSpan().log("Promised 2 " + s);
|
||||
successResult2.set(s);
|
||||
phaser.arriveAndAwaitAdvance(); // result set
|
||||
}
|
||||
s -> {
|
||||
tracer.activeSpan().log("Promised 2 " + s);
|
||||
successResult2.set(s);
|
||||
phaser.arriveAndAwaitAdvance(); // result set
|
||||
});
|
||||
|
||||
Promise<String> errorPromise = new Promise<>(context, tracer);
|
||||
|
||||
errorPromise.onError(
|
||||
new Promise.ErrorCallback() {
|
||||
@Override
|
||||
public void accept(Throwable t) {
|
||||
errorResult.set(t);
|
||||
phaser.arriveAndAwaitAdvance(); // result set
|
||||
}
|
||||
t -> {
|
||||
errorResult.set(t);
|
||||
phaser.arriveAndAwaitAdvance(); // result set
|
||||
});
|
||||
|
||||
assertThat(inMemoryTracing.getSpanExporter().getFinishedSpanItems().size()).isEqualTo(0);
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
package io.opentelemetry.opentracingshim.testbed.statelesscommonrequesthandler;
|
||||
|
||||
import io.opentelemetry.opentracingshim.testbed.TestUtils;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
|
@ -39,18 +38,15 @@ final class Client {
|
|||
public Future<String> send(final Object message) {
|
||||
|
||||
return executor.submit(
|
||||
new Callable<String>() {
|
||||
@Override
|
||||
public String call() {
|
||||
logger.info("send {}", message);
|
||||
TestUtils.sleep();
|
||||
requestHandler.beforeRequest(message);
|
||||
() -> {
|
||||
logger.info("send {}", message);
|
||||
TestUtils.sleep();
|
||||
requestHandler.beforeRequest(message);
|
||||
|
||||
TestUtils.sleep();
|
||||
requestHandler.afterResponse(message);
|
||||
TestUtils.sleep();
|
||||
requestHandler.afterResponse(message);
|
||||
|
||||
return message + ":response";
|
||||
}
|
||||
return message + ":response";
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,29 +102,25 @@ public class ConfigBuilderTest {
|
|||
|
||||
@Test
|
||||
public void nullValue_BooleanProperty() {
|
||||
Boolean booleanProperty =
|
||||
ConfigBuilder.getBooleanProperty("boolean", Collections.<String, String>emptyMap());
|
||||
Boolean booleanProperty = ConfigBuilder.getBooleanProperty("boolean", Collections.emptyMap());
|
||||
assertThat(booleanProperty).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullValue_LongProperty() {
|
||||
Long longProperty =
|
||||
ConfigBuilder.getLongProperty("long", Collections.<String, String>emptyMap());
|
||||
Long longProperty = ConfigBuilder.getLongProperty("long", Collections.emptyMap());
|
||||
assertThat(longProperty).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullValue_IntProperty() {
|
||||
Integer intProperty =
|
||||
ConfigBuilder.getIntProperty("int", Collections.<String, String>emptyMap());
|
||||
Integer intProperty = ConfigBuilder.getIntProperty("int", Collections.emptyMap());
|
||||
assertThat(intProperty).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullValue_DoubleProperty() {
|
||||
Double doubleProperty =
|
||||
ConfigBuilder.getDoubleProperty("double", Collections.<String, String>emptyMap());
|
||||
Double doubleProperty = ConfigBuilder.getDoubleProperty("double", Collections.emptyMap());
|
||||
assertThat(doubleProperty).isNull();
|
||||
}
|
||||
|
||||
|
|
@ -240,10 +236,6 @@ public class ConfigBuilderTest {
|
|||
return NamingConvention.DOT;
|
||||
}
|
||||
|
||||
public static NamingConvention getNamingEnv() {
|
||||
return NamingConvention.ENV_VAR;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Map<String, String> fromConfigMap(
|
||||
Map<String, String> configMap, NamingConvention namingConvention) {
|
||||
|
|
|
|||
|
|
@ -82,12 +82,8 @@ public class CorrelationContextManagerSdkTest {
|
|||
runnable =
|
||||
Context.current()
|
||||
.wrap(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
assertThat(contextManager.getCurrentContext()).isSameInstanceAs(distContext);
|
||||
}
|
||||
});
|
||||
() ->
|
||||
assertThat(contextManager.getCurrentContext()).isSameInstanceAs(distContext));
|
||||
}
|
||||
assertThat(contextManager.getCurrentContext())
|
||||
.isSameInstanceAs(EmptyCorrelationContext.getInstance());
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
|
|||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor.Type;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.DoublePoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.LongPoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Point;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.util.Collections;
|
||||
import org.junit.Rule;
|
||||
|
|
@ -90,7 +89,7 @@ public class BatchRecorderSdkTest {
|
|||
"testDoubleCounter", "", "1", Type.MONOTONIC_DOUBLE, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
DoublePoint.create(testClock.now(), testClock.now(), labelSet, 12.1d))));
|
||||
assertThat(longCounter.collectAll())
|
||||
.containsExactly(
|
||||
|
|
@ -98,7 +97,7 @@ public class BatchRecorderSdkTest {
|
|||
Descriptor.create("testLongCounter", "", "1", Type.MONOTONIC_LONG, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
LongPoint.create(testClock.now(), testClock.now(), labelSet, 12))));
|
||||
assertThat(doubleUpDownCounter.collectAll())
|
||||
.containsExactly(
|
||||
|
|
@ -107,7 +106,7 @@ public class BatchRecorderSdkTest {
|
|||
"testDoubleUpDownCounter", "", "1", Type.NON_MONOTONIC_DOUBLE, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
DoublePoint.create(testClock.now(), testClock.now(), labelSet, -12.1d))));
|
||||
assertThat(longUpDownCounter.collectAll())
|
||||
.containsExactly(
|
||||
|
|
@ -116,7 +115,7 @@ public class BatchRecorderSdkTest {
|
|||
"testLongUpDownCounter", "", "1", Type.NON_MONOTONIC_LONG, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
LongPoint.create(testClock.now(), testClock.now(), labelSet, -12))));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,15 +21,12 @@ import static com.google.common.truth.Truth.assertThat;
|
|||
import io.opentelemetry.common.AttributeValue;
|
||||
import io.opentelemetry.common.Attributes;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.Callback;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.DoubleResult;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.internal.TestClock;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor.Type;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.DoublePoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Point;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.util.Collections;
|
||||
import org.junit.Rule;
|
||||
|
|
@ -78,11 +75,8 @@ public class DoubleSumObserverSdkTest {
|
|||
.setUnit("ms")
|
||||
.build();
|
||||
doubleSumObserver.setCallback(
|
||||
new Callback<DoubleResult>() {
|
||||
@Override
|
||||
public void update(DoubleResult result) {
|
||||
// Do nothing.
|
||||
}
|
||||
result -> {
|
||||
// Do nothing.
|
||||
});
|
||||
assertThat(doubleSumObserver.collectAll())
|
||||
.containsExactly(
|
||||
|
|
@ -95,20 +89,14 @@ public class DoubleSumObserverSdkTest {
|
|||
Labels.of("sk1", "sv1")),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>emptyList()));
|
||||
Collections.emptyList()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void collectMetrics_WithOneRecord() {
|
||||
DoubleSumObserverSdk doubleSumObserver =
|
||||
testSdk.doubleSumObserverBuilder("testObserver").build();
|
||||
doubleSumObserver.setCallback(
|
||||
new Callback<DoubleResult>() {
|
||||
@Override
|
||||
public void update(DoubleResult result) {
|
||||
result.observe(12.1d, Labels.of("k", "v"));
|
||||
}
|
||||
});
|
||||
doubleSumObserver.setCallback(result -> result.observe(12.1d, Labels.of("k", "v")));
|
||||
testClock.advanceNanos(SECOND_NANOS);
|
||||
assertThat(doubleSumObserver.collectAll())
|
||||
.containsExactly(
|
||||
|
|
@ -116,7 +104,7 @@ public class DoubleSumObserverSdkTest {
|
|||
Descriptor.create("testObserver", "", "1", Type.MONOTONIC_DOUBLE, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
DoublePoint.create(
|
||||
testClock.now() - SECOND_NANOS,
|
||||
testClock.now(),
|
||||
|
|
@ -129,7 +117,7 @@ public class DoubleSumObserverSdkTest {
|
|||
Descriptor.create("testObserver", "", "1", Type.MONOTONIC_DOUBLE, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
DoublePoint.create(
|
||||
testClock.now() - 2 * SECOND_NANOS,
|
||||
testClock.now(),
|
||||
|
|
|
|||
|
|
@ -21,15 +21,12 @@ import static com.google.common.truth.Truth.assertThat;
|
|||
import io.opentelemetry.common.AttributeValue;
|
||||
import io.opentelemetry.common.Attributes;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.Callback;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.DoubleResult;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.internal.TestClock;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor.Type;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.DoublePoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Point;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.util.Collections;
|
||||
import org.junit.Rule;
|
||||
|
|
@ -78,11 +75,8 @@ public class DoubleUpDownSumObserverSdkTest {
|
|||
.setUnit("ms")
|
||||
.build();
|
||||
doubleUpDownSumObserver.setCallback(
|
||||
new Callback<DoubleResult>() {
|
||||
@Override
|
||||
public void update(DoubleResult result) {
|
||||
// Do nothing.
|
||||
}
|
||||
result -> {
|
||||
// Do nothing.
|
||||
});
|
||||
assertThat(doubleUpDownSumObserver.collectAll())
|
||||
.containsExactly(
|
||||
|
|
@ -95,20 +89,14 @@ public class DoubleUpDownSumObserverSdkTest {
|
|||
Labels.of("sk1", "sv1")),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>emptyList()));
|
||||
Collections.emptyList()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void collectMetrics_WithOneRecord() {
|
||||
DoubleUpDownSumObserverSdk doubleUpDownSumObserver =
|
||||
testSdk.doubleUpDownSumObserverBuilder("testObserver").build();
|
||||
doubleUpDownSumObserver.setCallback(
|
||||
new Callback<DoubleResult>() {
|
||||
@Override
|
||||
public void update(DoubleResult result) {
|
||||
result.observe(12.1d, Labels.of("k", "v"));
|
||||
}
|
||||
});
|
||||
doubleUpDownSumObserver.setCallback(result -> result.observe(12.1d, Labels.of("k", "v")));
|
||||
testClock.advanceNanos(SECOND_NANOS);
|
||||
assertThat(doubleUpDownSumObserver.collectAll())
|
||||
.containsExactly(
|
||||
|
|
@ -117,7 +105,7 @@ public class DoubleUpDownSumObserverSdkTest {
|
|||
"testObserver", "", "1", Type.NON_MONOTONIC_DOUBLE, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
DoublePoint.create(
|
||||
testClock.now() - SECOND_NANOS,
|
||||
testClock.now(),
|
||||
|
|
@ -131,7 +119,7 @@ public class DoubleUpDownSumObserverSdkTest {
|
|||
"testObserver", "", "1", Type.NON_MONOTONIC_DOUBLE, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
DoublePoint.create(
|
||||
testClock.now() - 2 * SECOND_NANOS,
|
||||
testClock.now(),
|
||||
|
|
|
|||
|
|
@ -21,14 +21,11 @@ import static com.google.common.truth.Truth.assertThat;
|
|||
import io.opentelemetry.common.AttributeValue;
|
||||
import io.opentelemetry.common.Attributes;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.Callback;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.DoubleResult;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.internal.TestClock;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor.Type;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Point;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.SummaryPoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.ValueAtPercentile;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
|
|
@ -81,11 +78,8 @@ public class DoubleValueObserverSdkTest {
|
|||
.setUnit("ms")
|
||||
.build();
|
||||
doubleValueObserver.setCallback(
|
||||
new Callback<DoubleResult>() {
|
||||
@Override
|
||||
public void update(DoubleResult result) {
|
||||
// Do nothing.
|
||||
}
|
||||
result -> {
|
||||
// Do nothing.
|
||||
});
|
||||
assertThat(doubleValueObserver.collectAll())
|
||||
.containsExactly(
|
||||
|
|
@ -98,20 +92,14 @@ public class DoubleValueObserverSdkTest {
|
|||
Labels.of("sk1", "sv1")),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>emptyList()));
|
||||
Collections.emptyList()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void collectMetrics_WithOneRecord() {
|
||||
DoubleValueObserverSdk doubleValueObserver =
|
||||
testSdk.doubleValueObserverBuilder("testObserver").build();
|
||||
doubleValueObserver.setCallback(
|
||||
new Callback<DoubleResult>() {
|
||||
@Override
|
||||
public void update(DoubleResult result) {
|
||||
result.observe(12.1d, Labels.of("k", "v"));
|
||||
}
|
||||
});
|
||||
doubleValueObserver.setCallback(result -> result.observe(12.1d, Labels.of("k", "v")));
|
||||
testClock.advanceNanos(SECOND_NANOS);
|
||||
assertThat(doubleValueObserver.collectAll())
|
||||
.containsExactly(
|
||||
|
|
@ -119,7 +107,7 @@ public class DoubleValueObserverSdkTest {
|
|||
Descriptor.create("testObserver", "", "1", Type.SUMMARY, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
SummaryPoint.create(
|
||||
testClock.now() - SECOND_NANOS,
|
||||
testClock.now(),
|
||||
|
|
@ -134,7 +122,7 @@ public class DoubleValueObserverSdkTest {
|
|||
Descriptor.create("testObserver", "", "1", Type.SUMMARY, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
SummaryPoint.create(
|
||||
testClock.now() - SECOND_NANOS,
|
||||
testClock.now(),
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ import io.opentelemetry.sdk.metrics.StressTestRunner.OperationUpdater;
|
|||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor.Type;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Point;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.SummaryPoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.ValueAtPercentile;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
|
|
@ -82,7 +81,7 @@ public class DoubleValueRecorderSdkTest {
|
|||
Labels.of("sk1", "sv1")),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>emptyList()));
|
||||
Collections.emptyList()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -109,7 +108,7 @@ public class DoubleValueRecorderSdkTest {
|
|||
Labels.of("sk1", "sv1")),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>emptyList()));
|
||||
Collections.emptyList()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -125,7 +124,7 @@ public class DoubleValueRecorderSdkTest {
|
|||
Descriptor.create("testMeasure", "", "1", Type.SUMMARY, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
SummaryPoint.create(
|
||||
testClock.now() - SECOND_NANOS,
|
||||
testClock.now(),
|
||||
|
|
|
|||
|
|
@ -21,15 +21,12 @@ import static com.google.common.truth.Truth.assertThat;
|
|||
import io.opentelemetry.common.AttributeValue;
|
||||
import io.opentelemetry.common.Attributes;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.Callback;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.LongResult;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.internal.TestClock;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor.Type;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.LongPoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Point;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.util.Collections;
|
||||
import org.junit.Rule;
|
||||
|
|
@ -78,11 +75,8 @@ public class LongSumObserverSdkTest {
|
|||
.setUnit("ms")
|
||||
.build();
|
||||
longSumObserver.setCallback(
|
||||
new Callback<LongResult>() {
|
||||
@Override
|
||||
public void update(LongResult result) {
|
||||
// Do nothing.
|
||||
}
|
||||
result -> {
|
||||
// Do nothing.
|
||||
});
|
||||
assertThat(longSumObserver.collectAll())
|
||||
.containsExactly(
|
||||
|
|
@ -95,19 +89,13 @@ public class LongSumObserverSdkTest {
|
|||
Labels.of("sk1", "sv1")),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>emptyList()));
|
||||
Collections.emptyList()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void collectMetrics_WithOneRecord() {
|
||||
LongSumObserverSdk longSumObserver = testSdk.longSumObserverBuilder("testObserver").build();
|
||||
longSumObserver.setCallback(
|
||||
new Callback<LongResult>() {
|
||||
@Override
|
||||
public void update(LongResult result) {
|
||||
result.observe(12, Labels.of("k", "v"));
|
||||
}
|
||||
});
|
||||
longSumObserver.setCallback(result -> result.observe(12, Labels.of("k", "v")));
|
||||
testClock.advanceNanos(SECOND_NANOS);
|
||||
assertThat(longSumObserver.collectAll())
|
||||
.containsExactly(
|
||||
|
|
@ -115,7 +103,7 @@ public class LongSumObserverSdkTest {
|
|||
Descriptor.create("testObserver", "", "1", Type.MONOTONIC_LONG, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
LongPoint.create(
|
||||
testClock.now() - SECOND_NANOS,
|
||||
testClock.now(),
|
||||
|
|
@ -128,7 +116,7 @@ public class LongSumObserverSdkTest {
|
|||
Descriptor.create("testObserver", "", "1", Type.MONOTONIC_LONG, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
LongPoint.create(
|
||||
testClock.now() - 2 * SECOND_NANOS,
|
||||
testClock.now(),
|
||||
|
|
|
|||
|
|
@ -21,15 +21,12 @@ import static com.google.common.truth.Truth.assertThat;
|
|||
import io.opentelemetry.common.AttributeValue;
|
||||
import io.opentelemetry.common.Attributes;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.Callback;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.LongResult;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.internal.TestClock;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor.Type;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.LongPoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Point;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.util.Collections;
|
||||
import org.junit.Rule;
|
||||
|
|
@ -78,11 +75,8 @@ public class LongUpDownSumObserverSdkTest {
|
|||
.setUnit("ms")
|
||||
.build();
|
||||
longUpDownSumObserver.setCallback(
|
||||
new Callback<LongResult>() {
|
||||
@Override
|
||||
public void update(LongResult result) {
|
||||
// Do nothing.
|
||||
}
|
||||
result -> {
|
||||
// Do nothing.
|
||||
});
|
||||
assertThat(longUpDownSumObserver.collectAll())
|
||||
.containsExactly(
|
||||
|
|
@ -95,20 +89,14 @@ public class LongUpDownSumObserverSdkTest {
|
|||
Labels.of("sk1", "sv1")),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>emptyList()));
|
||||
Collections.emptyList()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void collectMetrics_WithOneRecord() {
|
||||
LongUpDownSumObserverSdk longUpDownSumObserver =
|
||||
testSdk.longUpDownSumObserverBuilder("testObserver").build();
|
||||
longUpDownSumObserver.setCallback(
|
||||
new Callback<LongResult>() {
|
||||
@Override
|
||||
public void update(LongResult result) {
|
||||
result.observe(12, Labels.of("k", "v"));
|
||||
}
|
||||
});
|
||||
longUpDownSumObserver.setCallback(result -> result.observe(12, Labels.of("k", "v")));
|
||||
testClock.advanceNanos(SECOND_NANOS);
|
||||
assertThat(longUpDownSumObserver.collectAll())
|
||||
.containsExactly(
|
||||
|
|
@ -116,7 +104,7 @@ public class LongUpDownSumObserverSdkTest {
|
|||
Descriptor.create("testObserver", "", "1", Type.NON_MONOTONIC_LONG, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
LongPoint.create(
|
||||
testClock.now() - SECOND_NANOS,
|
||||
testClock.now(),
|
||||
|
|
@ -129,7 +117,7 @@ public class LongUpDownSumObserverSdkTest {
|
|||
Descriptor.create("testObserver", "", "1", Type.NON_MONOTONIC_LONG, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
LongPoint.create(
|
||||
testClock.now() - 2 * SECOND_NANOS,
|
||||
testClock.now(),
|
||||
|
|
|
|||
|
|
@ -21,14 +21,11 @@ import static com.google.common.truth.Truth.assertThat;
|
|||
import io.opentelemetry.common.AttributeValue;
|
||||
import io.opentelemetry.common.Attributes;
|
||||
import io.opentelemetry.common.Labels;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.Callback;
|
||||
import io.opentelemetry.metrics.AsynchronousInstrument.LongResult;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.internal.TestClock;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor.Type;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Point;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.SummaryPoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.ValueAtPercentile;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
|
|
@ -81,11 +78,8 @@ public class LongValueObserverSdkTest {
|
|||
.setUnit("ms")
|
||||
.build();
|
||||
longValueObserver.setCallback(
|
||||
new Callback<LongResult>() {
|
||||
@Override
|
||||
public void update(LongResult result) {
|
||||
// Do nothing.
|
||||
}
|
||||
result -> {
|
||||
// Do nothing.
|
||||
});
|
||||
assertThat(longValueObserver.collectAll())
|
||||
.containsExactly(
|
||||
|
|
@ -98,20 +92,14 @@ public class LongValueObserverSdkTest {
|
|||
Labels.of("sk1", "sv1")),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>emptyList()));
|
||||
Collections.emptyList()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void collectMetrics_WithOneRecord() {
|
||||
LongValueObserverSdk longValueObserver =
|
||||
testSdk.longValueObserverBuilder("testObserver").build();
|
||||
longValueObserver.setCallback(
|
||||
new Callback<LongResult>() {
|
||||
@Override
|
||||
public void update(LongResult result) {
|
||||
result.observe(12, Labels.of("k", "v"));
|
||||
}
|
||||
});
|
||||
longValueObserver.setCallback(result -> result.observe(12, Labels.of("k", "v")));
|
||||
testClock.advanceNanos(SECOND_NANOS);
|
||||
assertThat(longValueObserver.collectAll())
|
||||
.containsExactly(
|
||||
|
|
@ -119,7 +107,7 @@ public class LongValueObserverSdkTest {
|
|||
Descriptor.create("testObserver", "", "1", Type.SUMMARY, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
SummaryPoint.create(
|
||||
testClock.now() - SECOND_NANOS,
|
||||
testClock.now(),
|
||||
|
|
@ -134,7 +122,7 @@ public class LongValueObserverSdkTest {
|
|||
Descriptor.create("testObserver", "", "1", Type.SUMMARY, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
SummaryPoint.create(
|
||||
testClock.now() - SECOND_NANOS,
|
||||
testClock.now(),
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ import io.opentelemetry.sdk.metrics.StressTestRunner.OperationUpdater;
|
|||
import io.opentelemetry.sdk.metrics.data.MetricData;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor.Type;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Point;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.SummaryPoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.ValueAtPercentile;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
|
|
@ -82,7 +81,7 @@ public class LongValueRecorderSdkTest {
|
|||
Labels.of("sk1", "sv1")),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>emptyList()));
|
||||
Collections.emptyList()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -110,7 +109,7 @@ public class LongValueRecorderSdkTest {
|
|||
Labels.of("sk1", "sv1")),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>emptyList()));
|
||||
Collections.emptyList()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -125,7 +124,7 @@ public class LongValueRecorderSdkTest {
|
|||
Descriptor.create("testMeasure", "", "1", Type.SUMMARY, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
SummaryPoint.create(
|
||||
testClock.now() - SECOND_NANOS,
|
||||
testClock.now(),
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ import io.opentelemetry.sdk.metrics.data.MetricData;
|
|||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor.Type;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.LongPoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Point;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
import java.util.Collections;
|
||||
import org.junit.Rule;
|
||||
|
|
@ -109,13 +108,13 @@ public class MeterSdkRegistryTest {
|
|||
Descriptor.create("testLongCounter", "", "1", Type.MONOTONIC_LONG, Labels.empty()),
|
||||
Resource.getEmpty(),
|
||||
meterSdk1.getInstrumentationLibraryInfo(),
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
LongPoint.create(testClock.now(), testClock.now(), Labels.empty(), 10))),
|
||||
MetricData.create(
|
||||
Descriptor.create("testLongCounter", "", "1", Type.MONOTONIC_LONG, Labels.empty()),
|
||||
Resource.getEmpty(),
|
||||
meterSdk2.getInstrumentationLibraryInfo(),
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
LongPoint.create(testClock.now(), testClock.now(), Labels.empty(), 10))));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,6 @@ import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
|
|||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor.Type;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.DoublePoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.LongPoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Point;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.SummaryPoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.ValueAtPercentile;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
|
|
@ -336,20 +335,20 @@ public class MeterSdkTest {
|
|||
Descriptor.create("testLongCounter", "", "1", Type.MONOTONIC_LONG, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
LongPoint.create(testClock.now(), testClock.now(), Labels.empty(), 10))),
|
||||
MetricData.create(
|
||||
Descriptor.create(
|
||||
"testDoubleCounter", "", "1", Type.MONOTONIC_DOUBLE, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
DoublePoint.create(testClock.now(), testClock.now(), Labels.empty(), 10.1))),
|
||||
MetricData.create(
|
||||
Descriptor.create("testLongValueRecorder", "", "1", Type.SUMMARY, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
SummaryPoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
|
|
@ -362,7 +361,7 @@ public class MeterSdkTest {
|
|||
Descriptor.create("testDoubleValueRecorder", "", "1", Type.SUMMARY, Labels.empty()),
|
||||
RESOURCE,
|
||||
INSTRUMENTATION_LIBRARY_INFO,
|
||||
Collections.<Point>singletonList(
|
||||
Collections.singletonList(
|
||||
SummaryPoint.create(
|
||||
testClock.now(),
|
||||
testClock.now(),
|
||||
|
|
|
|||
|
|
@ -40,30 +40,24 @@ abstract class StressTestRunner {
|
|||
final CountDownLatch countDownLatch = new CountDownLatch(numThreads);
|
||||
Thread collectionThread =
|
||||
new Thread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// While workers still work, do collections.
|
||||
while (countDownLatch.getCount() != 0) {
|
||||
Uninterruptibles.sleepUninterruptibly(
|
||||
getCollectionIntervalMs(), TimeUnit.MILLISECONDS);
|
||||
}
|
||||
() -> {
|
||||
// While workers still work, do collections.
|
||||
while (countDownLatch.getCount() != 0) {
|
||||
Uninterruptibles.sleepUninterruptibly(
|
||||
getCollectionIntervalMs(), TimeUnit.MILLISECONDS);
|
||||
}
|
||||
});
|
||||
List<Thread> operationThreads = new ArrayList<>(numThreads);
|
||||
for (final Operation operation : operations) {
|
||||
operationThreads.add(
|
||||
new Thread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (int i = 0; i < operation.getNumOperations(); i++) {
|
||||
operation.getUpdater().update();
|
||||
Uninterruptibles.sleepUninterruptibly(
|
||||
operation.getOperationDelayMs(), TimeUnit.MILLISECONDS);
|
||||
}
|
||||
countDownLatch.countDown();
|
||||
() -> {
|
||||
for (int i = 0; i < operation.getNumOperations(); i++) {
|
||||
operation.getUpdater().update();
|
||||
Uninterruptibles.sleepUninterruptibly(
|
||||
operation.getOperationDelayMs(), TimeUnit.MILLISECONDS);
|
||||
}
|
||||
countDownLatch.countDown();
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -80,20 +80,17 @@ public class DoubleMinMaxSumCountTest {
|
|||
final int index = i;
|
||||
Thread t =
|
||||
new Thread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
double update = updates[index];
|
||||
try {
|
||||
startingGun.await();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
for (int j = 0; j < numberOfUpdates; j++) {
|
||||
aggregator.recordDouble(update);
|
||||
if (ThreadLocalRandom.current().nextInt(10) == 0) {
|
||||
aggregator.mergeToAndReset(summarizer);
|
||||
}
|
||||
() -> {
|
||||
double update = updates[index];
|
||||
try {
|
||||
startingGun.await();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
for (int j = 0; j < numberOfUpdates; j++) {
|
||||
aggregator.recordDouble(update);
|
||||
if (ThreadLocalRandom.current().nextInt(10) == 0) {
|
||||
aggregator.mergeToAndReset(summarizer);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -82,20 +82,17 @@ public class LongMinMaxSumCountTest {
|
|||
final int index = i;
|
||||
Thread t =
|
||||
new Thread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
long update = updates[index];
|
||||
try {
|
||||
startingGun.await();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
for (int j = 0; j < numberOfUpdates; j++) {
|
||||
aggregator.recordLong(update);
|
||||
if (ThreadLocalRandom.current().nextInt(10) == 0) {
|
||||
aggregator.mergeToAndReset(summarizer);
|
||||
}
|
||||
() -> {
|
||||
long update = updates[index];
|
||||
try {
|
||||
startingGun.await();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
for (int j = 0; j < numberOfUpdates; j++) {
|
||||
aggregator.recordLong(update);
|
||||
if (ThreadLocalRandom.current().nextInt(10) == 0) {
|
||||
aggregator.mergeToAndReset(summarizer);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
|||
import io.opentelemetry.sdk.metrics.data.MetricData.Descriptor;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.DoublePoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.LongPoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.Point;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.SummaryPoint;
|
||||
import io.opentelemetry.sdk.metrics.data.MetricData.ValueAtPercentile;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
|
|
@ -88,7 +87,7 @@ public class MetricDataTest {
|
|||
null,
|
||||
Resource.getEmpty(),
|
||||
InstrumentationLibraryInfo.getEmpty(),
|
||||
Collections.<Point>singletonList(DOUBLE_POINT));
|
||||
Collections.singletonList(DOUBLE_POINT));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -99,7 +98,7 @@ public class MetricDataTest {
|
|||
LONG_METRIC_DESCRIPTOR,
|
||||
null,
|
||||
InstrumentationLibraryInfo.getEmpty(),
|
||||
Collections.<Point>singletonList(DOUBLE_POINT));
|
||||
Collections.singletonList(DOUBLE_POINT));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -107,10 +106,7 @@ public class MetricDataTest {
|
|||
thrown.expect(NullPointerException.class);
|
||||
thrown.expectMessage("instrumentationLibraryInfo");
|
||||
MetricData.create(
|
||||
LONG_METRIC_DESCRIPTOR,
|
||||
Resource.getEmpty(),
|
||||
null,
|
||||
Collections.<Point>singletonList(DOUBLE_POINT));
|
||||
LONG_METRIC_DESCRIPTOR, Resource.getEmpty(), null, Collections.singletonList(DOUBLE_POINT));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -128,7 +124,7 @@ public class MetricDataTest {
|
|||
LONG_METRIC_DESCRIPTOR,
|
||||
Resource.getEmpty(),
|
||||
InstrumentationLibraryInfo.getEmpty(),
|
||||
Collections.<Point>emptyList());
|
||||
Collections.emptyList());
|
||||
assertThat(metricData.getDescriptor()).isEqualTo(LONG_METRIC_DESCRIPTOR);
|
||||
assertThat(metricData.getResource()).isEqualTo(Resource.getEmpty());
|
||||
assertThat(metricData.getInstrumentationLibraryInfo())
|
||||
|
|
@ -148,7 +144,7 @@ public class MetricDataTest {
|
|||
LONG_METRIC_DESCRIPTOR,
|
||||
Resource.getEmpty(),
|
||||
InstrumentationLibraryInfo.getEmpty(),
|
||||
Collections.<Point>singletonList(LONG_POINT));
|
||||
Collections.singletonList(LONG_POINT));
|
||||
assertThat(metricData.getPoints()).containsExactly(LONG_POINT);
|
||||
}
|
||||
|
||||
|
|
@ -167,7 +163,7 @@ public class MetricDataTest {
|
|||
DOUBLE_METRIC_DESCRIPTOR,
|
||||
Resource.getEmpty(),
|
||||
InstrumentationLibraryInfo.getEmpty(),
|
||||
Collections.<Point>singletonList(SUMMARY_POINT));
|
||||
Collections.singletonList(SUMMARY_POINT));
|
||||
assertThat(metricData.getPoints()).containsExactly(SUMMARY_POINT);
|
||||
}
|
||||
|
||||
|
|
@ -183,7 +179,7 @@ public class MetricDataTest {
|
|||
DOUBLE_METRIC_DESCRIPTOR,
|
||||
Resource.getEmpty(),
|
||||
InstrumentationLibraryInfo.getEmpty(),
|
||||
Collections.<Point>singletonList(DOUBLE_POINT));
|
||||
Collections.singletonList(DOUBLE_POINT));
|
||||
assertThat(metricData.getPoints()).containsExactly(DOUBLE_POINT);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ public class IntervalMetricReaderTest {
|
|||
"my metric", "my metric description", "us", Type.MONOTONIC_LONG, Labels.empty());
|
||||
|
||||
private static final List<Point> LONG_POINT_LIST =
|
||||
Collections.<Point>singletonList(LongPoint.create(1000, 3000, Labels.empty(), 1234567));
|
||||
Collections.singletonList(LongPoint.create(1000, 3000, Labels.empty(), 1234567));
|
||||
|
||||
private static final MetricData METRIC_DATA =
|
||||
MetricData.create(
|
||||
|
|
|
|||
|
|
@ -51,8 +51,7 @@ public class MultiSpanProcessorTest {
|
|||
|
||||
@Test
|
||||
public void empty() {
|
||||
SpanProcessor multiSpanProcessor =
|
||||
MultiSpanProcessor.create(Collections.<SpanProcessor>emptyList());
|
||||
SpanProcessor multiSpanProcessor = MultiSpanProcessor.create(Collections.emptyList());
|
||||
multiSpanProcessor.onStart(readableSpan);
|
||||
multiSpanProcessor.onEnd(readableSpan);
|
||||
multiSpanProcessor.shutdown();
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import static com.google.common.truth.Truth.assertThat;
|
|||
import io.opentelemetry.common.AttributeValue;
|
||||
import io.opentelemetry.common.Attributes;
|
||||
import io.opentelemetry.common.ReadableAttributes;
|
||||
import io.opentelemetry.common.ReadableKeyValuePairs.KeyValueConsumer;
|
||||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
|
||||
import io.opentelemetry.sdk.internal.TestClock;
|
||||
import io.opentelemetry.sdk.resources.Resource;
|
||||
|
|
@ -113,7 +112,7 @@ public class RecordEventsReadableSpanTest {
|
|||
verifySpanData(
|
||||
spanData,
|
||||
Attributes.empty(),
|
||||
Collections.<Event>emptyList(),
|
||||
Collections.emptyList(),
|
||||
Collections.singletonList(link),
|
||||
SPAN_NAME,
|
||||
startEpochNanos,
|
||||
|
|
@ -660,13 +659,7 @@ public class RecordEventsReadableSpanTest {
|
|||
// verify equality manually, since the implementations don't all equals with each other.
|
||||
ReadableAttributes spanDataAttributes = spanData.getAttributes();
|
||||
assertThat(spanDataAttributes.size()).isEqualTo(attributes.size());
|
||||
spanDataAttributes.forEach(
|
||||
new KeyValueConsumer<AttributeValue>() {
|
||||
@Override
|
||||
public void consume(String key, AttributeValue value) {
|
||||
assertThat(attributes.get(key)).isEqualTo(value);
|
||||
}
|
||||
});
|
||||
spanDataAttributes.forEach((key, value) -> assertThat(attributes.get(key)).isEqualTo(value));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -682,13 +675,7 @@ public class RecordEventsReadableSpanTest {
|
|||
Resource resource = this.resource;
|
||||
Attributes attributes = TestUtils.generateRandomAttributes();
|
||||
final AttributesMap attributesWithCapacity = new AttributesMap(32);
|
||||
attributes.forEach(
|
||||
new KeyValueConsumer<AttributeValue>() {
|
||||
@Override
|
||||
public void consume(String key, AttributeValue value) {
|
||||
attributesWithCapacity.put(key, value);
|
||||
}
|
||||
});
|
||||
attributes.forEach((key, value) -> attributesWithCapacity.put(key, value));
|
||||
Attributes event1Attributes = TestUtils.generateRandomAttributes();
|
||||
Attributes event2Attributes = TestUtils.generateRandomAttributes();
|
||||
SpanContext context =
|
||||
|
|
@ -708,7 +695,7 @@ public class RecordEventsReadableSpanTest {
|
|||
clock,
|
||||
resource,
|
||||
attributesWithCapacity,
|
||||
Collections.<io.opentelemetry.trace.Link>singletonList(link1),
|
||||
Collections.singletonList(link1),
|
||||
1,
|
||||
0);
|
||||
long startEpochNanos = clock.now();
|
||||
|
|
@ -724,7 +711,7 @@ public class RecordEventsReadableSpanTest {
|
|||
long endEpochNanos = clock.now();
|
||||
|
||||
List<Event> events =
|
||||
Arrays.<Event>asList(
|
||||
Arrays.asList(
|
||||
TimedEvent.create(
|
||||
firstEventEpochNanos, "event1", event1Attributes, event1Attributes.size()),
|
||||
TimedEvent.create(
|
||||
|
|
@ -735,7 +722,7 @@ public class RecordEventsReadableSpanTest {
|
|||
result,
|
||||
attributesWithCapacity,
|
||||
events,
|
||||
Collections.<io.opentelemetry.trace.Link>singletonList(link1),
|
||||
Collections.singletonList(link1),
|
||||
name,
|
||||
startEpochNanos,
|
||||
endEpochNanos,
|
||||
|
|
@ -751,12 +738,9 @@ public class RecordEventsReadableSpanTest {
|
|||
ExecutorService es = Executors.newSingleThreadExecutor();
|
||||
Future<?> modifierFuture =
|
||||
es.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (int i = 0; i < 5096 * 5; ++i) {
|
||||
span.setAttribute("hey" + i, "");
|
||||
}
|
||||
() -> {
|
||||
for (int i = 0; i < 5096 * 5; ++i) {
|
||||
span.setAttribute("hey" + i, "");
|
||||
}
|
||||
});
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ package io.opentelemetry.sdk.trace;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static io.opentelemetry.common.AttributeValue.doubleAttributeValue;
|
||||
|
||||
import com.google.common.truth.Truth;
|
||||
import io.opentelemetry.common.AttributeValue;
|
||||
import io.opentelemetry.common.Attributes;
|
||||
import io.opentelemetry.sdk.trace.Sampler.Decision;
|
||||
|
|
@ -59,20 +58,20 @@ public class SamplersTest {
|
|||
|
||||
@Test
|
||||
public void emptySamplingDecision() {
|
||||
Truth.assertThat(Samplers.emptyDecision(true)).isSameInstanceAs(Samplers.emptyDecision(true));
|
||||
Truth.assertThat(Samplers.emptyDecision(false)).isSameInstanceAs(Samplers.emptyDecision(false));
|
||||
assertThat(Samplers.emptyDecision(true)).isSameInstanceAs(Samplers.emptyDecision(true));
|
||||
assertThat(Samplers.emptyDecision(false)).isSameInstanceAs(Samplers.emptyDecision(false));
|
||||
|
||||
Truth.assertThat(Samplers.emptyDecision(true).isSampled()).isTrue();
|
||||
Truth.assertThat(Samplers.emptyDecision(true).getAttributes().isEmpty()).isTrue();
|
||||
Truth.assertThat(Samplers.emptyDecision(false).isSampled()).isFalse();
|
||||
Truth.assertThat(Samplers.emptyDecision(false).getAttributes().isEmpty()).isTrue();
|
||||
assertThat(Samplers.emptyDecision(true).isSampled()).isTrue();
|
||||
assertThat(Samplers.emptyDecision(true).getAttributes().isEmpty()).isTrue();
|
||||
assertThat(Samplers.emptyDecision(false).isSampled()).isFalse();
|
||||
assertThat(Samplers.emptyDecision(false).getAttributes().isEmpty()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void samplingDecisionEmpty() {
|
||||
Truth.assertThat(Samplers.decision(/*isSampled=*/ true, Attributes.empty()))
|
||||
assertThat(Samplers.decision(/*isSampled=*/ true, Attributes.empty()))
|
||||
.isSameInstanceAs(Samplers.emptyDecision(true));
|
||||
Truth.assertThat(Samplers.decision(/*isSampled=*/ false, Attributes.empty()))
|
||||
assertThat(Samplers.decision(/*isSampled=*/ false, Attributes.empty()))
|
||||
.isSameInstanceAs(Samplers.emptyDecision(false));
|
||||
}
|
||||
|
||||
|
|
@ -83,18 +82,18 @@ public class SamplersTest {
|
|||
"foo", AttributeValue.longAttributeValue(42),
|
||||
"bar", AttributeValue.stringAttributeValue("baz"));
|
||||
final Decision sampledDecision = Samplers.decision(/*isSampled=*/ true, attrs);
|
||||
Truth.assertThat(sampledDecision.isSampled()).isTrue();
|
||||
Truth.assertThat(sampledDecision.getAttributes()).isEqualTo(attrs);
|
||||
assertThat(sampledDecision.isSampled()).isTrue();
|
||||
assertThat(sampledDecision.getAttributes()).isEqualTo(attrs);
|
||||
|
||||
final Decision notSampledDecision = Samplers.decision(/*isSampled=*/ false, attrs);
|
||||
Truth.assertThat(notSampledDecision.isSampled()).isFalse();
|
||||
Truth.assertThat(notSampledDecision.getAttributes()).isEqualTo(attrs);
|
||||
assertThat(notSampledDecision.isSampled()).isFalse();
|
||||
assertThat(notSampledDecision.getAttributes()).isEqualTo(attrs);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void alwaysOnSampler() {
|
||||
// Sampled parent.
|
||||
Truth.assertThat(
|
||||
assertThat(
|
||||
Samplers.alwaysOn()
|
||||
.shouldSample(
|
||||
sampledSpanContext,
|
||||
|
|
@ -102,12 +101,12 @@ public class SamplersTest {
|
|||
SPAN_NAME,
|
||||
SPAN_KIND,
|
||||
Attributes.empty(),
|
||||
Collections.<io.opentelemetry.trace.Link>emptyList())
|
||||
Collections.emptyList())
|
||||
.isSampled())
|
||||
.isTrue();
|
||||
|
||||
// Not sampled parent.
|
||||
Truth.assertThat(
|
||||
assertThat(
|
||||
Samplers.alwaysOn()
|
||||
.shouldSample(
|
||||
notSampledSpanContext,
|
||||
|
|
@ -115,12 +114,12 @@ public class SamplersTest {
|
|||
SPAN_NAME,
|
||||
SPAN_KIND,
|
||||
Attributes.empty(),
|
||||
Collections.<io.opentelemetry.trace.Link>emptyList())
|
||||
Collections.emptyList())
|
||||
.isSampled())
|
||||
.isTrue();
|
||||
|
||||
// Null parent.
|
||||
Truth.assertThat(
|
||||
assertThat(
|
||||
Samplers.alwaysOn()
|
||||
.shouldSample(
|
||||
null,
|
||||
|
|
@ -128,20 +127,20 @@ public class SamplersTest {
|
|||
SPAN_NAME,
|
||||
SPAN_KIND,
|
||||
Attributes.empty(),
|
||||
Collections.<io.opentelemetry.trace.Link>emptyList())
|
||||
Collections.emptyList())
|
||||
.isSampled())
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void alwaysOnSampler_GetDescription() {
|
||||
Truth.assertThat(Samplers.alwaysOn().getDescription()).isEqualTo("AlwaysOnSampler");
|
||||
assertThat(Samplers.alwaysOn().getDescription()).isEqualTo("AlwaysOnSampler");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void alwaysOffSampler() {
|
||||
// Sampled parent.
|
||||
Truth.assertThat(
|
||||
assertThat(
|
||||
Samplers.alwaysOff()
|
||||
.shouldSample(
|
||||
sampledSpanContext,
|
||||
|
|
@ -149,12 +148,12 @@ public class SamplersTest {
|
|||
SPAN_NAME,
|
||||
SPAN_KIND,
|
||||
Attributes.empty(),
|
||||
Collections.<io.opentelemetry.trace.Link>emptyList())
|
||||
Collections.emptyList())
|
||||
.isSampled())
|
||||
.isFalse();
|
||||
|
||||
// Not sampled parent.
|
||||
Truth.assertThat(
|
||||
assertThat(
|
||||
Samplers.alwaysOff()
|
||||
.shouldSample(
|
||||
notSampledSpanContext,
|
||||
|
|
@ -162,12 +161,12 @@ public class SamplersTest {
|
|||
SPAN_NAME,
|
||||
SPAN_KIND,
|
||||
Attributes.empty(),
|
||||
Collections.<io.opentelemetry.trace.Link>emptyList())
|
||||
Collections.emptyList())
|
||||
.isSampled())
|
||||
.isFalse();
|
||||
|
||||
// Null parent.
|
||||
Truth.assertThat(
|
||||
assertThat(
|
||||
Samplers.alwaysOff()
|
||||
.shouldSample(
|
||||
null,
|
||||
|
|
@ -175,14 +174,14 @@ public class SamplersTest {
|
|||
SPAN_NAME,
|
||||
SPAN_KIND,
|
||||
Attributes.empty(),
|
||||
Collections.<io.opentelemetry.trace.Link>emptyList())
|
||||
Collections.emptyList())
|
||||
.isSampled())
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void alwaysOffSampler_GetDescription() {
|
||||
Truth.assertThat(Samplers.alwaysOff().getDescription()).isEqualTo("AlwaysOffSampler");
|
||||
assertThat(Samplers.alwaysOff().getDescription()).isEqualTo("AlwaysOffSampler");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -245,44 +244,26 @@ public class SamplersTest {
|
|||
public void probabilitySampler_DifferentProbabilities_NotSampledParent() {
|
||||
final Sampler fiftyPercentSample = Samplers.Probability.create(0.5);
|
||||
assertSamplerSamplesWithProbability(
|
||||
fiftyPercentSample,
|
||||
notSampledSpanContext,
|
||||
Collections.<io.opentelemetry.trace.Link>emptyList(),
|
||||
0.5);
|
||||
fiftyPercentSample, notSampledSpanContext, Collections.emptyList(), 0.5);
|
||||
final Sampler twentyPercentSample = Samplers.Probability.create(0.2);
|
||||
assertSamplerSamplesWithProbability(
|
||||
twentyPercentSample,
|
||||
notSampledSpanContext,
|
||||
Collections.<io.opentelemetry.trace.Link>emptyList(),
|
||||
0.2);
|
||||
twentyPercentSample, notSampledSpanContext, Collections.emptyList(), 0.2);
|
||||
final Sampler twoThirdsSample = Samplers.Probability.create(2.0 / 3.0);
|
||||
assertSamplerSamplesWithProbability(
|
||||
twoThirdsSample,
|
||||
notSampledSpanContext,
|
||||
Collections.<io.opentelemetry.trace.Link>emptyList(),
|
||||
2.0 / 3.0);
|
||||
twoThirdsSample, notSampledSpanContext, Collections.emptyList(), 2.0 / 3.0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void probabilitySampler_DifferentProbabilities_SampledParent() {
|
||||
final Sampler fiftyPercentSample = Samplers.Probability.create(0.5);
|
||||
assertSamplerSamplesWithProbability(
|
||||
fiftyPercentSample,
|
||||
sampledSpanContext,
|
||||
Collections.<io.opentelemetry.trace.Link>emptyList(),
|
||||
1.0);
|
||||
fiftyPercentSample, sampledSpanContext, Collections.emptyList(), 1.0);
|
||||
final Sampler twentyPercentSample = Samplers.Probability.create(0.2);
|
||||
assertSamplerSamplesWithProbability(
|
||||
twentyPercentSample,
|
||||
sampledSpanContext,
|
||||
Collections.<io.opentelemetry.trace.Link>emptyList(),
|
||||
1.0);
|
||||
twentyPercentSample, sampledSpanContext, Collections.emptyList(), 1.0);
|
||||
final Sampler twoThirdsSample = Samplers.Probability.create(2.0 / 3.0);
|
||||
assertSamplerSamplesWithProbability(
|
||||
twoThirdsSample,
|
||||
sampledSpanContext,
|
||||
Collections.<io.opentelemetry.trace.Link>emptyList(),
|
||||
1.0);
|
||||
twoThirdsSample, sampledSpanContext, Collections.emptyList(), 1.0);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -337,7 +318,7 @@ public class SamplersTest {
|
|||
SPAN_NAME,
|
||||
SPAN_KIND,
|
||||
Attributes.empty(),
|
||||
Collections.<io.opentelemetry.trace.Link>emptyList());
|
||||
Collections.emptyList());
|
||||
assertThat(decision1.isSampled()).isFalse();
|
||||
assertThat(decision1.getAttributes())
|
||||
.isEqualTo(
|
||||
|
|
@ -372,7 +353,7 @@ public class SamplersTest {
|
|||
SPAN_NAME,
|
||||
SPAN_KIND,
|
||||
Attributes.empty(),
|
||||
Collections.<io.opentelemetry.trace.Link>emptyList());
|
||||
Collections.emptyList());
|
||||
assertThat(decision2.isSampled()).isTrue();
|
||||
assertThat(decision1.getAttributes())
|
||||
.isEqualTo(
|
||||
|
|
|
|||
|
|
@ -42,16 +42,13 @@ abstract class StressTestRunner {
|
|||
for (final Operation operation : operations) {
|
||||
operationThreads.add(
|
||||
new Thread(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (int i = 0; i < operation.getNumOperations(); i++) {
|
||||
operation.getUpdater().update();
|
||||
Uninterruptibles.sleepUninterruptibly(
|
||||
operation.getOperationDelayMs(), TimeUnit.MILLISECONDS);
|
||||
}
|
||||
countDownLatch.countDown();
|
||||
() -> {
|
||||
for (int i = 0; i < operation.getNumOperations(); i++) {
|
||||
operation.getUpdater().update();
|
||||
Uninterruptibles.sleepUninterruptibly(
|
||||
operation.getOperationDelayMs(), TimeUnit.MILLISECONDS);
|
||||
}
|
||||
countDownLatch.countDown();
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -78,11 +78,7 @@ public final class TestUtils {
|
|||
public static Span.Builder startSpanWithSampler(
|
||||
TracerSdkProvider tracerSdkFactory, Tracer tracer, String spanName, Sampler sampler) {
|
||||
return startSpanWithSampler(
|
||||
tracerSdkFactory,
|
||||
tracer,
|
||||
spanName,
|
||||
sampler,
|
||||
Collections.<String, AttributeValue>emptyMap());
|
||||
tracerSdkFactory, tracer, spanName, sampler, Collections.emptyMap());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ package io.opentelemetry.sdk.trace.export;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
|
||||
import io.opentelemetry.sdk.common.export.ConfigBuilder;
|
||||
import io.opentelemetry.sdk.common.export.ConfigBuilderTest.ConfigTester;
|
||||
import io.opentelemetry.sdk.trace.ReadableSpan;
|
||||
import io.opentelemetry.sdk.trace.Samplers;
|
||||
|
|
@ -60,17 +59,6 @@ public class BatchSpanProcessorTest {
|
|||
private final BlockingSpanExporter blockingSpanExporter = new BlockingSpanExporter();
|
||||
@Mock private SpanExporter mockServiceHandler;
|
||||
|
||||
abstract static class ConfigTest<T> extends ConfigBuilder<T> {
|
||||
|
||||
public static ConfigBuilder.NamingConvention getDot() {
|
||||
return NamingConvention.DOT;
|
||||
}
|
||||
|
||||
public static ConfigBuilder.NamingConvention getEnv() {
|
||||
return NamingConvention.ENV_VAR;
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
|
@ -127,7 +115,7 @@ public class BatchSpanProcessorTest {
|
|||
public void configTest_EmptyOptions() {
|
||||
BatchSpanProcessor.Builder config =
|
||||
BatchSpanProcessor.newBuilder(new WaitingSpanExporter(0))
|
||||
.fromConfigMap(Collections.<String, String>emptyMap(), ConfigTester.getNamingDot());
|
||||
.fromConfigMap(Collections.emptyMap(), ConfigTester.getNamingDot());
|
||||
assertThat(config.getScheduleDelayMillis())
|
||||
.isEqualTo(BatchSpanProcessor.Builder.DEFAULT_SCHEDULE_DELAY_MILLIS);
|
||||
assertThat(config.getMaxQueueSize())
|
||||
|
|
@ -220,8 +208,7 @@ public class BatchSpanProcessorTest {
|
|||
WaitingSpanExporter waitingSpanExporter2 = new WaitingSpanExporter(2);
|
||||
tracerSdkFactory.addSpanProcessor(
|
||||
BatchSpanProcessor.newBuilder(
|
||||
MultiSpanExporter.create(
|
||||
Arrays.<SpanExporter>asList(waitingSpanExporter, waitingSpanExporter2)))
|
||||
MultiSpanExporter.create(Arrays.asList(waitingSpanExporter, waitingSpanExporter2)))
|
||||
.setScheduleDelayMillis(MAX_SCHEDULE_DELAY_MILLIS)
|
||||
.build());
|
||||
|
||||
|
|
@ -300,7 +287,7 @@ public class BatchSpanProcessorTest {
|
|||
WaitingSpanExporter waitingSpanExporter = new WaitingSpanExporter(1);
|
||||
doThrow(new IllegalArgumentException("No export for you."))
|
||||
.when(mockServiceHandler)
|
||||
.export(ArgumentMatchers.<SpanData>anyList());
|
||||
.export(ArgumentMatchers.anyList());
|
||||
tracerSdkFactory.addSpanProcessor(
|
||||
BatchSpanProcessor.newBuilder(
|
||||
MultiSpanExporter.create(Arrays.asList(mockServiceHandler, waitingSpanExporter)))
|
||||
|
|
|
|||
|
|
@ -51,8 +51,7 @@ public class MultiSpanExporterTest {
|
|||
|
||||
@Test
|
||||
public void empty() {
|
||||
SpanExporter multiSpanExporter =
|
||||
MultiSpanExporter.create(Collections.<SpanExporter>emptyList());
|
||||
SpanExporter multiSpanExporter = MultiSpanExporter.create(Collections.emptyList());
|
||||
multiSpanExporter.export(SPAN_LIST);
|
||||
multiSpanExporter.shutdown();
|
||||
}
|
||||
|
|
@ -121,7 +120,7 @@ public class MultiSpanExporterTest {
|
|||
|
||||
doThrow(new IllegalArgumentException("No export for you."))
|
||||
.when(spanExporter1)
|
||||
.export(ArgumentMatchers.<SpanData>anyList());
|
||||
.export(ArgumentMatchers.anyList());
|
||||
when(spanExporter2.export(same(SPAN_LIST))).thenReturn(ResultCode.SUCCESS);
|
||||
assertThat(multiSpanExporter.export(SPAN_LIST)).isEqualTo(ResultCode.FAILURE);
|
||||
verify(spanExporter1).export(same(SPAN_LIST));
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ public class SimpleSpanProcessorTest {
|
|||
public void configTest_EmptyOptions() {
|
||||
SimpleSpanProcessor.Builder config =
|
||||
SimpleSpanProcessor.newBuilder(spanExporter)
|
||||
.fromConfigMap(Collections.<String, String>emptyMap(), ConfigTester.getNamingDot());
|
||||
.fromConfigMap(Collections.emptyMap(), ConfigTester.getNamingDot());
|
||||
assertThat(config.getExportOnlySampled())
|
||||
.isEqualTo(SimpleSpanProcessor.Builder.DEFAULT_EXPORT_ONLY_SAMPLED);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -237,7 +237,7 @@ public class DisruptorAsyncSpanProcessorTest {
|
|||
DisruptorAsyncSpanProcessor disruptorAsyncSpanProcessor =
|
||||
DisruptorAsyncSpanProcessor.newBuilder(
|
||||
MultiSpanProcessor.create(
|
||||
Arrays.<SpanProcessor>asList(incrementSpanProcessor1, incrementSpanProcessor2)))
|
||||
Arrays.asList(incrementSpanProcessor1, incrementSpanProcessor2)))
|
||||
.build();
|
||||
disruptorAsyncSpanProcessor.onStart(readableSpan);
|
||||
disruptorAsyncSpanProcessor.onEnd(readableSpan);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import static org.mockito.Mockito.verify;
|
|||
import io.grpc.ManagedChannel;
|
||||
import io.grpc.inprocess.InProcessChannelBuilder;
|
||||
import io.grpc.inprocess.InProcessServerBuilder;
|
||||
import io.grpc.stub.StreamObserver;
|
||||
import io.grpc.testing.GrpcCleanupRule;
|
||||
import io.opentelemetry.exporters.jaeger.proto.api_v2.Sampling;
|
||||
import io.opentelemetry.exporters.jaeger.proto.api_v2.Sampling.RateLimitingSamplingStrategy;
|
||||
|
|
@ -111,10 +110,7 @@ public class JaegerRemoteSamplerTest {
|
|||
.until(samplerIsType(sampler, RateLimitingSampler.class));
|
||||
|
||||
// verify
|
||||
verify(service)
|
||||
.getSamplingStrategy(
|
||||
requestCaptor.capture(),
|
||||
ArgumentMatchers.<StreamObserver<SamplingStrategyResponse>>any());
|
||||
verify(service).getSamplingStrategy(requestCaptor.capture(), ArgumentMatchers.any());
|
||||
Assert.assertEquals(SERVICE_NAME, requestCaptor.getValue().getServiceName());
|
||||
Assert.assertTrue(sampler.getSampler() instanceof RateLimitingSampler);
|
||||
Assert.assertEquals(
|
||||
|
|
@ -137,11 +133,6 @@ public class JaegerRemoteSamplerTest {
|
|||
|
||||
static Callable<Boolean> samplerIsType(
|
||||
final JaegerRemoteSampler sampler, final Class<? extends Sampler> expected) {
|
||||
return new Callable<Boolean>() {
|
||||
@Override
|
||||
public Boolean call() {
|
||||
return sampler.getSampler().getClass().equals(expected);
|
||||
}
|
||||
};
|
||||
return () -> sampler.getSampler().getClass().equals(expected);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -186,13 +186,10 @@ public class RateLimiterTest {
|
|||
for (int w = 0; w < numWorkers; ++w) {
|
||||
Future<?> future =
|
||||
executorService.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (int i = 0; i < creditsPerWorker * 2; ++i) {
|
||||
if (limiter.checkCredit(1)) {
|
||||
count.getAndIncrement(); // count allowed operations
|
||||
}
|
||||
() -> {
|
||||
for (int i = 0; i < creditsPerWorker * 2; ++i) {
|
||||
if (limiter.checkCredit(1)) {
|
||||
count.getAndIncrement(); // count allowed operations
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ import static org.junit.Assert.assertTrue;
|
|||
import io.opentelemetry.common.AttributeValue;
|
||||
import io.opentelemetry.common.Attributes;
|
||||
import io.opentelemetry.sdk.trace.Sampler.Decision;
|
||||
import io.opentelemetry.trace.Link;
|
||||
import io.opentelemetry.trace.Span;
|
||||
import io.opentelemetry.trace.SpanContext;
|
||||
import io.opentelemetry.trace.SpanId;
|
||||
|
|
@ -60,7 +59,7 @@ public class RateLimitingSamplerTest {
|
|||
SPAN_NAME,
|
||||
SPAN_KIND,
|
||||
Attributes.empty(),
|
||||
Collections.<Link>emptyList())
|
||||
Collections.emptyList())
|
||||
.isSampled());
|
||||
assertTrue(
|
||||
sampler
|
||||
|
|
@ -70,7 +69,7 @@ public class RateLimitingSamplerTest {
|
|||
SPAN_NAME,
|
||||
SPAN_KIND,
|
||||
Attributes.empty(),
|
||||
Collections.<Link>emptyList())
|
||||
Collections.emptyList())
|
||||
.isSampled());
|
||||
}
|
||||
|
||||
|
|
@ -84,7 +83,7 @@ public class RateLimitingSamplerTest {
|
|||
SPAN_NAME,
|
||||
SPAN_KIND,
|
||||
Attributes.empty(),
|
||||
Collections.<Link>emptyList());
|
||||
Collections.emptyList());
|
||||
assertTrue(decision.isSampled());
|
||||
assertFalse(
|
||||
sampler
|
||||
|
|
@ -94,7 +93,7 @@ public class RateLimitingSamplerTest {
|
|||
SPAN_NAME,
|
||||
SPAN_KIND,
|
||||
Attributes.empty(),
|
||||
Collections.<Link>emptyList())
|
||||
Collections.emptyList())
|
||||
.isSampled());
|
||||
assertEquals(2, decision.getAttributes().size());
|
||||
assertEquals(
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ import io.opentelemetry.sdk.trace.data.SpanData;
|
|||
import io.opentelemetry.trace.Span.Kind;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Callable;
|
||||
|
|
@ -36,12 +35,7 @@ public final class TestUtils {
|
|||
|
||||
/** Returns the number of finished {@code Span}s in the specified {@code InMemorySpanExporter}. */
|
||||
public static Callable<Integer> finishedSpansSize(final InMemorySpanExporter tracer) {
|
||||
return new Callable<Integer>() {
|
||||
@Override
|
||||
public Integer call() {
|
||||
return tracer.getFinishedSpanItems().size();
|
||||
}
|
||||
};
|
||||
return () -> tracer.getFinishedSpanItems().size();
|
||||
}
|
||||
|
||||
/** Returns a {@code List} with the {@code Span} matching the specified attribute. */
|
||||
|
|
@ -49,34 +43,31 @@ public final class TestUtils {
|
|||
List<SpanData> spans, final String key, final Object value) {
|
||||
return getByCondition(
|
||||
spans,
|
||||
new Condition() {
|
||||
@Override
|
||||
public boolean check(SpanData span) {
|
||||
AttributeValue attrValue = span.getAttributes().get(key);
|
||||
if (attrValue == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (attrValue.getType()) {
|
||||
case BOOLEAN:
|
||||
return value.equals(attrValue.getBooleanValue());
|
||||
case STRING:
|
||||
return value.equals(attrValue.getStringValue());
|
||||
case DOUBLE:
|
||||
return value.equals(attrValue.getDoubleValue());
|
||||
case LONG:
|
||||
return value.equals(attrValue.getLongValue());
|
||||
case STRING_ARRAY:
|
||||
return value.equals(attrValue.getStringArrayValue());
|
||||
case LONG_ARRAY:
|
||||
return value.equals(attrValue.getLongArrayValue());
|
||||
case BOOLEAN_ARRAY:
|
||||
return value.equals(attrValue.getBooleanArrayValue());
|
||||
case DOUBLE_ARRAY:
|
||||
return value.equals(attrValue.getDoubleArrayValue());
|
||||
}
|
||||
span -> {
|
||||
AttributeValue attrValue = span.getAttributes().get(key);
|
||||
if (attrValue == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (attrValue.getType()) {
|
||||
case BOOLEAN:
|
||||
return value.equals(attrValue.getBooleanValue());
|
||||
case STRING:
|
||||
return value.equals(attrValue.getStringValue());
|
||||
case DOUBLE:
|
||||
return value.equals(attrValue.getDoubleValue());
|
||||
case LONG:
|
||||
return value.equals(attrValue.getLongValue());
|
||||
case STRING_ARRAY:
|
||||
return value.equals(attrValue.getStringArrayValue());
|
||||
case LONG_ARRAY:
|
||||
return value.equals(attrValue.getLongArrayValue());
|
||||
case BOOLEAN_ARRAY:
|
||||
return value.equals(attrValue.getBooleanArrayValue());
|
||||
case DOUBLE_ARRAY:
|
||||
return value.equals(attrValue.getDoubleArrayValue());
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -97,14 +88,7 @@ public final class TestUtils {
|
|||
|
||||
/** Returns a {@code List} with the {@code Span} matching the specified kind. */
|
||||
public static List<SpanData> getByKind(List<SpanData> spans, final Kind kind) {
|
||||
return getByCondition(
|
||||
spans,
|
||||
new Condition() {
|
||||
@Override
|
||||
public boolean check(SpanData span) {
|
||||
return span.getKind() == kind;
|
||||
}
|
||||
});
|
||||
return getByCondition(spans, span -> span.getKind() == kind);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -124,14 +108,7 @@ public final class TestUtils {
|
|||
|
||||
/** Returns a {@code List} with the {@code Span} matching the specified name. */
|
||||
private static List<SpanData> getByName(List<SpanData> spans, final String name) {
|
||||
return getByCondition(
|
||||
spans,
|
||||
new Condition() {
|
||||
@Override
|
||||
public boolean check(SpanData span) {
|
||||
return span.getName().equals(name);
|
||||
}
|
||||
});
|
||||
return getByCondition(spans, span -> span.getName().equals(name));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -191,13 +168,7 @@ public final class TestUtils {
|
|||
public static List<SpanData> sortByStartTime(List<SpanData> spans) {
|
||||
List<SpanData> sortedSpans = new ArrayList<>(spans);
|
||||
Collections.sort(
|
||||
sortedSpans,
|
||||
new Comparator<SpanData>() {
|
||||
@Override
|
||||
public int compare(SpanData o1, SpanData o2) {
|
||||
return Long.compare(o1.getStartEpochNanos(), o2.getStartEpochNanos());
|
||||
}
|
||||
});
|
||||
sortedSpans, (o1, o2) -> Long.compare(o1.getStartEpochNanos(), o2.getStartEpochNanos()));
|
||||
return sortedSpans;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -78,31 +78,28 @@ public class ActiveSpanReplacementTest {
|
|||
private void submitAnotherTask(final Span initialSpan) {
|
||||
|
||||
executor.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Create a new Span for this task
|
||||
Span taskSpan = tracer.spanBuilder("task").startSpan();
|
||||
try (Scope scope = tracer.withSpan(taskSpan)) {
|
||||
() -> {
|
||||
// Create a new Span for this task
|
||||
Span taskSpan = tracer.spanBuilder("task").startSpan();
|
||||
try (Scope scope = tracer.withSpan(taskSpan)) {
|
||||
|
||||
// Simulate work strictly related to the initial Span
|
||||
// and finish it.
|
||||
try (Scope initialScope = tracer.withSpan(initialSpan)) {
|
||||
sleep(50);
|
||||
} finally {
|
||||
initialSpan.end();
|
||||
}
|
||||
|
||||
// Restore the span for this task and create a subspan
|
||||
Span subTaskSpan = tracer.spanBuilder("subtask").startSpan();
|
||||
try (Scope subTaskScope = tracer.withSpan(subTaskSpan)) {
|
||||
sleep(50);
|
||||
} finally {
|
||||
subTaskSpan.end();
|
||||
}
|
||||
// Simulate work strictly related to the initial Span
|
||||
// and finish it.
|
||||
try (Scope initialScope = tracer.withSpan(initialSpan)) {
|
||||
sleep(50);
|
||||
} finally {
|
||||
taskSpan.end();
|
||||
initialSpan.end();
|
||||
}
|
||||
|
||||
// Restore the span for this task and create a subspan
|
||||
Span subTaskSpan = tracer.spanBuilder("subtask").startSpan();
|
||||
try (Scope subTaskScope = tracer.withSpan(subTaskSpan)) {
|
||||
sleep(50);
|
||||
} finally {
|
||||
subTaskSpan.end();
|
||||
}
|
||||
} finally {
|
||||
taskSpan.end();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import io.opentelemetry.context.Scope;
|
|||
import io.opentelemetry.trace.Span;
|
||||
import io.opentelemetry.trace.Span.Kind;
|
||||
import io.opentelemetry.trace.Tracer;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
|
@ -48,26 +47,23 @@ final class Actor implements AutoCloseable {
|
|||
final Span parent = tracer.getCurrentSpan();
|
||||
phaser.register();
|
||||
return executor.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Span child =
|
||||
tracer
|
||||
.spanBuilder("received")
|
||||
.setParent(parent)
|
||||
.setSpanKind(Kind.CONSUMER)
|
||||
.startSpan();
|
||||
try (Scope ignored = tracer.withSpan(child)) {
|
||||
phaser.arriveAndAwaitAdvance(); // child tracer started
|
||||
child.addEvent("received " + message);
|
||||
phaser.arriveAndAwaitAdvance(); // assert size
|
||||
} finally {
|
||||
child.end();
|
||||
}
|
||||
|
||||
phaser.arriveAndAwaitAdvance(); // child tracer finished
|
||||
() -> {
|
||||
Span child =
|
||||
tracer
|
||||
.spanBuilder("received")
|
||||
.setParent(parent)
|
||||
.setSpanKind(Kind.CONSUMER)
|
||||
.startSpan();
|
||||
try (Scope ignored = tracer.withSpan(child)) {
|
||||
phaser.arriveAndAwaitAdvance(); // child tracer started
|
||||
child.addEvent("received " + message);
|
||||
phaser.arriveAndAwaitAdvance(); // assert size
|
||||
} finally {
|
||||
child.end();
|
||||
}
|
||||
|
||||
phaser.arriveAndAwaitAdvance(); // child tracer finished
|
||||
phaser.arriveAndAwaitAdvance(); // assert size
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -75,24 +71,21 @@ final class Actor implements AutoCloseable {
|
|||
final Span parent = tracer.getCurrentSpan();
|
||||
phaser.register();
|
||||
return executor.submit(
|
||||
new Callable<String>() {
|
||||
@Override
|
||||
public String call() {
|
||||
Span span =
|
||||
tracer
|
||||
.spanBuilder("received")
|
||||
.setParent(parent)
|
||||
.setSpanKind(Kind.CONSUMER)
|
||||
.startSpan();
|
||||
try {
|
||||
phaser.arriveAndAwaitAdvance(); // child tracer started
|
||||
phaser.arriveAndAwaitAdvance(); // assert size
|
||||
return "received " + message;
|
||||
} finally {
|
||||
span.end();
|
||||
phaser.arriveAndAwaitAdvance(); // child tracer finished
|
||||
phaser.arriveAndAwaitAdvance(); // assert size
|
||||
}
|
||||
() -> {
|
||||
Span span =
|
||||
tracer
|
||||
.spanBuilder("received")
|
||||
.setParent(parent)
|
||||
.setSpanKind(Kind.CONSUMER)
|
||||
.startSpan();
|
||||
try {
|
||||
phaser.arriveAndAwaitAdvance(); // child tracer started
|
||||
phaser.arriveAndAwaitAdvance(); // assert size
|
||||
return "received " + message;
|
||||
} finally {
|
||||
span.end();
|
||||
phaser.arriveAndAwaitAdvance(); // child tracer finished
|
||||
phaser.arriveAndAwaitAdvance(); // assert size
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ package io.opentelemetry.sdk.extensions.trace.testbed.clientserver;
|
|||
import io.grpc.Context;
|
||||
import io.opentelemetry.OpenTelemetry;
|
||||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.context.propagation.HttpTextFormat.Setter;
|
||||
import io.opentelemetry.trace.Span;
|
||||
import io.opentelemetry.trace.Span.Kind;
|
||||
import io.opentelemetry.trace.Tracer;
|
||||
|
|
@ -44,15 +43,7 @@ final class Client {
|
|||
try (Scope ignored = tracer.withSpan(span)) {
|
||||
OpenTelemetry.getPropagators()
|
||||
.getHttpTextFormat()
|
||||
.inject(
|
||||
Context.current(),
|
||||
message,
|
||||
new Setter<Message>() {
|
||||
@Override
|
||||
public void set(Message carrier, String key, String value) {
|
||||
carrier.put(key, value);
|
||||
}
|
||||
});
|
||||
.inject(Context.current(), message, (carrier, key, value) -> carrier.put(key, value));
|
||||
queue.put(message);
|
||||
} finally {
|
||||
span.end();
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
package io.opentelemetry.sdk.extensions.trace.testbed.concurrentcommonrequesthandler;
|
||||
|
||||
import io.opentelemetry.sdk.extensions.trace.testbed.TestUtils;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
|
@ -34,34 +33,25 @@ final class Client {
|
|||
public Future<String> send(final Object message) {
|
||||
final Context context = new Context();
|
||||
return executor.submit(
|
||||
new Callable<String>() {
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
TestUtils.sleep();
|
||||
executor
|
||||
.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TestUtils.sleep();
|
||||
requestHandler.beforeRequest(message, context);
|
||||
}
|
||||
})
|
||||
.get();
|
||||
() -> {
|
||||
TestUtils.sleep();
|
||||
executor
|
||||
.submit(
|
||||
() -> {
|
||||
TestUtils.sleep();
|
||||
requestHandler.beforeRequest(message, context);
|
||||
})
|
||||
.get();
|
||||
|
||||
executor
|
||||
.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
TestUtils.sleep();
|
||||
requestHandler.afterResponse(message, context);
|
||||
}
|
||||
})
|
||||
.get();
|
||||
executor
|
||||
.submit(
|
||||
() -> {
|
||||
TestUtils.sleep();
|
||||
requestHandler.afterResponse(message, context);
|
||||
})
|
||||
.get();
|
||||
|
||||
return message + ":response";
|
||||
}
|
||||
return message + ":response";
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,16 +71,13 @@ public final class ErrorReportingTest {
|
|||
public void testCallbackError() {
|
||||
final Span span = tracer.spanBuilder("one").startSpan();
|
||||
executor.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try (Scope ignored = tracer.withSpan(span)) {
|
||||
throw new RuntimeException("Invalid state");
|
||||
} catch (Exception exc) {
|
||||
span.setStatus(Status.UNKNOWN);
|
||||
} finally {
|
||||
span.end();
|
||||
}
|
||||
() -> {
|
||||
try (Scope ignored = tracer.withSpan(span)) {
|
||||
throw new RuntimeException("Invalid state");
|
||||
} catch (Exception exc) {
|
||||
span.setStatus(Status.UNKNOWN);
|
||||
} finally {
|
||||
span.end();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -135,16 +132,13 @@ public final class ErrorReportingTest {
|
|||
// ScopedRunnable captures the active Span at this time.
|
||||
executor.submit(
|
||||
new ScopedRunnable(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
throw new RuntimeException("Invalid state");
|
||||
} catch (Exception exc) {
|
||||
tracer.getCurrentSpan().setStatus(Status.UNKNOWN);
|
||||
} finally {
|
||||
tracer.getCurrentSpan().end();
|
||||
}
|
||||
() -> {
|
||||
try {
|
||||
throw new RuntimeException("Invalid state");
|
||||
} catch (Exception exc) {
|
||||
tracer.getCurrentSpan().setStatus(Status.UNKNOWN);
|
||||
} finally {
|
||||
tracer.getCurrentSpan().end();
|
||||
}
|
||||
},
|
||||
tracer));
|
||||
|
|
|
|||
|
|
@ -72,33 +72,27 @@ public final class LateSpanFinishTest {
|
|||
private void submitTasks(final Span parentSpan) {
|
||||
|
||||
executor.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
/* Alternative to calling activate() is to pass it manually to asChildOf() for each
|
||||
* created Span. */
|
||||
try (Scope scope = tracer.withSpan(parentSpan)) {
|
||||
Span childSpan = tracer.spanBuilder("task1").startSpan();
|
||||
try (Scope childScope = tracer.withSpan(childSpan)) {
|
||||
TestUtils.sleep(55);
|
||||
} finally {
|
||||
childSpan.end();
|
||||
}
|
||||
() -> {
|
||||
/* Alternative to calling activate() is to pass it manually to asChildOf() for each
|
||||
* created Span. */
|
||||
try (Scope scope = tracer.withSpan(parentSpan)) {
|
||||
Span childSpan = tracer.spanBuilder("task1").startSpan();
|
||||
try (Scope childScope = tracer.withSpan(childSpan)) {
|
||||
TestUtils.sleep(55);
|
||||
} finally {
|
||||
childSpan.end();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
executor.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try (Scope scope = tracer.withSpan(parentSpan)) {
|
||||
Span childSpan = tracer.spanBuilder("task2").startSpan();
|
||||
try (Scope childScope = tracer.withSpan(childSpan)) {
|
||||
TestUtils.sleep(85);
|
||||
} finally {
|
||||
childSpan.end();
|
||||
}
|
||||
() -> {
|
||||
try (Scope scope = tracer.withSpan(parentSpan)) {
|
||||
Span childSpan = tracer.spanBuilder("task2").startSpan();
|
||||
try (Scope childScope = tracer.withSpan(childSpan)) {
|
||||
TestUtils.sleep(85);
|
||||
} finally {
|
||||
childSpan.end();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ package io.opentelemetry.sdk.extensions.trace.testbed.listenerperrequest;
|
|||
import io.opentelemetry.trace.Span;
|
||||
import io.opentelemetry.trace.Span.Kind;
|
||||
import io.opentelemetry.trace.Tracer;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
|
@ -35,14 +34,11 @@ final class Client {
|
|||
/** Async execution. */
|
||||
private Future<Object> execute(final Object message, final ResponseListener responseListener) {
|
||||
return executor.submit(
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() {
|
||||
// send via wire and get response
|
||||
Object response = message + ":response";
|
||||
responseListener.onResponse(response);
|
||||
return response;
|
||||
}
|
||||
() -> {
|
||||
// send via wire and get response
|
||||
Object response = message + ":response";
|
||||
responseListener.onResponse(response);
|
||||
return response;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ package io.opentelemetry.sdk.extensions.trace.testbed.multiplecallbacks;
|
|||
import io.opentelemetry.context.Scope;
|
||||
import io.opentelemetry.trace.Span;
|
||||
import io.opentelemetry.trace.Tracer;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
|
@ -39,19 +38,16 @@ class Client {
|
|||
final Span parent = tracer.getCurrentSpan();
|
||||
|
||||
return executor.submit(
|
||||
new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
Span span = tracer.spanBuilder("subtask").setParent(parent).startSpan();
|
||||
try (Scope subtaskScope = tracer.withSpan(span)) {
|
||||
// Simulate work - make sure we finish *after* the parent Span.
|
||||
parentDoneLatch.await();
|
||||
} finally {
|
||||
span.end();
|
||||
}
|
||||
|
||||
return message + "::response";
|
||||
() -> {
|
||||
Span span = tracer.spanBuilder("subtask").setParent(parent).startSpan();
|
||||
try (Scope subtaskScope = tracer.withSpan(span)) {
|
||||
// Simulate work - make sure we finish *after* the parent Span.
|
||||
parentDoneLatch.await();
|
||||
} finally {
|
||||
span.end();
|
||||
}
|
||||
|
||||
return message + "::response";
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,34 +70,25 @@ public final class NestedCallbacksTest {
|
|||
private void submitCallbacks(final Span span) {
|
||||
|
||||
executor.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try (Scope ignored = tracer.withSpan(span)) {
|
||||
span.setAttribute("key1", "1");
|
||||
() -> {
|
||||
try (Scope ignored = tracer.withSpan(span)) {
|
||||
span.setAttribute("key1", "1");
|
||||
|
||||
executor.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try (Scope ignored = tracer.withSpan(span)) {
|
||||
span.setAttribute("key2", "2");
|
||||
executor.submit(
|
||||
() -> {
|
||||
try (Scope ignored12 = tracer.withSpan(span)) {
|
||||
span.setAttribute("key2", "2");
|
||||
|
||||
executor.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try (Scope ignored = tracer.withSpan(span)) {
|
||||
span.setAttribute("key3", "3");
|
||||
} finally {
|
||||
span.end();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
executor.submit(
|
||||
() -> {
|
||||
try (Scope ignored1 = tracer.withSpan(span)) {
|
||||
span.setAttribute("key3", "3");
|
||||
} finally {
|
||||
span.end();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,18 +50,15 @@ final class Promise<T> {
|
|||
void success(final T result) {
|
||||
for (final SuccessCallback<T> callback : successCallbacks) {
|
||||
context.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Span childSpan = tracer.spanBuilder("success").setParent(parentSpan).startSpan();
|
||||
childSpan.setAttribute("component", "success");
|
||||
try (Scope ignored = tracer.withSpan(childSpan)) {
|
||||
callback.accept(result);
|
||||
} finally {
|
||||
childSpan.end();
|
||||
}
|
||||
context.getPhaser().arriveAndAwaitAdvance(); // trace reported
|
||||
() -> {
|
||||
Span childSpan = tracer.spanBuilder("success").setParent(parentSpan).startSpan();
|
||||
childSpan.setAttribute("component", "success");
|
||||
try (Scope ignored = tracer.withSpan(childSpan)) {
|
||||
callback.accept(result);
|
||||
} finally {
|
||||
childSpan.end();
|
||||
}
|
||||
context.getPhaser().arriveAndAwaitAdvance(); // trace reported
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -70,18 +67,15 @@ final class Promise<T> {
|
|||
void error(final Throwable error) {
|
||||
for (final ErrorCallback callback : errorCallbacks) {
|
||||
context.submit(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Span childSpan = tracer.spanBuilder("error").setParent(parentSpan).startSpan();
|
||||
childSpan.setAttribute("component", "error");
|
||||
try (Scope ignored = tracer.withSpan(childSpan)) {
|
||||
callback.accept(error);
|
||||
} finally {
|
||||
childSpan.end();
|
||||
}
|
||||
context.getPhaser().arriveAndAwaitAdvance(); // trace reported
|
||||
() -> {
|
||||
Span childSpan = tracer.spanBuilder("error").setParent(parentSpan).startSpan();
|
||||
childSpan.setAttribute("component", "error");
|
||||
try (Scope ignored = tracer.withSpan(childSpan)) {
|
||||
callback.accept(error);
|
||||
} finally {
|
||||
childSpan.end();
|
||||
}
|
||||
context.getPhaser().arriveAndAwaitAdvance(); // trace reported
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,33 +66,24 @@ public class PromisePropagationTest {
|
|||
Promise<String> successPromise = new Promise<>(context, tracer);
|
||||
|
||||
successPromise.onSuccess(
|
||||
new Promise.SuccessCallback<String>() {
|
||||
@Override
|
||||
public void accept(String s) {
|
||||
tracer.getCurrentSpan().addEvent("Promised 1 " + s);
|
||||
successResult1.set(s);
|
||||
phaser.arriveAndAwaitAdvance(); // result set
|
||||
}
|
||||
s -> {
|
||||
tracer.getCurrentSpan().addEvent("Promised 1 " + s);
|
||||
successResult1.set(s);
|
||||
phaser.arriveAndAwaitAdvance(); // result set
|
||||
});
|
||||
successPromise.onSuccess(
|
||||
new Promise.SuccessCallback<String>() {
|
||||
@Override
|
||||
public void accept(String s) {
|
||||
tracer.getCurrentSpan().addEvent("Promised 2 " + s);
|
||||
successResult2.set(s);
|
||||
phaser.arriveAndAwaitAdvance(); // result set
|
||||
}
|
||||
s -> {
|
||||
tracer.getCurrentSpan().addEvent("Promised 2 " + s);
|
||||
successResult2.set(s);
|
||||
phaser.arriveAndAwaitAdvance(); // result set
|
||||
});
|
||||
|
||||
Promise<String> errorPromise = new Promise<>(context, tracer);
|
||||
|
||||
errorPromise.onError(
|
||||
new Promise.ErrorCallback() {
|
||||
@Override
|
||||
public void accept(Throwable t) {
|
||||
errorResult.set(t);
|
||||
phaser.arriveAndAwaitAdvance(); // result set
|
||||
}
|
||||
t -> {
|
||||
errorResult.set(t);
|
||||
phaser.arriveAndAwaitAdvance(); // result set
|
||||
});
|
||||
|
||||
assertThat(inMemoryTracing.getSpanExporter().getFinishedSpanItems().size()).isEqualTo(0);
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@
|
|||
package io.opentelemetry.sdk.extensions.trace.testbed.statelesscommonrequesthandler;
|
||||
|
||||
import io.opentelemetry.sdk.extensions.trace.testbed.TestUtils;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
|
@ -35,17 +34,14 @@ final class Client {
|
|||
public Future<String> send(final Object message) {
|
||||
|
||||
return executor.submit(
|
||||
new Callable<String>() {
|
||||
@Override
|
||||
public String call() {
|
||||
TestUtils.sleep();
|
||||
requestHandler.beforeRequest(message);
|
||||
() -> {
|
||||
TestUtils.sleep();
|
||||
requestHandler.beforeRequest(message);
|
||||
|
||||
TestUtils.sleep();
|
||||
requestHandler.afterResponse(message);
|
||||
TestUtils.sleep();
|
||||
requestHandler.afterResponse(message);
|
||||
|
||||
return message + ":response";
|
||||
}
|
||||
return message + ":response";
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue