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));
}
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));
}
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();
}
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");
}
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();
}
Aggregations