Search in sources :

Example 51 with Attributes

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

the class TemporalMetricStorageTest method synchronousDelta_dropsStale.

@Test
void synchronousDelta_dropsStale() {
    TemporalMetricStorage<DoubleAccumulation> storage = new TemporalMetricStorage<>(SUM, /* isSynchronous= */
    true);
    // Send in new measurement at time 10 for collector 1, with attr1
    Map<Attributes, DoubleAccumulation> measurement1 = new HashMap<>();
    Attributes attr1 = Attributes.builder().put("key", "value1").build();
    measurement1.put(attr1, DoubleAccumulation.create(3));
    assertThat(storage.buildMetricFor(collector1, Resource.empty(), InstrumentationLibraryInfo.empty(), METRIC_DESCRIPTOR, AggregationTemporality.DELTA, measurement1, 0, 10)).hasDoubleSum().isDelta().points().hasSize(1).isNotEmpty().contains(ImmutableDoublePointData.create(0, 10, attr1, 3));
    // Send in new measurement at time 20 for collector 1, with attr2
    // Result should drop accumulation for attr1, only reporting accumulation for attr2
    Map<Attributes, DoubleAccumulation> measurement2 = new HashMap<>();
    Attributes attr2 = Attributes.builder().put("key", "value2").build();
    measurement2.put(attr2, DoubleAccumulation.create(7));
    assertThat(storage.buildMetricFor(collector1, Resource.empty(), InstrumentationLibraryInfo.empty(), METRIC_DESCRIPTOR, AggregationTemporality.DELTA, measurement2, 0, 20)).hasDoubleSum().isDelta().points().hasSize(1).isNotEmpty().containsExactly(ImmutableDoublePointData.create(10, 20, attr2, 7));
}
Also used : HashMap(java.util.HashMap) DoubleAccumulation(io.opentelemetry.sdk.metrics.internal.aggregator.DoubleAccumulation) Attributes(io.opentelemetry.api.common.Attributes) Test(org.junit.jupiter.api.Test)

Example 52 with Attributes

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

the class TemporalMetricStorageTest method asynchronousDelta_dropsStale.

@Test
void asynchronousDelta_dropsStale() {
    TemporalMetricStorage<DoubleAccumulation> storage = new TemporalMetricStorage<>(ASYNC_SUM, /* isSynchronous= */
    false);
    // Send in new measurement at time 10 for collector 1, with attr1
    Map<Attributes, DoubleAccumulation> measurement1 = new HashMap<>();
    Attributes attr1 = Attributes.builder().put("key", "value1").build();
    measurement1.put(attr1, DoubleAccumulation.create(3));
    assertThat(storage.buildMetricFor(collector1, Resource.empty(), InstrumentationLibraryInfo.empty(), METRIC_DESCRIPTOR, AggregationTemporality.DELTA, measurement1, 0, 10)).hasDoubleSum().isDelta().points().hasSize(1).isNotEmpty().contains(ImmutableDoublePointData.create(0, 10, attr1, 3));
    // Send in new measurement at time 20 for collector 1, with attr2
    // Result should drop accumulation for attr1, only reporting accumulation for attr2
    Map<Attributes, DoubleAccumulation> measurement2 = new HashMap<>();
    Attributes attr2 = Attributes.builder().put("key", "value2").build();
    measurement2.put(attr2, DoubleAccumulation.create(7));
    assertThat(storage.buildMetricFor(collector1, Resource.empty(), InstrumentationLibraryInfo.empty(), METRIC_DESCRIPTOR, AggregationTemporality.DELTA, measurement2, 0, 20)).hasDoubleSum().isDelta().points().hasSize(1).isNotEmpty().containsExactly(ImmutableDoublePointData.create(10, 20, attr2, 7));
}
Also used : HashMap(java.util.HashMap) DoubleAccumulation(io.opentelemetry.sdk.metrics.internal.aggregator.DoubleAccumulation) Attributes(io.opentelemetry.api.common.Attributes) Test(org.junit.jupiter.api.Test)

Example 53 with Attributes

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

the class ResourceConfigurationTest method resourceFromConfig_empty.

@Test
void resourceFromConfig_empty() {
    Attributes attributes = ResourceConfiguration.getAttributes(DefaultConfigProperties.createForTest(emptyMap()));
    assertThat(attributes).isEmpty();
}
Also used : Attributes(io.opentelemetry.api.common.Attributes) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes) Test(org.junit.jupiter.api.Test)

Example 54 with Attributes

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

the class ResourceConfigurationTest method resourceFromConfig_overrideServiceName.

@Test
void resourceFromConfig_overrideServiceName() {
    Attributes attributes = ResourceConfiguration.getAttributes(DefaultConfigProperties.createForTest(ImmutableMap.of(ResourceConfiguration.ATTRIBUTE_PROPERTY, "service.name=myService,appName=MyApp", ResourceConfiguration.SERVICE_NAME_PROPERTY, "ReallyMyService")));
    assertThat(attributes).hasSize(2).containsEntry(ResourceAttributes.SERVICE_NAME, "ReallyMyService").containsEntry("appName", "MyApp");
}
Also used : Attributes(io.opentelemetry.api.common.Attributes) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes) Test(org.junit.jupiter.api.Test)

Example 55 with Attributes

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

the class ResourceConfigurationTest method resourceFromConfig_emptyEnvVar.

@Test
void resourceFromConfig_emptyEnvVar() {
    Attributes attributes = ResourceConfiguration.getAttributes(DefaultConfigProperties.createForTest(singletonMap(ResourceConfiguration.ATTRIBUTE_PROPERTY, "")));
    assertThat(attributes).isEmpty();
}
Also used : Attributes(io.opentelemetry.api.common.Attributes) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes) 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