Search in sources :

Example 36 with Attributes

use of io.opentelemetry.api.common.Attributes in project opentelemetry-java by open-telemetry.

the class ResourceTest method testMergeResources_Resource1.

@Test
void testMergeResources_Resource1() {
    Attributes expectedAttributes = Attributes.of(stringKey("a"), "1", stringKey("b"), "2");
    Resource resource = Resource.empty().merge(resource1);
    assertThat(resource.getAttributes()).isEqualTo(expectedAttributes);
}
Also used : Attributes(io.opentelemetry.api.common.Attributes) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes) Test(org.junit.jupiter.api.Test)

Example 37 with Attributes

use of io.opentelemetry.api.common.Attributes in project opentelemetry-java by open-telemetry.

the class DoubleExponentialHistogramAggregatorTest method diffDownScaledAccumulation.

@Test
void diffDownScaledAccumulation() {
    Attributes attributes = Attributes.builder().put("test", "value").build();
    ExemplarData exemplar = DoubleExemplarData.create(attributes, 2L, SpanContext.create("00000000000000000000000000000001", "0000000000000002", TraceFlags.getDefault(), TraceState.getDefault()), 1);
    List<ExemplarData> exemplars = Collections.singletonList(exemplar);
    List<ExemplarData> previousExemplars = Collections.singletonList(DoubleExemplarData.create(attributes, 1L, SpanContext.create("00000000000000000000000000000001", "0000000000000002", TraceFlags.getDefault(), TraceState.getDefault()), 2));
    ExponentialHistogramAccumulation nextAccumulation = getTestAccumulation(exemplars, 1, 1, 100, -1, -100);
    ExponentialHistogramAccumulation previousAccumulation = getTestAccumulation(previousExemplars, 1, -1);
    // Assure most recent exemplars are kept
    ExponentialHistogramAccumulation diff = aggregator.diff(previousAccumulation, nextAccumulation);
    assertThat(diff).isEqualTo(getTestAccumulation(exemplars, 1, 100, -100));
}
Also used : DoubleExemplarData(io.opentelemetry.sdk.metrics.data.DoubleExemplarData) ExemplarData(io.opentelemetry.sdk.metrics.data.ExemplarData) Attributes(io.opentelemetry.api.common.Attributes) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 38 with Attributes

use of io.opentelemetry.api.common.Attributes in project opentelemetry-java by open-telemetry.

the class DoubleExponentialHistogramAggregatorTest method testMergeAccumulation.

@Test
void testMergeAccumulation() {
    Attributes attributes = Attributes.builder().put("test", "value").build();
    ExemplarData exemplar = DoubleExemplarData.create(attributes, 2L, SpanContext.create("00000000000000000000000000000001", "0000000000000002", TraceFlags.getDefault(), TraceState.getDefault()), 1);
    List<ExemplarData> exemplars = Collections.singletonList(exemplar);
    List<ExemplarData> previousExemplars = Collections.singletonList(DoubleExemplarData.create(attributes, 1L, SpanContext.create("00000000000000000000000000000001", "0000000000000002", TraceFlags.getDefault(), TraceState.getDefault()), 2));
    ExponentialHistogramAccumulation previousAccumulation = getTestAccumulation(previousExemplars, 0, 4.1, 100, 100, 10000, 1000000);
    ExponentialHistogramAccumulation nextAccumulation = getTestAccumulation(exemplars, -1000, -2000000, -8.2, 2.3);
    // Merged accumulations should equal accumulation with equivalent recordings and latest
    // exemplars.
    assertThat(aggregator.merge(previousAccumulation, nextAccumulation)).isEqualTo(getTestAccumulation(exemplars, 0, 4.1, 100, 100, 10000, 1000000, -1000, -2000000, -8.2, 2.3));
}
Also used : DoubleExemplarData(io.opentelemetry.sdk.metrics.data.DoubleExemplarData) ExemplarData(io.opentelemetry.sdk.metrics.data.ExemplarData) Attributes(io.opentelemetry.api.common.Attributes) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 39 with Attributes

use of io.opentelemetry.api.common.Attributes in project opentelemetry-java by open-telemetry.

the class DoubleExponentialHistogramAggregatorTest method testExemplarsInAccumulation.

