use of io.opentelemetry.sdk.testing.time.TestClock in project opentelemetry-java by open-telemetry.
the class FixedSizeExemplarReservoirTest method noMeasurement_returnsEmpty.
@Test
public void noMeasurement_returnsEmpty() {
TestClock clock = TestClock.create();
ExemplarReservoir reservoir = new FixedSizeExemplarReservoir(clock, 1, RandomSupplier.platformDefault());
assertThat(reservoir.collectAndReset(Attributes.empty())).isEmpty();
}
use of io.opentelemetry.sdk.testing.time.TestClock in project opentelemetry-java by open-telemetry.
the class HistogramBucketExemplarReservoirTest method noMeasurement_returnsEmpty.
@Test
public void noMeasurement_returnsEmpty() {
TestClock clock = TestClock.create();
ExemplarReservoir reservoir = new HistogramBucketExemplarReservoir(clock, new double[] {});
assertThat(reservoir.collectAndReset(Attributes.empty())).isEmpty();
}
use of io.opentelemetry.sdk.testing.time.TestClock in project opentelemetry-java by open-telemetry.
the class HistogramBucketExemplarReservoirTest method oneBucket_samplesEverything.
@Test
public void oneBucket_samplesEverything() {
TestClock clock = TestClock.create();
ExemplarReservoir reservoir = new HistogramBucketExemplarReservoir(clock, new double[] {});
reservoir.offerMeasurement(1L, Attributes.empty(), Context.root());
assertThat(reservoir.collectAndReset(Attributes.empty())).hasSize(1).satisfiesExactly(exemplar -> assertThat(exemplar).hasEpochNanos(clock.now()).hasFilteredAttributes(Attributes.empty()).hasValue(1));
// Measurement count is reset, we should sample a new measurement (and only one)
clock.advance(Duration.ofSeconds(1));
reservoir.offerMeasurement(2L, Attributes.empty(), Context.root());
assertThat(reservoir.collectAndReset(Attributes.empty())).hasSize(1).satisfiesExactly(exemplar -> assertThat(exemplar).hasEpochNanos(clock.now()).hasFilteredAttributes(Attributes.empty()).hasValue(2));
// only latest measurement is kept per-bucket
clock.advance(Duration.ofSeconds(1));
reservoir.offerMeasurement(3L, Attributes.empty(), Context.root());
reservoir.offerMeasurement(4L, Attributes.empty(), Context.root());
assertThat(reservoir.collectAndReset(Attributes.empty())).hasSize(1).satisfiesExactly(exemplar -> assertThat(exemplar).hasEpochNanos(clock.now()).hasFilteredAttributes(Attributes.empty()).hasValue(4));
}
use of io.opentelemetry.sdk.testing.time.TestClock in project opentelemetry-java by open-telemetry.
the class SdkSpanTest method testAsSpanData.
@Test
void testAsSpanData() {
String name = "GreatSpan";
SpanKind kind = SpanKind.SERVER;
String traceId = this.traceId;
String spanId = this.spanId;
String parentSpanId = this.parentSpanId;
SpanLimits spanLimits = SpanLimits.getDefault();
SpanProcessor spanProcessor = NoopSpanProcessor.getInstance();
TestClock clock = TestClock.create();
Resource resource = this.resource;
Attributes attributes = TestUtils.generateRandomAttributes();
AttributesMap attributesWithCapacity = new AttributesMap(32, Integer.MAX_VALUE);
attributes.forEach((key, value) -> attributesWithCapacity.put((AttributeKey) key, value));
Attributes event1Attributes = TestUtils.generateRandomAttributes();
Attributes event2Attributes = TestUtils.generateRandomAttributes();
SpanContext context = SpanContext.create(traceId, spanId, TraceFlags.getDefault(), TraceState.getDefault());
LinkData link1 = LinkData.create(context, TestUtils.generateRandomAttributes());
SdkSpan readableSpan = SdkSpan.startSpan(context, name, instrumentationLibraryInfo, kind, parentSpanId != null ? Span.wrap(SpanContext.create(traceId, parentSpanId, TraceFlags.getDefault(), TraceState.getDefault())) : Span.getInvalid(), Context.root(), spanLimits, spanProcessor, clock, resource, attributesWithCapacity, Collections.singletonList(link1), 1, 0);
long startEpochNanos = clock.now();
clock.advance(Duration.ofMillis(4));
long firstEventEpochNanos = clock.now();
readableSpan.addEvent("event1", event1Attributes);
clock.advance(Duration.ofMillis(6));
long secondEventTimeNanos = clock.now();
readableSpan.addEvent("event2", event2Attributes);
clock.advance(Duration.ofMillis(100));
readableSpan.end();
long endEpochNanos = clock.now();
List<EventData> events = Arrays.asList(EventData.create(firstEventEpochNanos, "event1", event1Attributes, event1Attributes.size()), EventData.create(secondEventTimeNanos, "event2", event2Attributes, event2Attributes.size()));
SpanData result = readableSpan.toSpanData();
verifySpanData(result, attributesWithCapacity, events, Collections.singletonList(link1), name, startEpochNanos, endEpochNanos, StatusData.unset(), /* hasEnded= */
true);
assertThat(result.getTotalRecordedLinks()).isEqualTo(1);
assertThat(result.getSpanContext().isSampled()).isEqualTo(false);
}
use of io.opentelemetry.sdk.testing.time.TestClock in project opentelemetry-java by open-telemetry.
the class FixedSizeExemplarReservoirTest method oneMeasurement_filtersAttributes.
@Test
public void oneMeasurement_filtersAttributes() {
Attributes all = Attributes.builder().put("one", 1).put("two", "two").put("three", true).build();
Attributes partial = Attributes.builder().put("three", true).build();
Attributes remaining = Attributes.builder().put("one", 1).put("two", "two").build();
TestClock clock = TestClock.create();
ExemplarReservoir reservoir = new FixedSizeExemplarReservoir(clock, 1, RandomSupplier.platformDefault());
reservoir.offerMeasurement(1L, all, Context.root());
assertThat(reservoir.collectAndReset(partial)).satisfiesExactly(exemplar -> assertThat(exemplar).hasEpochNanos(clock.now()).hasValue(1).hasFilteredAttributes(remaining));
}
Aggregations