|
22 | 22 | import static co.elastic.otel.ElasticAutoConfigurationCustomizerProvider.resourceProviders; |
23 | 23 | import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; |
24 | 24 |
|
| 25 | +import co.elastic.otel.testing.OtelReflectionUtils; |
| 26 | +import io.opentelemetry.exporter.otlp.http.metrics.OtlpHttpMetricExporter; |
25 | 27 | import io.opentelemetry.javaagent.tooling.EmptyConfigProperties; |
| 28 | +import io.opentelemetry.sdk.OpenTelemetrySdk; |
| 29 | +import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk; |
26 | 30 | import io.opentelemetry.sdk.autoconfigure.spi.internal.DefaultConfigProperties; |
| 31 | +import io.opentelemetry.sdk.metrics.InstrumentType; |
| 32 | +import io.opentelemetry.sdk.metrics.data.AggregationTemporality; |
| 33 | +import io.opentelemetry.sdk.metrics.export.AggregationTemporalitySelector; |
| 34 | +import io.opentelemetry.sdk.metrics.export.MetricExporter; |
27 | 35 | import io.opentelemetry.sdk.resources.Resource; |
28 | 36 | import io.opentelemetry.semconv.incubating.DeploymentIncubatingAttributes; |
29 | 37 | import java.util.HashMap; |
| 38 | +import java.util.List; |
30 | 39 | import java.util.Map; |
| 40 | +import org.assertj.core.api.Assertions; |
31 | 41 | import org.junit.jupiter.api.Test; |
32 | 42 |
|
33 | 43 | class ElasticAutoConfigurationCustomizerProviderTest { |
@@ -88,6 +98,50 @@ void customizeMetricTemporalityPreference() { |
88 | 98 | assertThat(value).isEqualTo("LOWMEMORY"); |
89 | 99 | } |
90 | 100 |
|
| 101 | + @Test |
| 102 | + void testTemporalityWorkaroundStilLRequired() { |
| 103 | + // Verifies that the workaround for |
| 104 | + // https://github.com/open-telemetry/opentelemetry-java/issues/7276 |
| 105 | + // is still required. Once not needed anymore, fix the TODO in |
| 106 | + // co.elastic.otel.ElasticUserAgentHeader and remove this test |
| 107 | + |
| 108 | + OtlpHttpMetricExporter original = |
| 109 | + OtlpHttpMetricExporter.builder() |
| 110 | + .setAggregationTemporalitySelector(AggregationTemporalitySelector.deltaPreferred()) |
| 111 | + .build(); |
| 112 | + Assertions.assertThat(original.getAggregationTemporality(InstrumentType.COUNTER)) |
| 113 | + .isEqualTo(AggregationTemporality.DELTA); |
| 114 | + |
| 115 | + OtlpHttpMetricExporter modified = original.toBuilder().build(); |
| 116 | + |
| 117 | + // The bug causes the temporality to become cumulative, though it should be delta |
| 118 | + assertThat(modified.getAggregationTemporality(InstrumentType.COUNTER)) |
| 119 | + .isEqualTo(AggregationTemporality.CUMULATIVE); |
| 120 | + } |
| 121 | + |
| 122 | + @Test |
| 123 | + void verifyDefaultTemporalityOverriddenToDelta() { |
| 124 | + try (OpenTelemetrySdk sdk = |
| 125 | + AutoConfiguredOpenTelemetrySdk.builder().build().getOpenTelemetrySdk()) { |
| 126 | + List<MetricExporter> metricExporters = |
| 127 | + OtelReflectionUtils.extractMetricExporters(sdk.getSdkMeterProvider()); |
| 128 | + |
| 129 | + assertThat(metricExporters).hasSize(1); |
| 130 | + |
| 131 | + MetricExporter otlp = metricExporters.get(0); |
| 132 | + assertThat(otlp.getAggregationTemporality(InstrumentType.COUNTER)) |
| 133 | + .isEqualTo(AggregationTemporality.DELTA); |
| 134 | + assertThat(otlp.getAggregationTemporality(InstrumentType.OBSERVABLE_COUNTER)) |
| 135 | + .isEqualTo(AggregationTemporality.DELTA); |
| 136 | + assertThat(otlp.getAggregationTemporality(InstrumentType.HISTOGRAM)) |
| 137 | + .isEqualTo(AggregationTemporality.DELTA); |
| 138 | + assertThat(otlp.getAggregationTemporality(InstrumentType.UP_DOWN_COUNTER)) |
| 139 | + .isEqualTo(AggregationTemporality.CUMULATIVE); |
| 140 | + assertThat(otlp.getAggregationTemporality(InstrumentType.OBSERVABLE_UP_DOWN_COUNTER)) |
| 141 | + .isEqualTo(AggregationTemporality.CUMULATIVE); |
| 142 | + } |
| 143 | + } |
| 144 | + |
91 | 145 | @Test |
92 | 146 | void legacyDeploymentEnvironment() { |
93 | 147 | Resource input = |
|
0 commit comments