@Test
void testExemplarsInAccumulation() {
    DoubleExponentialHistogramAggregator agg = new DoubleExponentialHistogramAggregator(() -> reservoir);
    Attributes attributes = Attributes.builder().put("test", "value").build();
    ExemplarData exemplar = DoubleExemplarData.create(attributes, 2L, SpanContext.create("00000000000000000000000000000001", "0000000000000002", TraceFlags.getDefault(), TraceState.getDefault()), 1);
    List<ExemplarData> exemplars = Collections.singletonList(exemplar);
    Mockito.when(reservoir.collectAndReset(Attributes.empty())).thenReturn(exemplars);
    AggregatorHandle<ExponentialHistogramAccumulation> aggregatorHandle = agg.createHandle();
    aggregatorHandle.recordDouble(0, attributes, Context.root());
    assertThat(Objects.requireNonNull(aggregatorHandle.accumulateThenReset(Attributes.empty())).getExemplars()).isEqualTo(exemplars);
}
Also used : DoubleExemplarData(io.opentelemetry.sdk.metrics.data.DoubleExemplarData) ExemplarData(io.opentelemetry.sdk.metrics.data.ExemplarData) Attributes(io.opentelemetry.api.common.Attributes) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 40 with Attributes

use of io.opentelemetry.api.common.Attributes in project opentelemetry-java by open-telemetry.

the class DoubleHistogramAggregatorTest method mergeAccumulation.

@Test
void mergeAccumulation() {
    Attributes attributes = Attributes.builder().put("test", "value").build();
    ExemplarData exemplar = DoubleExemplarData.create(attributes, 2L, SpanContext.create("00000000000000000000000000000001", "0000000000000002", TraceFlags.getDefault(), TraceState.getDefault()), 1);
    List<ExemplarData> exemplars = Collections.singletonList(exemplar);
    List<ExemplarData> previousExemplars = Collections.singletonList(DoubleExemplarData.create(attributes, 1L, SpanContext.create("00000000000000000000000000000001", "0000000000000002", TraceFlags.getDefault(), TraceState.getDefault()), 2));
    HistogramAccumulation previousAccumulation = HistogramAccumulation.create(2, new long[] { 1, 1, 0 }, previousExemplars);
    HistogramAccumulation nextAccumulation = HistogramAccumulation.create(2, new long[] { 0, 0, 2 }, exemplars);
    // Assure most recent exemplars are kept.
    assertThat(aggregator.merge(previousAccumulation, nextAccumulation)).isEqualTo(HistogramAccumulation.create(4, new long[] { 1, 1, 2 }, exemplars));
}
Also used : DoubleExemplarData(io.opentelemetry.sdk.metrics.data.DoubleExemplarData) ExemplarData(io.opentelemetry.sdk.metrics.data.ExemplarData) Attributes(io.opentelemetry.api.common.Attributes) Test(org.junit.jupiter.api.Test)

Aggregations

Attributes (io.opentelemetry.api.common.Attributes)175 Test (org.junit.jupiter.api.Test)128 ResourceAttributes (io.opentelemetry.semconv.resource.attributes.ResourceAttributes)45 Resource (io.opentelemetry.sdk.resources.Resource)33 InstrumentationLibraryInfo (io.opentelemetry.sdk.common.InstrumentationLibraryInfo)27 Context (io.opentelemetry.context.Context)25 SemanticAttributes (io.opentelemetry.semconv.trace.attributes.SemanticAttributes)24 SpanContext (io.opentelemetry.api.trace.SpanContext)22 MetricAssertions.assertThat (io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat)22 SpanData (io.opentelemetry.sdk.trace.data.SpanData)22 HashMap (java.util.HashMap)21 Duration (java.time.Duration)20 ExemplarData (io.opentelemetry.sdk.metrics.data.ExemplarData)18 InMemoryMetricReader (io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader)18 TestClock (io.opentelemetry.sdk.testing.time.TestClock)18 AttributeKey (io.opentelemetry.api.common.AttributeKey)17 Span (io.opentelemetry.api.trace.Span)17 DoubleExemplarData (io.opentelemetry.sdk.metrics.data.DoubleExemplarData)17 AttributeKey.stringKey (io.opentelemetry.api.common.AttributeKey.stringKey)16 Map (java.util.Map)16