From f0959e6bf582f40f8d09e99325dfc04888d40f58 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Fri, 5 Aug 2022 13:55:05 -0700 Subject: [PATCH 01/95] Add placeholder --- .../implementation/MetricDataMapper.java | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index b223937eb4d..4d68c8266fc 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -49,17 +49,19 @@ public class MetricDataMapper { - private static final List EXCLUDED_METRIC_NAMES = new ArrayList<>(); + private static final List OTEL_PRE_AGGREGATED_METRIC_NAMES = new ArrayList<>(); + private static final List OTHER_EXCLUDED_METRIC_NAMES = new ArrayList<>(); private static final Logger logger = LoggerFactory.getLogger(MetricDataMapper.class); private final BiConsumer telemetryInitializer; static { - EXCLUDED_METRIC_NAMES.add("http.server.active_requests"); // Servlet - EXCLUDED_METRIC_NAMES.add("http.server.duration"); // Servlet - EXCLUDED_METRIC_NAMES.add("http.client.duration"); // HttpClient - EXCLUDED_METRIC_NAMES.add("rpc.client.duration"); // gRPC - EXCLUDED_METRIC_NAMES.add("rpc.server.duration"); // gRPC + OTHER_EXCLUDED_METRIC_NAMES.add("http.server.active_requests"); // Servlet + + OTEL_PRE_AGGREGATED_METRIC_NAMES.add("http.server.duration"); // Servlet + OTEL_PRE_AGGREGATED_METRIC_NAMES.add("http.client.duration"); // HttpClient + OTEL_PRE_AGGREGATED_METRIC_NAMES.add("rpc.client.duration"); // gRPC + OTEL_PRE_AGGREGATED_METRIC_NAMES.add("rpc.server.duration"); // gRPC } public MetricDataMapper(BiConsumer telemetryInitializer) { @@ -67,26 +69,37 @@ public MetricDataMapper(BiConsumer telemetry } public void map(MetricData metricData, Consumer consumer) { - if (EXCLUDED_METRIC_NAMES.contains(metricData.getName())) { + if (OTHER_EXCLUDED_METRIC_NAMES.contains(metricData.getName())) { return; } MetricDataType type = metricData.getType(); - if (type == DOUBLE_SUM + List telemetryItemList = new ArrayList<>(); + if (OTEL_PRE_AGGREGATED_METRIC_NAMES.contains(metricData.getName())) { + telemetryItemList = convertOtelStandardMetricToAzureMonitorStandardMetric(metricData); + } else if (type == DOUBLE_SUM || type == DOUBLE_GAUGE || type == LONG_SUM || type == LONG_GAUGE || type == HISTOGRAM) { - List telemetryItemList = convertOtelMetricToAzureMonitorMetric(metricData); - for (TelemetryItem telemetryItem : telemetryItemList) { - consumer.accept(telemetryItem); - } + telemetryItemList = convertOtelCustomMetricToAzureMonitorCustomMetric(metricData); } else { logger.warn("metric data type {} is not supported yet.", metricData.getType()); } + + for (TelemetryItem telemetryItem : telemetryItemList) { + consumer.accept(telemetryItem); + } + } + + private List convertOtelStandardMetricToAzureMonitorStandardMetric( + MetricData metricData) { + // TODO + return null; } - private List convertOtelMetricToAzureMonitorMetric(MetricData metricData) { + private List convertOtelCustomMetricToAzureMonitorCustomMetric( + MetricData metricData) { List telemetryItems = new ArrayList<>(); for (PointData pointData : metricData.getData().getPoints()) { From e7071110861d7b74a64da88b124b6b839b083ace Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Fri, 5 Aug 2022 13:55:59 -0700 Subject: [PATCH 02/95] Rename --- .../exporter/implementation/MetricDataMapper.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index 4d68c8266fc..0196100c41b 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -50,13 +50,13 @@ public class MetricDataMapper { private static final List OTEL_PRE_AGGREGATED_METRIC_NAMES = new ArrayList<>(); - private static final List OTHER_EXCLUDED_METRIC_NAMES = new ArrayList<>(); + private static final List EXCLUDED_METRIC_NAMES = new ArrayList<>(); private static final Logger logger = LoggerFactory.getLogger(MetricDataMapper.class); private final BiConsumer telemetryInitializer; static { - OTHER_EXCLUDED_METRIC_NAMES.add("http.server.active_requests"); // Servlet + EXCLUDED_METRIC_NAMES.add("http.server.active_requests"); // Servlet OTEL_PRE_AGGREGATED_METRIC_NAMES.add("http.server.duration"); // Servlet OTEL_PRE_AGGREGATED_METRIC_NAMES.add("http.client.duration"); // HttpClient @@ -69,7 +69,7 @@ public MetricDataMapper(BiConsumer telemetry } public void map(MetricData metricData, Consumer consumer) { - if (OTHER_EXCLUDED_METRIC_NAMES.contains(metricData.getName())) { + if (EXCLUDED_METRIC_NAMES.contains(metricData.getName())) { return; } From c4e547405fc0b994e6d35a7754dfb2302eddfa64 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Mon, 8 Aug 2022 13:13:03 -0700 Subject: [PATCH 03/95] Start mapping pre-agg metrics to azure monitor metrics --- .../implementation/MetricDataMapper.java | 45 +++--- .../AzureMonitorMetricExporterTest.java | 14 +- .../exporter/PreAggregatedMetricsTest.java | 128 ++++++++++++++++++ 3 files changed, 160 insertions(+), 27 deletions(-) create mode 100644 agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index 0196100c41b..a89f68576e7 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -49,6 +49,10 @@ public class MetricDataMapper { + private static final String MS_METRIC_ID = "_MS.metricId"; + private static final String MS_IS_AUTOCOLLECTED = "_MS.IsAutocollected"; + private static final String TRUE = "True"; + private static final String MS_PROCESSED_BY_METRIC_EXTRACTORS = "_MS.ProcessedByMetricExtractors"; private static final List OTEL_PRE_AGGREGATED_METRIC_NAMES = new ArrayList<>(); private static final List EXCLUDED_METRIC_NAMES = new ArrayList<>(); @@ -74,32 +78,24 @@ public void map(MetricData metricData, Consumer consumer) { } MetricDataType type = metricData.getType(); - List telemetryItemList = new ArrayList<>(); - if (OTEL_PRE_AGGREGATED_METRIC_NAMES.contains(metricData.getName())) { - telemetryItemList = convertOtelStandardMetricToAzureMonitorStandardMetric(metricData); - } else if (type == DOUBLE_SUM + if (type == DOUBLE_SUM || type == DOUBLE_GAUGE || type == LONG_SUM || type == LONG_GAUGE || type == HISTOGRAM) { - telemetryItemList = convertOtelCustomMetricToAzureMonitorCustomMetric(metricData); + boolean isPreAggregated = OTEL_PRE_AGGREGATED_METRIC_NAMES.contains(metricData.getName()); + List telemetryItemList = + convertOtelMetricToAzureMonitorMetric(metricData, isPreAggregated); + for (TelemetryItem telemetryItem : telemetryItemList) { + consumer.accept(telemetryItem); + } } else { logger.warn("metric data type {} is not supported yet.", metricData.getType()); } - - for (TelemetryItem telemetryItem : telemetryItemList) { - consumer.accept(telemetryItem); - } - } - - private List convertOtelStandardMetricToAzureMonitorStandardMetric( - MetricData metricData) { - // TODO - return null; } - private List convertOtelCustomMetricToAzureMonitorCustomMetric( - MetricData metricData) { + private List convertOtelMetricToAzureMonitorMetric( + MetricData metricData, boolean isPreAggregated) { List telemetryItems = new ArrayList<>(); for (PointData pointData : metricData.getData().getPoints()) { @@ -107,7 +103,7 @@ private List convertOtelCustomMetricToAzureMonitorCustomMetric( telemetryInitializer.accept(builder, metricData.getResource()); builder.setTime(FormattedTime.offSetDateTimeFromEpochNanos(pointData.getEpochNanos())); - updateMetricPointBuilder(builder, metricData, pointData); + updateMetricPointBuilder(builder, metricData, pointData, isPreAggregated); telemetryItems.add(builder.build()); } @@ -116,7 +112,10 @@ private List convertOtelCustomMetricToAzureMonitorCustomMetric( // visible for testing public static void updateMetricPointBuilder( - MetricTelemetryBuilder metricTelemetryBuilder, MetricData metricData, PointData pointData) { + MetricTelemetryBuilder metricTelemetryBuilder, + MetricData metricData, + PointData pointData, + boolean isPreAggregated) { checkArgument(metricData != null, "MetricData cannot be null."); MetricPointBuilder pointBuilder = new MetricPointBuilder(); @@ -151,12 +150,18 @@ public static void updateMetricPointBuilder( } pointBuilder.setName(metricData.getName()); - metricTelemetryBuilder.setMetricPoint(pointBuilder); pointData .getAttributes() .forEach( (key, value) -> metricTelemetryBuilder.addProperty(key.getKey(), value.toString())); + + if (isPreAggregated) { + metricTelemetryBuilder.addProperty(MS_METRIC_ID, "requests/duration"); + metricTelemetryBuilder.addProperty(MS_IS_AUTOCOLLECTED, TRUE); + // this flag will inform the ingestion service to stop post-aggregation + metricTelemetryBuilder.addProperty(MS_PROCESSED_BY_METRIC_EXTRACTORS, TRUE); + } } } diff --git a/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/AzureMonitorMetricExporterTest.java b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/AzureMonitorMetricExporterTest.java index 373bf5eabf7..b1b0d463f1d 100644 --- a/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/AzureMonitorMetricExporterTest.java +++ b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/AzureMonitorMetricExporterTest.java @@ -100,7 +100,7 @@ public void testDoubleCounter() throws InterruptedException { MetricData metricData = metricDatas.get(0); for (PointData pointData : metricData.getData().getPoints()) { MetricTelemetryBuilder builder = MetricTelemetryBuilder.create(); - MetricDataMapper.updateMetricPointBuilder(builder, metricDatas.get(0), pointData); + MetricDataMapper.updateMetricPointBuilder(builder, metricDatas.get(0), pointData, false); MetricsData metricsData = (MetricsData) builder.build().getData().getBaseData(); assertThat(metricsData.getMetrics().size()).isEqualTo(1); assertThat(metricsData.getMetrics().get(0).getValue()).isEqualTo(3.1415); @@ -129,7 +129,7 @@ public void testDoubleGauge() throws InterruptedException { MetricData metricData = metricDataList.get(0); for (PointData pointData : metricData.getData().getPoints()) { MetricTelemetryBuilder builder = MetricTelemetryBuilder.create(); - MetricDataMapper.updateMetricPointBuilder(builder, metricData, pointData); + MetricDataMapper.updateMetricPointBuilder(builder, metricData, pointData, false); MetricsData metricsData = (MetricsData) builder.build().getData().getBaseData(); assertThat(metricsData.getMetrics().size()).isEqualTo(1); assertThat(metricsData.getMetrics().get(0).getValue()).isEqualTo(20.0); @@ -205,7 +205,7 @@ public void testLongCounter() throws InterruptedException { .isEqualTo("yellow"); MetricTelemetryBuilder builder = MetricTelemetryBuilder.create(); - MetricDataMapper.updateMetricPointBuilder(builder, metricData, longPointData1); + MetricDataMapper.updateMetricPointBuilder(builder, metricData, longPointData1, false); MetricsData metricsData = (MetricsData) builder.build().getData().getBaseData(); assertThat(metricsData.getMetrics().size()).isEqualTo(1); MetricDataPoint metricDataPoint = metricsData.getMetrics().get(0); @@ -217,7 +217,7 @@ public void testLongCounter() throws InterruptedException { assertThat(properties).containsEntry("color", "green"); builder = MetricTelemetryBuilder.create(); - MetricDataMapper.updateMetricPointBuilder(builder, metricData, longPointData2); + MetricDataMapper.updateMetricPointBuilder(builder, metricData, longPointData2, false); metricsData = (MetricsData) builder.build().getData().getBaseData(); assertThat(metricsData.getMetrics().size()).isEqualTo(1); metricDataPoint = metricsData.getMetrics().get(0); @@ -229,7 +229,7 @@ public void testLongCounter() throws InterruptedException { assertThat(properties).containsEntry("color", "red"); builder = MetricTelemetryBuilder.create(); - MetricDataMapper.updateMetricPointBuilder(builder, metricData, longPointData3); + MetricDataMapper.updateMetricPointBuilder(builder, metricData, longPointData3, false); metricsData = (MetricsData) builder.build().getData().getBaseData(); assertThat(metricsData.getMetrics().size()).isEqualTo(1); metricDataPoint = metricsData.getMetrics().get(0); @@ -264,7 +264,7 @@ public void testLongGauge() throws InterruptedException { MetricData metricData = metricDataList.get(0); for (PointData pointData : metricData.getData().getPoints()) { MetricTelemetryBuilder builder = MetricTelemetryBuilder.create(); - MetricDataMapper.updateMetricPointBuilder(builder, metricData, pointData); + MetricDataMapper.updateMetricPointBuilder(builder, metricData, pointData, false); MetricsData metricsData = (MetricsData) builder.build().getData().getBaseData(); assertThat(metricsData.getMetrics().size()).isEqualTo(1); assertThat(metricsData.getMetrics().get(0).getValue()).isEqualTo(20); @@ -295,7 +295,7 @@ public void testDoubleHistogram() throws InterruptedException { assertThat(metricData.getData().getPoints().size()).isEqualTo(1); PointData pointData = metricData.getData().getPoints().iterator().next(); MetricTelemetryBuilder builder = MetricTelemetryBuilder.create(); - MetricDataMapper.updateMetricPointBuilder(builder, metricData, pointData); + MetricDataMapper.updateMetricPointBuilder(builder, metricData, pointData, false); MetricsData metricsData = (MetricsData) builder.build().getData().getBaseData(); assertThat(metricsData.getMetrics().size()).isEqualTo(1); assertThat(metricsData.getMetrics().get(0).getCount()).isEqualTo(1); diff --git a/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java new file mode 100644 index 00000000000..413b50ced15 --- /dev/null +++ b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java @@ -0,0 +1,128 @@ +/* + * ApplicationInsights-Java + * Copyright (c) Microsoft Corporation + * All rights reserved. + * + * MIT License + * Permission is hereby granted, free of charge, to any person obtaining a copy of this + * software and associated documentation files (the ""Software""), to deal in the Software + * without restriction, including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, and to permit + * persons to whom the Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package com.azure.monitor.opentelemetry.exporter; + +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; +import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; + +import com.azure.core.util.logging.ClientLogger; +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.trace.Span; +import io.opentelemetry.api.trace.SpanContext; +import io.opentelemetry.api.trace.TraceFlags; +import io.opentelemetry.api.trace.TraceState; +import io.opentelemetry.context.Context; +import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics; +import io.opentelemetry.sdk.metrics.SdkMeterProvider; +import io.opentelemetry.sdk.metrics.data.MetricData; +import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import java.util.Collection; +import java.util.concurrent.TimeUnit; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class PreAggregatedMetricsTest { + + private InMemoryMetricReader metricReader; + private SdkMeterProvider meterProvider; + + @BeforeEach + void setup() { + metricReader = InMemoryMetricReader.create(); + meterProvider = SdkMeterProvider.builder().registerMetricReader(metricReader).build(); + } + + @Test + void collectHttpClientRMetric() { + OperationListener listener = HttpClientMetrics.get().create(meterProvider.get("test")); + + Attributes requestAttributes = + Attributes.builder() + .put("http.method", "GET") + .put("http.url", "https://localhost:1234/") + .put("http.host", "host") + .put("http.target", "/") + .put("http.scheme", "https") + .put("net.peer.name", "localhost") + .put("net.peer.ip", "0.0.0.0") + .put("net.peer.port", 1234) + .put("http.request_content_length", 100) + .build(); + + Attributes responseAttributes = + Attributes.builder() + .put("http.flavor", "2.0") + .put("http.server_name", "server") + .put("http.status_code", 200) + .put("http.response_content_length", 200) + .build(); + + Context parent = + Context.root() + .with( + Span.wrap( + SpanContext.create( + "ff01020304050600ff0a0b0c0d0e0f00", + "090a0b0c0d0e0f00", + TraceFlags.getSampled(), + TraceState.getDefault()))); + + Context context1 = listener.onStart(parent, requestAttributes, nanos(100)); + listener.onEnd(context1, responseAttributes, nanos(250)); + + ClientLogger LOGGER = new ClientLogger(PreAggregatedMetricsTest.class); + Collection metricDataCollection = metricReader.collectAllMetrics(); + for (MetricData metricData : metricDataCollection) { + LOGGER.verbose("metric: {}", metricData); + } + + assertThat(metricDataCollection) + .satisfiesExactly( + metric -> + assertThat(metric) + .hasName("http.client.duration") + .hasUnit("ms") + .hasHistogramSatisfying( + histogram -> + histogram.hasPointsSatisfying( + point -> + point + .hasSum(150 /* millis */) + .hasAttributesSatisfying( + equalTo(SemanticAttributes.NET_PEER_NAME, "localhost"), + equalTo(SemanticAttributes.NET_PEER_PORT, 1234), + equalTo(SemanticAttributes.HTTP_METHOD, "GET"), + equalTo(SemanticAttributes.HTTP_FLAVOR, "2.0"), + equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200)) + .hasExemplarsSatisfying( + exemplar -> + exemplar + .hasTraceId("ff01020304050600ff0a0b0c0d0e0f00") + .hasSpanId("090a0b0c0d0e0f00"))))); + } + + private static long nanos(int millis) { + return TimeUnit.MILLISECONDS.toNanos(millis); + } +} From fd58580df373588f26e9de98959bbf2e6f19d9e1 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Tue, 9 Aug 2022 14:02:31 -0700 Subject: [PATCH 04/95] Add preagg metrics extractor --- .../implementation/MetricDataMapper.java | 26 +++++------- .../DurationBucketizer.java | 32 +++++++++++++++ .../RequestCustomDimensionsExtractor.java | 41 +++++++++++++++++++ 3 files changed, 84 insertions(+), 15 deletions(-) create mode 100644 agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DurationBucketizer.java create mode 100644 agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestCustomDimensionsExtractor.java diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index a89f68576e7..c7de7e3a056 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -21,6 +21,7 @@ package com.azure.monitor.opentelemetry.exporter.implementation; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.updatePreAggMetricsCustomDimensions; import static io.opentelemetry.api.internal.Utils.checkArgument; import static io.opentelemetry.sdk.metrics.data.MetricDataType.DOUBLE_GAUGE; import static io.opentelemetry.sdk.metrics.data.MetricDataType.DOUBLE_SUM; @@ -33,6 +34,7 @@ import com.azure.monitor.opentelemetry.exporter.implementation.builders.MetricTelemetryBuilder; import com.azure.monitor.opentelemetry.exporter.implementation.models.TelemetryItem; import com.azure.monitor.opentelemetry.exporter.implementation.utils.FormattedTime; +import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.sdk.metrics.data.DoublePointData; import io.opentelemetry.sdk.metrics.data.HistogramPointData; import io.opentelemetry.sdk.metrics.data.LongPointData; @@ -49,10 +51,6 @@ public class MetricDataMapper { - private static final String MS_METRIC_ID = "_MS.metricId"; - private static final String MS_IS_AUTOCOLLECTED = "_MS.IsAutocollected"; - private static final String TRUE = "True"; - private static final String MS_PROCESSED_BY_METRIC_EXTRACTORS = "_MS.ProcessedByMetricExtractors"; private static final List OTEL_PRE_AGGREGATED_METRIC_NAMES = new ArrayList<>(); private static final List EXCLUDED_METRIC_NAMES = new ArrayList<>(); @@ -120,18 +118,15 @@ public static void updateMetricPointBuilder( MetricPointBuilder pointBuilder = new MetricPointBuilder(); MetricDataType type = metricData.getType(); + double pointDataValue; switch (type) { case LONG_SUM: - pointBuilder.setValue((double) ((LongPointData) pointData).getValue()); - break; case LONG_GAUGE: - pointBuilder.setValue((double) ((LongPointData) pointData).getValue()); + pointDataValue = (double)((LongPointData) pointData).getValue(); break; case DOUBLE_SUM: - pointBuilder.setValue(((DoublePointData) pointData).getValue()); - break; case DOUBLE_GAUGE: - pointBuilder.setValue(((DoublePointData) pointData).getValue()); + pointDataValue = ((DoublePointData) pointData).getValue(); break; case HISTOGRAM: long histogramCount = ((HistogramPointData) pointData).getCount(); @@ -139,7 +134,7 @@ public static void updateMetricPointBuilder( pointBuilder.setCount((int) histogramCount); } HistogramPointData histogramPointData = (HistogramPointData) pointData; - pointBuilder.setValue(histogramPointData.getSum()); + pointDataValue = histogramPointData.getSum(); // TODO need to be updated pointBuilder.setMin(histogramPointData.getMin()); pointBuilder.setMax(histogramPointData.getMax()); break; @@ -149,6 +144,7 @@ public static void updateMetricPointBuilder( throw new IllegalArgumentException("metric data type '" + type + "' is not supported yet"); } + pointBuilder.setValue(pointDataValue); pointBuilder.setName(metricData.getName()); metricTelemetryBuilder.setMetricPoint(pointBuilder); @@ -158,10 +154,10 @@ public static void updateMetricPointBuilder( (key, value) -> metricTelemetryBuilder.addProperty(key.getKey(), value.toString())); if (isPreAggregated) { - metricTelemetryBuilder.addProperty(MS_METRIC_ID, "requests/duration"); - metricTelemetryBuilder.addProperty(MS_IS_AUTOCOLLECTED, TRUE); - // this flag will inform the ingestion service to stop post-aggregation - metricTelemetryBuilder.addProperty(MS_PROCESSED_BY_METRIC_EXTRACTORS, TRUE); + updatePreAggMetricsCustomDimensions( + metricTelemetryBuilder, + pointDataValue, + pointData.getAttributes().get(AttributeKey.stringKey("http.status_code"))); } } } diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DurationBucketizer.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DurationBucketizer.java new file mode 100644 index 00000000000..5296dd16229 --- /dev/null +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DurationBucketizer.java @@ -0,0 +1,32 @@ +package com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics; + +import java.util.HashMap; +import java.util.Map; + +public class DurationBucketizer { + + private static final Map performanceBuckets = new HashMap<>(); + + static { + performanceBuckets.put("<250ms", 250.0); + performanceBuckets.put("250ms-500ms", 500.0); + performanceBuckets.put("500ms-1sec", 1000.0); + performanceBuckets.put("1sec-3sec", 3000.0); + performanceBuckets.put("3sec-7sec", 7000.0); + performanceBuckets.put("7sec-15sec", 15000.0); + performanceBuckets.put("15sec-30sec", 30000.0); + performanceBuckets.put("30sec-1min", 60000.0); + performanceBuckets.put("1min-2min", 120000.0); + performanceBuckets.put("2min-5min", 300000.0); + performanceBuckets.put(">=5min", Double.MAX_VALUE); + } + + public static String getPerformanceBucket(double durationInMillis) { + for (Map.Entry entry : performanceBuckets.entrySet()) { + if (durationInMillis < entry.getValue()) { + return entry.getKey(); + } + } + return ">=5min"; + } +} diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestCustomDimensionsExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestCustomDimensionsExtractor.java new file mode 100644 index 00000000000..acb8dc7621f --- /dev/null +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestCustomDimensionsExtractor.java @@ -0,0 +1,41 @@ +package com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics; + +import com.azure.monitor.opentelemetry.exporter.implementation.builders.AbstractTelemetryBuilder; +import com.azure.monitor.opentelemetry.exporter.implementation.models.ContextTagKeys; + +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.DurationBucketizer.getPerformanceBucket; + +public final class RequestCustomDimensionsExtractor { + + // visible for testing + static final String REQUEST_METRIC_ID = "requests/duration"; + static final String MS_METRIC_ID = "_MS.metricId"; + static final String MS_IS_AUTOCOLLECTED = "_MS.IsAutocollected"; + static final String TRUE = "True"; + static final String FALSE = "False"; + static final String MS_PROCESSED_BY_METRIC_EXTRACTORS = "_MS.ProcessedByMetricExtractors"; + static final String PERFORMANCE_BUCKET = "request/performanceBucket"; + static final String REQUEST_RESULT_CODE = "request/resultCode"; + static final String OPERATION_SYNTHETIC = "operation/synthetic"; + static final String CLOUD_ROLE_NAME = "cloud/roleName"; + static final String CLOUD_ROLE_INSTANCE = "cloud/roleInstance"; + static final String REQUEST_SUCCESS = "request/success"; + + public static void updatePreAggMetricsCustomDimensions(AbstractTelemetryBuilder metricTelemetryBuilder, double value, String resultCode) { + metricTelemetryBuilder.addProperty(MS_METRIC_ID, REQUEST_METRIC_ID); + metricTelemetryBuilder.addProperty(MS_IS_AUTOCOLLECTED, TRUE); + // this flag will inform the ingestion service to stop post-aggregation + metricTelemetryBuilder.addProperty(MS_PROCESSED_BY_METRIC_EXTRACTORS, TRUE); + + // TODO figure out the correct duration/value + metricTelemetryBuilder.addProperty(PERFORMANCE_BUCKET, getPerformanceBucket(value)); + metricTelemetryBuilder.addProperty(REQUEST_RESULT_CODE, resultCode); + metricTelemetryBuilder.addProperty(OPERATION_SYNTHETIC, FALSE); + metricTelemetryBuilder.addProperty(CLOUD_ROLE_NAME, metricTelemetryBuilder.build().getTags().get(ContextTagKeys.AI_CLOUD_ROLE.toString())); + metricTelemetryBuilder.addProperty(CLOUD_ROLE_INSTANCE, metricTelemetryBuilder.build().getTags().get( + ContextTagKeys.AI_CLOUD_ROLE_INSTANCE.toString())); + metricTelemetryBuilder.addProperty(REQUEST_SUCCESS, TRUE); + } + + private RequestCustomDimensionsExtractor() {} +} From b47c27c774f5ea726fc0edb5fa4753ea47653f5a Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Tue, 9 Aug 2022 14:03:48 -0700 Subject: [PATCH 05/95] Fix spotless --- .../implementation/MetricDataMapper.java | 2 +- .../DurationBucketizer.java | 21 ++++++++++ .../RequestCustomDimensionsExtractor.java | 40 ++++++++++++++++--- 3 files changed, 56 insertions(+), 7 deletions(-) diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index c7de7e3a056..9a8b433f28c 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -122,7 +122,7 @@ public static void updateMetricPointBuilder( switch (type) { case LONG_SUM: case LONG_GAUGE: - pointDataValue = (double)((LongPointData) pointData).getValue(); + pointDataValue = (double) ((LongPointData) pointData).getValue(); break; case DOUBLE_SUM: case DOUBLE_GAUGE: diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DurationBucketizer.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DurationBucketizer.java index 5296dd16229..1b4414c033b 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DurationBucketizer.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DurationBucketizer.java @@ -1,3 +1,24 @@ +/* + * ApplicationInsights-Java + * Copyright (c) Microsoft Corporation + * All rights reserved. + * + * MIT License + * Permission is hereby granted, free of charge, to any person obtaining a copy of this + * software and associated documentation files (the ""Software""), to deal in the Software + * without restriction, including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, and to permit + * persons to whom the Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + package com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics; import java.util.HashMap; diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestCustomDimensionsExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestCustomDimensionsExtractor.java index acb8dc7621f..7eac89314d6 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestCustomDimensionsExtractor.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestCustomDimensionsExtractor.java @@ -1,10 +1,31 @@ +/* + * ApplicationInsights-Java + * Copyright (c) Microsoft Corporation + * All rights reserved. + * + * MIT License + * Permission is hereby granted, free of charge, to any person obtaining a copy of this + * software and associated documentation files (the ""Software""), to deal in the Software + * without restriction, including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, and to permit + * persons to whom the Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + package com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.DurationBucketizer.getPerformanceBucket; + import com.azure.monitor.opentelemetry.exporter.implementation.builders.AbstractTelemetryBuilder; import com.azure.monitor.opentelemetry.exporter.implementation.models.ContextTagKeys; -import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.DurationBucketizer.getPerformanceBucket; - public final class RequestCustomDimensionsExtractor { // visible for testing @@ -21,7 +42,8 @@ public final class RequestCustomDimensionsExtractor { static final String CLOUD_ROLE_INSTANCE = "cloud/roleInstance"; static final String REQUEST_SUCCESS = "request/success"; - public static void updatePreAggMetricsCustomDimensions(AbstractTelemetryBuilder metricTelemetryBuilder, double value, String resultCode) { + public static void updatePreAggMetricsCustomDimensions( + AbstractTelemetryBuilder metricTelemetryBuilder, double value, String resultCode) { metricTelemetryBuilder.addProperty(MS_METRIC_ID, REQUEST_METRIC_ID); metricTelemetryBuilder.addProperty(MS_IS_AUTOCOLLECTED, TRUE); // this flag will inform the ingestion service to stop post-aggregation @@ -31,9 +53,15 @@ public static void updatePreAggMetricsCustomDimensions(AbstractTelemetryBuilder metricTelemetryBuilder.addProperty(PERFORMANCE_BUCKET, getPerformanceBucket(value)); metricTelemetryBuilder.addProperty(REQUEST_RESULT_CODE, resultCode); metricTelemetryBuilder.addProperty(OPERATION_SYNTHETIC, FALSE); - metricTelemetryBuilder.addProperty(CLOUD_ROLE_NAME, metricTelemetryBuilder.build().getTags().get(ContextTagKeys.AI_CLOUD_ROLE.toString())); - metricTelemetryBuilder.addProperty(CLOUD_ROLE_INSTANCE, metricTelemetryBuilder.build().getTags().get( - ContextTagKeys.AI_CLOUD_ROLE_INSTANCE.toString())); + metricTelemetryBuilder.addProperty( + CLOUD_ROLE_NAME, + metricTelemetryBuilder.build().getTags().get(ContextTagKeys.AI_CLOUD_ROLE.toString())); + metricTelemetryBuilder.addProperty( + CLOUD_ROLE_INSTANCE, + metricTelemetryBuilder + .build() + .getTags() + .get(ContextTagKeys.AI_CLOUD_ROLE_INSTANCE.toString())); metricTelemetryBuilder.addProperty(REQUEST_SUCCESS, TRUE); } From 341b4329c611a488b1c01e2ef5b8f98b4a14bffe Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Tue, 9 Aug 2022 16:06:55 -0700 Subject: [PATCH 06/95] Use stdout --- .../exporter/implementation/MetricDataMapper.java | 3 ++- .../preaggregatedmetrics/DurationBucketizer.java | 4 +++- .../opentelemetry/exporter/PreAggregatedMetricsTest.java | 5 ++--- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index 9a8b433f28c..6bc98c3c3aa 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -134,7 +134,7 @@ public static void updateMetricPointBuilder( pointBuilder.setCount((int) histogramCount); } HistogramPointData histogramPointData = (HistogramPointData) pointData; - pointDataValue = histogramPointData.getSum(); // TODO need to be updated + pointDataValue = histogramPointData.getSum(); pointBuilder.setMin(histogramPointData.getMin()); pointBuilder.setMax(histogramPointData.getMax()); break; @@ -154,6 +154,7 @@ public static void updateMetricPointBuilder( (key, value) -> metricTelemetryBuilder.addProperty(key.getKey(), value.toString())); if (isPreAggregated) { + // TODO update value updatePreAggMetricsCustomDimensions( metricTelemetryBuilder, pointDataValue, diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DurationBucketizer.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DurationBucketizer.java index 1b4414c033b..ada7c95e56c 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DurationBucketizer.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DurationBucketizer.java @@ -24,7 +24,7 @@ import java.util.HashMap; import java.util.Map; -public class DurationBucketizer { +public final class DurationBucketizer { private static final Map performanceBuckets = new HashMap<>(); @@ -50,4 +50,6 @@ public static String getPerformanceBucket(double durationInMillis) { } return ">=5min"; } + + private DurationBucketizer() {} } diff --git a/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java index 413b50ced15..b0a07a0ac9c 100644 --- a/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java +++ b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java @@ -24,7 +24,6 @@ import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; -import com.azure.core.util.logging.ClientLogger; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.SpanContext; @@ -53,6 +52,7 @@ void setup() { meterProvider = SdkMeterProvider.builder().registerMetricReader(metricReader).build(); } + @SuppressWarnings("SystemOut") @Test void collectHttpClientRMetric() { OperationListener listener = HttpClientMetrics.get().create(meterProvider.get("test")); @@ -91,10 +91,9 @@ void collectHttpClientRMetric() { Context context1 = listener.onStart(parent, requestAttributes, nanos(100)); listener.onEnd(context1, responseAttributes, nanos(250)); - ClientLogger LOGGER = new ClientLogger(PreAggregatedMetricsTest.class); Collection metricDataCollection = metricReader.collectAllMetrics(); for (MetricData metricData : metricDataCollection) { - LOGGER.verbose("metric: {}", metricData); + System.out.println("metric: " + metricData); } assertThat(metricDataCollection) From 684b7ea1b2f492fba8ff848b00a3552ea57102ca Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Tue, 9 Aug 2022 18:43:16 -0700 Subject: [PATCH 07/95] Update test and refactor --- .../agent/internal/init/SecondEntryPoint.java | 4 +- .../exporter/AzureMonitorExporterBuilder.java | 2 +- .../implementation/MetricDataMapper.java | 40 +++++++++++++---- .../RequestCustomDimensionsExtractor.java | 31 +++++++------ .../AzureMonitorMetricExporterTest.java | 15 ++++--- .../exporter/PreAggregatedMetricsTest.java | 45 ++++++++++++++++++- 6 files changed, 104 insertions(+), 33 deletions(-) diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/SecondEntryPoint.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/SecondEntryPoint.java index 50d72c4af68..186db866451 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/SecondEntryPoint.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/SecondEntryPoint.java @@ -514,7 +514,9 @@ private static SdkMeterProviderBuilder configureMetrics( TelemetryClient telemetryClient, Configuration configuration) { - MetricDataMapper mapper = new MetricDataMapper(telemetryClient::populateDefaults); + MetricDataMapper mapper = + new MetricDataMapper( + telemetryClient::populateDefaults, configuration.preview.captureHttpServer4xxAsError); metricReader = PeriodicMetricReader.builder( new AgentMetricExporter( diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/AzureMonitorExporterBuilder.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/AzureMonitorExporterBuilder.java index e7e36b25d6c..ed895d69a7a 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/AzureMonitorExporterBuilder.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/AzureMonitorExporterBuilder.java @@ -276,7 +276,7 @@ public AzureMonitorMetricExporter buildMetricExporter() { HeartbeatExporter.start( MINUTES.toSeconds(15), this::populateDefaults, telemetryItemExporter::send); return new AzureMonitorMetricExporter( - new MetricDataMapper(this::populateDefaults), telemetryItemExporter); + new MetricDataMapper(this::populateDefaults, true), telemetryItemExporter); } /** diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index 6bc98c3c3aa..6a133992b16 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -56,6 +56,7 @@ public class MetricDataMapper { private static final Logger logger = LoggerFactory.getLogger(MetricDataMapper.class); private final BiConsumer telemetryInitializer; + private final boolean captureHttpServer4xxAsError; static { EXCLUDED_METRIC_NAMES.add("http.server.active_requests"); // Servlet @@ -66,8 +67,11 @@ public class MetricDataMapper { OTEL_PRE_AGGREGATED_METRIC_NAMES.add("rpc.server.duration"); // gRPC } - public MetricDataMapper(BiConsumer telemetryInitializer) { + public MetricDataMapper( + BiConsumer telemetryInitializer, + boolean captureHttpServer4xxAsError) { this.telemetryInitializer = telemetryInitializer; + this.captureHttpServer4xxAsError = captureHttpServer4xxAsError; } public void map(MetricData metricData, Consumer consumer) { @@ -101,7 +105,8 @@ private List convertOtelMetricToAzureMonitorMetric( telemetryInitializer.accept(builder, metricData.getResource()); builder.setTime(FormattedTime.offSetDateTimeFromEpochNanos(pointData.getEpochNanos())); - updateMetricPointBuilder(builder, metricData, pointData, isPreAggregated); + updateMetricPointBuilder( + builder, metricData, pointData, captureHttpServer4xxAsError, isPreAggregated); telemetryItems.add(builder.build()); } @@ -113,6 +118,7 @@ public static void updateMetricPointBuilder( MetricTelemetryBuilder metricTelemetryBuilder, MetricData metricData, PointData pointData, + boolean captureHttpServer4xxAsError, boolean isPreAggregated) { checkArgument(metricData != null, "MetricData cannot be null."); @@ -148,17 +154,33 @@ public static void updateMetricPointBuilder( pointBuilder.setName(metricData.getName()); metricTelemetryBuilder.setMetricPoint(pointBuilder); - pointData - .getAttributes() - .forEach( - (key, value) -> metricTelemetryBuilder.addProperty(key.getKey(), value.toString())); - if (isPreAggregated) { - // TODO update value + // TODO update value if applicable updatePreAggMetricsCustomDimensions( metricTelemetryBuilder, pointDataValue, - pointData.getAttributes().get(AttributeKey.stringKey("http.status_code"))); + pointData + .getAttributes() + .get(AttributeKey.stringKey(SemanticAttributes.HTTP_STATUS_CODE.toString())), + getSuccess(pointData, captureHttpServer4xxAsError)); + } else { + pointData + .getAttributes() + .forEach( + (key, value) -> metricTelemetryBuilder.addProperty(key.getKey(), value.toString())); + } + } + + private static boolean getSuccess(PointData pointData, boolean captureHttpServer4xxAsError) { + Long statusCode = + Long.valueOf( + pointData + .getAttributes() + .get(AttributeKey.stringKey(SemanticAttributes.HTTP_STATUS_CODE.toString()))); + if (captureHttpServer4xxAsError) { + return statusCode == null || statusCode < 400; } + + return statusCode == 200; } } diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestCustomDimensionsExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestCustomDimensionsExtractor.java index 7eac89314d6..77ce8de900b 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestCustomDimensionsExtractor.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestCustomDimensionsExtractor.java @@ -29,21 +29,24 @@ public final class RequestCustomDimensionsExtractor { // visible for testing - static final String REQUEST_METRIC_ID = "requests/duration"; - static final String MS_METRIC_ID = "_MS.metricId"; - static final String MS_IS_AUTOCOLLECTED = "_MS.IsAutocollected"; - static final String TRUE = "True"; - static final String FALSE = "False"; - static final String MS_PROCESSED_BY_METRIC_EXTRACTORS = "_MS.ProcessedByMetricExtractors"; - static final String PERFORMANCE_BUCKET = "request/performanceBucket"; - static final String REQUEST_RESULT_CODE = "request/resultCode"; - static final String OPERATION_SYNTHETIC = "operation/synthetic"; - static final String CLOUD_ROLE_NAME = "cloud/roleName"; - static final String CLOUD_ROLE_INSTANCE = "cloud/roleInstance"; - static final String REQUEST_SUCCESS = "request/success"; + public static final String MS_METRIC_ID = "_MS.metricId"; + public static final String REQUEST_METRIC_ID = "requests/duration"; + public static final String MS_IS_AUTOCOLLECTED = "_MS.IsAutocollected"; + public static final String TRUE = "True"; + public static final String FALSE = "False"; + public static final String MS_PROCESSED_BY_METRIC_EXTRACTORS = "_MS.ProcessedByMetricExtractors"; + public static final String PERFORMANCE_BUCKET = "request/performanceBucket"; + public static final String REQUEST_RESULT_CODE = "request/resultCode"; + public static final String OPERATION_SYNTHETIC = "operation/synthetic"; + public static final String CLOUD_ROLE_NAME = "cloud/roleName"; + public static final String CLOUD_ROLE_INSTANCE = "cloud/roleInstance"; + public static final String REQUEST_SUCCESS = "request/success"; public static void updatePreAggMetricsCustomDimensions( - AbstractTelemetryBuilder metricTelemetryBuilder, double value, String resultCode) { + AbstractTelemetryBuilder metricTelemetryBuilder, + double value, + String resultCode, + boolean success) { metricTelemetryBuilder.addProperty(MS_METRIC_ID, REQUEST_METRIC_ID); metricTelemetryBuilder.addProperty(MS_IS_AUTOCOLLECTED, TRUE); // this flag will inform the ingestion service to stop post-aggregation @@ -62,7 +65,7 @@ public static void updatePreAggMetricsCustomDimensions( .build() .getTags() .get(ContextTagKeys.AI_CLOUD_ROLE_INSTANCE.toString())); - metricTelemetryBuilder.addProperty(REQUEST_SUCCESS, TRUE); + metricTelemetryBuilder.addProperty(REQUEST_SUCCESS, success ? TRUE : FALSE); } private RequestCustomDimensionsExtractor() {} diff --git a/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/AzureMonitorMetricExporterTest.java b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/AzureMonitorMetricExporterTest.java index b1b0d463f1d..4d4cc24e3e8 100644 --- a/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/AzureMonitorMetricExporterTest.java +++ b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/AzureMonitorMetricExporterTest.java @@ -100,7 +100,8 @@ public void testDoubleCounter() throws InterruptedException { MetricData metricData = metricDatas.get(0); for (PointData pointData : metricData.getData().getPoints()) { MetricTelemetryBuilder builder = MetricTelemetryBuilder.create(); - MetricDataMapper.updateMetricPointBuilder(builder, metricDatas.get(0), pointData, false); + MetricDataMapper.updateMetricPointBuilder( + builder, metricDatas.get(0), pointData, true, false); MetricsData metricsData = (MetricsData) builder.build().getData().getBaseData(); assertThat(metricsData.getMetrics().size()).isEqualTo(1); assertThat(metricsData.getMetrics().get(0).getValue()).isEqualTo(3.1415); @@ -129,7 +130,7 @@ public void testDoubleGauge() throws InterruptedException { MetricData metricData = metricDataList.get(0); for (PointData pointData : metricData.getData().getPoints()) { MetricTelemetryBuilder builder = MetricTelemetryBuilder.create(); - MetricDataMapper.updateMetricPointBuilder(builder, metricData, pointData, false); + MetricDataMapper.updateMetricPointBuilder(builder, metricData, pointData, true, false); MetricsData metricsData = (MetricsData) builder.build().getData().getBaseData(); assertThat(metricsData.getMetrics().size()).isEqualTo(1); assertThat(metricsData.getMetrics().get(0).getValue()).isEqualTo(20.0); @@ -205,7 +206,7 @@ public void testLongCounter() throws InterruptedException { .isEqualTo("yellow"); MetricTelemetryBuilder builder = MetricTelemetryBuilder.create(); - MetricDataMapper.updateMetricPointBuilder(builder, metricData, longPointData1, false); + MetricDataMapper.updateMetricPointBuilder(builder, metricData, longPointData1, true, false); MetricsData metricsData = (MetricsData) builder.build().getData().getBaseData(); assertThat(metricsData.getMetrics().size()).isEqualTo(1); MetricDataPoint metricDataPoint = metricsData.getMetrics().get(0); @@ -217,7 +218,7 @@ public void testLongCounter() throws InterruptedException { assertThat(properties).containsEntry("color", "green"); builder = MetricTelemetryBuilder.create(); - MetricDataMapper.updateMetricPointBuilder(builder, metricData, longPointData2, false); + MetricDataMapper.updateMetricPointBuilder(builder, metricData, longPointData2, true, false); metricsData = (MetricsData) builder.build().getData().getBaseData(); assertThat(metricsData.getMetrics().size()).isEqualTo(1); metricDataPoint = metricsData.getMetrics().get(0); @@ -229,7 +230,7 @@ public void testLongCounter() throws InterruptedException { assertThat(properties).containsEntry("color", "red"); builder = MetricTelemetryBuilder.create(); - MetricDataMapper.updateMetricPointBuilder(builder, metricData, longPointData3, false); + MetricDataMapper.updateMetricPointBuilder(builder, metricData, longPointData3, true, false); metricsData = (MetricsData) builder.build().getData().getBaseData(); assertThat(metricsData.getMetrics().size()).isEqualTo(1); metricDataPoint = metricsData.getMetrics().get(0); @@ -264,7 +265,7 @@ public void testLongGauge() throws InterruptedException { MetricData metricData = metricDataList.get(0); for (PointData pointData : metricData.getData().getPoints()) { MetricTelemetryBuilder builder = MetricTelemetryBuilder.create(); - MetricDataMapper.updateMetricPointBuilder(builder, metricData, pointData, false); + MetricDataMapper.updateMetricPointBuilder(builder, metricData, pointData, true, false); MetricsData metricsData = (MetricsData) builder.build().getData().getBaseData(); assertThat(metricsData.getMetrics().size()).isEqualTo(1); assertThat(metricsData.getMetrics().get(0).getValue()).isEqualTo(20); @@ -295,7 +296,7 @@ public void testDoubleHistogram() throws InterruptedException { assertThat(metricData.getData().getPoints().size()).isEqualTo(1); PointData pointData = metricData.getData().getPoints().iterator().next(); MetricTelemetryBuilder builder = MetricTelemetryBuilder.create(); - MetricDataMapper.updateMetricPointBuilder(builder, metricData, pointData, false); + MetricDataMapper.updateMetricPointBuilder(builder, metricData, pointData, true, false); MetricsData metricsData = (MetricsData) builder.build().getData().getBaseData(); assertThat(metricsData.getMetrics().size()).isEqualTo(1); assertThat(metricsData.getMetrics().get(0).getCount()).isEqualTo(1); diff --git a/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java index b0a07a0ac9c..904c5b78512 100644 --- a/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java +++ b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java @@ -21,9 +21,26 @@ package com.azure.monitor.opentelemetry.exporter; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.CLOUD_ROLE_INSTANCE; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.CLOUD_ROLE_NAME; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.FALSE; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.MS_IS_AUTOCOLLECTED; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.MS_METRIC_ID; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.MS_PROCESSED_BY_METRIC_EXTRACTORS; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.OPERATION_SYNTHETIC; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.PERFORMANCE_BUCKET; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.REQUEST_METRIC_ID; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.REQUEST_RESULT_CODE; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.REQUEST_SUCCESS; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.TRUE; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; +import com.azure.monitor.opentelemetry.exporter.implementation.MetricDataMapper; +import com.azure.monitor.opentelemetry.exporter.implementation.builders.MetricTelemetryBuilder; +import com.azure.monitor.opentelemetry.exporter.implementation.models.ContextTagKeys; +import com.azure.monitor.opentelemetry.exporter.implementation.models.MetricsData; +import com.azure.monitor.opentelemetry.exporter.implementation.models.TelemetryItem; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.trace.Span; import io.opentelemetry.api.trace.SpanContext; @@ -37,6 +54,8 @@ import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.Collection; +import java.util.HashMap; +import java.util.Map; import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -54,7 +73,7 @@ void setup() { @SuppressWarnings("SystemOut") @Test - void collectHttpClientRMetric() { + void testHttpClientRequestDuration() { OperationListener listener = HttpClientMetrics.get().create(meterProvider.get("test")); Attributes requestAttributes = @@ -96,6 +115,8 @@ void collectHttpClientRMetric() { System.out.println("metric: " + metricData); } + assertThat(metricDataCollection.size()).isEqualTo(1); + assertThat(metricDataCollection) .satisfiesExactly( metric -> @@ -119,6 +140,28 @@ void collectHttpClientRMetric() { exemplar .hasTraceId("ff01020304050600ff0a0b0c0d0e0f00") .hasSpanId("090a0b0c0d0e0f00"))))); + + MetricTelemetryBuilder builder = MetricTelemetryBuilder.create(); + MetricData metricData = metricDataCollection.iterator().next(); + MetricDataMapper.updateMetricPointBuilder( + builder, metricData, metricData.getData().getPoints().iterator().next(), true, true); + TelemetryItem telemetryItem = builder.build(); + MetricsData metricsData = (MetricsData) telemetryItem.getData().getBaseData(); + Map expectedMap = new HashMap<>(); + expectedMap.put(MS_METRIC_ID, REQUEST_METRIC_ID); + expectedMap.put(MS_IS_AUTOCOLLECTED, TRUE); + expectedMap.put(MS_PROCESSED_BY_METRIC_EXTRACTORS, TRUE); + expectedMap.put(PERFORMANCE_BUCKET, "<250ms"); + expectedMap.put(REQUEST_RESULT_CODE, "200"); + expectedMap.put(OPERATION_SYNTHETIC, FALSE); + expectedMap.put( + CLOUD_ROLE_NAME, telemetryItem.getTags().get(ContextTagKeys.AI_CLOUD_ROLE.toString())); + expectedMap.put( + CLOUD_ROLE_INSTANCE, + telemetryItem.getTags().get(ContextTagKeys.AI_CLOUD_ROLE_INSTANCE.toString())); + expectedMap.put(REQUEST_SUCCESS, TRUE); + + assertThat(metricsData.getProperties()).containsExactlyInAnyOrderEntriesOf(expectedMap); } private static long nanos(int millis) { From a3b8fddb3efd23c2a65d6ca2e7b61e7742b76147 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Tue, 9 Aug 2022 19:25:33 -0700 Subject: [PATCH 08/95] Fix test --- .../implementation/MetricDataMapper.java | 14 +++----- .../DurationBucketizer.java | 5 +-- .../RequestCustomDimensionsExtractor.java | 30 ++++++++++------- .../exporter/PreAggregatedMetricsTest.java | 32 +++++++++++-------- 4 files changed, 44 insertions(+), 37 deletions(-) diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index 6a133992b16..4c5893720bc 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -156,13 +156,12 @@ public static void updateMetricPointBuilder( if (isPreAggregated) { // TODO update value if applicable + Long statusCode = pointData.getAttributes().get(AttributeKey.longKey("http.status_code")); updatePreAggMetricsCustomDimensions( metricTelemetryBuilder, pointDataValue, - pointData - .getAttributes() - .get(AttributeKey.stringKey(SemanticAttributes.HTTP_STATUS_CODE.toString())), - getSuccess(pointData, captureHttpServer4xxAsError)); + statusCode, + getSuccess(statusCode, captureHttpServer4xxAsError)); } else { pointData .getAttributes() @@ -171,12 +170,7 @@ public static void updateMetricPointBuilder( } } - private static boolean getSuccess(PointData pointData, boolean captureHttpServer4xxAsError) { - Long statusCode = - Long.valueOf( - pointData - .getAttributes() - .get(AttributeKey.stringKey(SemanticAttributes.HTTP_STATUS_CODE.toString()))); + private static boolean getSuccess(Long statusCode, boolean captureHttpServer4xxAsError) { if (captureHttpServer4xxAsError) { return statusCode == null || statusCode < 400; } diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DurationBucketizer.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DurationBucketizer.java index ada7c95e56c..8db61ef5f4c 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DurationBucketizer.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DurationBucketizer.java @@ -21,12 +21,13 @@ package com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics; -import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; public final class DurationBucketizer { - private static final Map performanceBuckets = new HashMap<>(); + // sorted HashMap + private static final Map performanceBuckets = new LinkedHashMap<>(); static { performanceBuckets.put("<250ms", 250.0); diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestCustomDimensionsExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestCustomDimensionsExtractor.java index 77ce8de900b..2bf9a04f1f5 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestCustomDimensionsExtractor.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestCustomDimensionsExtractor.java @@ -45,7 +45,7 @@ public final class RequestCustomDimensionsExtractor { public static void updatePreAggMetricsCustomDimensions( AbstractTelemetryBuilder metricTelemetryBuilder, double value, - String resultCode, + long statusCode, boolean success) { metricTelemetryBuilder.addProperty(MS_METRIC_ID, REQUEST_METRIC_ID); metricTelemetryBuilder.addProperty(MS_IS_AUTOCOLLECTED, TRUE); @@ -54,17 +54,25 @@ public static void updatePreAggMetricsCustomDimensions( // TODO figure out the correct duration/value metricTelemetryBuilder.addProperty(PERFORMANCE_BUCKET, getPerformanceBucket(value)); - metricTelemetryBuilder.addProperty(REQUEST_RESULT_CODE, resultCode); + metricTelemetryBuilder.addProperty(REQUEST_RESULT_CODE, String.valueOf(statusCode)); metricTelemetryBuilder.addProperty(OPERATION_SYNTHETIC, FALSE); - metricTelemetryBuilder.addProperty( - CLOUD_ROLE_NAME, - metricTelemetryBuilder.build().getTags().get(ContextTagKeys.AI_CLOUD_ROLE.toString())); - metricTelemetryBuilder.addProperty( - CLOUD_ROLE_INSTANCE, - metricTelemetryBuilder - .build() - .getTags() - .get(ContextTagKeys.AI_CLOUD_ROLE_INSTANCE.toString())); + + if (metricTelemetryBuilder.build().getTags() != null) { + String cloudName = + metricTelemetryBuilder.build().getTags().get(ContextTagKeys.AI_CLOUD_ROLE.toString()); + if (cloudName != null && !cloudName.isEmpty()) { + metricTelemetryBuilder.addProperty(CLOUD_ROLE_NAME, cloudName); + } + + String cloudRoleInstance = + metricTelemetryBuilder + .build() + .getTags() + .get(ContextTagKeys.AI_CLOUD_ROLE_INSTANCE.toString()); + if (cloudRoleInstance != null && !cloudRoleInstance.isEmpty()) { + metricTelemetryBuilder.addProperty(CLOUD_ROLE_INSTANCE, cloudRoleInstance); + } + } metricTelemetryBuilder.addProperty(REQUEST_SUCCESS, success ? TRUE : FALSE); } diff --git a/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java index 904c5b78512..cd4fbcee4cc 100644 --- a/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java +++ b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java @@ -21,8 +21,6 @@ package com.azure.monitor.opentelemetry.exporter; -import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.CLOUD_ROLE_INSTANCE; -import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.CLOUD_ROLE_NAME; import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.FALSE; import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.MS_IS_AUTOCOLLECTED; import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.MS_METRIC_ID; @@ -38,7 +36,6 @@ import com.azure.monitor.opentelemetry.exporter.implementation.MetricDataMapper; import com.azure.monitor.opentelemetry.exporter.implementation.builders.MetricTelemetryBuilder; -import com.azure.monitor.opentelemetry.exporter.implementation.models.ContextTagKeys; import com.azure.monitor.opentelemetry.exporter.implementation.models.MetricsData; import com.azure.monitor.opentelemetry.exporter.implementation.models.TelemetryItem; import io.opentelemetry.api.common.Attributes; @@ -147,6 +144,16 @@ void testHttpClientRequestDuration() { builder, metricData, metricData.getData().getPoints().iterator().next(), true, true); TelemetryItem telemetryItem = builder.build(); MetricsData metricsData = (MetricsData) telemetryItem.getData().getBaseData(); + + assertThat(metricsData.getProperties()) + .containsExactlyInAnyOrderEntriesOf(generateExpectedProperties()); + } + + private static long nanos(int millis) { + return TimeUnit.MILLISECONDS.toNanos(millis); + } + + private static Map generateExpectedProperties() { Map expectedMap = new HashMap<>(); expectedMap.put(MS_METRIC_ID, REQUEST_METRIC_ID); expectedMap.put(MS_IS_AUTOCOLLECTED, TRUE); @@ -154,17 +161,14 @@ void testHttpClientRequestDuration() { expectedMap.put(PERFORMANCE_BUCKET, "<250ms"); expectedMap.put(REQUEST_RESULT_CODE, "200"); expectedMap.put(OPERATION_SYNTHETIC, FALSE); - expectedMap.put( - CLOUD_ROLE_NAME, telemetryItem.getTags().get(ContextTagKeys.AI_CLOUD_ROLE.toString())); - expectedMap.put( - CLOUD_ROLE_INSTANCE, - telemetryItem.getTags().get(ContextTagKeys.AI_CLOUD_ROLE_INSTANCE.toString())); expectedMap.put(REQUEST_SUCCESS, TRUE); - - assertThat(metricsData.getProperties()).containsExactlyInAnyOrderEntriesOf(expectedMap); - } - - private static long nanos(int millis) { - return TimeUnit.MILLISECONDS.toNanos(millis); + // TODO test cloud_role_name and cloud_role_instance + // expectedMap.put( + // CLOUD_ROLE_NAME, + // telemetryItem.getTags().get(ContextTagKeys.AI_CLOUD_ROLE.toString())); + // expectedMap.put( + // CLOUD_ROLE_INSTANCE, + // telemetryItem.getTags().get(ContextTagKeys.AI_CLOUD_ROLE_INSTANCE.toString())); + return expectedMap; } } From e3144982c0170cf4cc0b574339acb35c3e552248 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Wed, 10 Aug 2022 11:01:37 -0700 Subject: [PATCH 09/95] Fix lgtm --- .../opentelemetry/exporter/implementation/MetricDataMapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index 4c5893720bc..a162b5e18d0 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -175,6 +175,6 @@ private static boolean getSuccess(Long statusCode, boolean captureHttpServer4xxA return statusCode == null || statusCode < 400; } - return statusCode == 200; + return true; } } From 58e50bd636a9b4f62f6889a642aeb62885c86c03 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Wed, 10 Aug 2022 16:38:06 -0700 Subject: [PATCH 10/95] Perf buckets --- agent/agent-bootstrap/build.gradle.kts | 4 + .../instrumenter/http/HttpServerMetrics.java | 150 ++++++++++++++++++ .../http/TemporaryMetricsView.java | 106 +++++++++++++ ...panExporterWithAttributeProcessorTest.java | 4 +- agent/agent/build.gradle.kts | 3 + 5 files changed, 265 insertions(+), 2 deletions(-) create mode 100644 agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java create mode 100644 agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java diff --git a/agent/agent-bootstrap/build.gradle.kts b/agent/agent-bootstrap/build.gradle.kts index ba1a62b8370..c018fef5266 100644 --- a/agent/agent-bootstrap/build.gradle.kts +++ b/agent/agent-bootstrap/build.gradle.kts @@ -7,6 +7,10 @@ dependencies { // needed to access io.opentelemetry.instrumentation.api.aisdk.MicrometerUtil // TODO (heya) remove this when updating to upstream micrometer instrumentation compileOnly("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api") + compileOnly("io.opentelemetry:opentelemetry-semconv") + + compileOnly("com.google.auto.value:auto-value-annotations") + annotationProcessor("com.google.auto.value:auto-value") implementation("ch.qos.logback:logback-classic") implementation("ch.qos.logback.contrib:logback-json-classic") diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java new file mode 100644 index 00000000000..d5800a06b69 --- /dev/null +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java @@ -0,0 +1,150 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.instrumenter.http; + +import static java.util.logging.Level.FINE; + +import com.google.auto.value.AutoValue; +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.metrics.DoubleHistogram; +import io.opentelemetry.api.metrics.LongHistogram; +import io.opentelemetry.api.metrics.LongUpDownCounter; +import io.opentelemetry.api.metrics.Meter; +import io.opentelemetry.context.Context; +import io.opentelemetry.context.ContextKey; +import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; +import io.opentelemetry.instrumentation.api.instrumenter.OperationMetrics; +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import java.util.concurrent.TimeUnit; +import java.util.logging.Logger; +import javax.annotation.Nullable; + +/** + * {@link OperationListener} which keeps track of HTTP + * server metrics. + */ +public final class HttpServerMetrics implements OperationListener { + + private static final double NANOS_PER_MS = TimeUnit.MILLISECONDS.toNanos(1); + + private static final ContextKey HTTP_SERVER_REQUEST_METRICS_STATE = + ContextKey.named("http-server-request-metrics-state"); + + private static final Logger logger = Logger.getLogger(HttpServerMetrics.class.getName()); + + /** + * Returns a {@link OperationMetrics} which can be used to enable recording of {@link + * HttpServerMetrics} on an {@link + * io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder}. + */ + public static OperationMetrics get() { + return HttpServerMetrics::new; + } + + private final LongUpDownCounter activeRequests; + private final DoubleHistogram duration; + private final LongHistogram requestSize; + private final LongHistogram responseSize; + + private HttpServerMetrics(Meter meter) { + activeRequests = + meter + .upDownCounterBuilder("http.server.active_requests") + .setUnit("requests") + .setDescription("The number of concurrent HTTP requests that are currently in-flight") + .build(); + + duration = + meter + .histogramBuilder("http.server.duration") + .setUnit("ms") + .setDescription("The duration of the inbound HTTP request") + .build(); + requestSize = + meter + .histogramBuilder("http.server.request.size") + .setUnit("By") + .setDescription("The size of HTTP request messages") + .ofLongs() + .build(); + responseSize = + meter + .histogramBuilder("http.server.response.size") + .setUnit("By") + .setDescription("The size of HTTP response messages") + .ofLongs() + .build(); + } + + @Override + public Context onStart(Context context, Attributes startAttributes, long startNanos) { + activeRequests.add(1, TemporaryMetricsView.applyActiveRequestsView(startAttributes), context); + + return context.with( + HTTP_SERVER_REQUEST_METRICS_STATE, + new AutoValue_HttpServerMetrics_State(startAttributes, startNanos)); + } + + @Override + public void onEnd(Context context, Attributes endAttributes, long endNanos) { + State state = context.get(HTTP_SERVER_REQUEST_METRICS_STATE); + if (state == null) { + logger.log( + FINE, + "No state present when ending context {0}. Cannot record HTTP request metrics.", + context); + return; + } + activeRequests.add( + -1, TemporaryMetricsView.applyActiveRequestsView(state.startAttributes()), context); + Attributes durationAndSizeAttributes = + TemporaryMetricsView.applyServerDurationAndSizeView(state.startAttributes(), endAttributes); + + long duration = endNanos - state.startTimeNanos(); + + durationAndSizeAttributes = + durationAndSizeAttributes.toBuilder() + .put("AI perf bucket", getAiPerfBucket(duration)) + .build(); + + this.duration.record(duration / NANOS_PER_MS, durationAndSizeAttributes, context); + Long requestLength = + getAttribute( + SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, endAttributes, state.startAttributes()); + if (requestLength != null) { + requestSize.record(requestLength, durationAndSizeAttributes); + } + Long responseLength = + getAttribute( + SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, + endAttributes, + state.startAttributes()); + if (responseLength != null) { + responseSize.record(responseLength, durationAndSizeAttributes); + } + } + + @Nullable + private static T getAttribute(AttributeKey key, Attributes... attributesList) { + for (Attributes attributes : attributesList) { + T value = attributes.get(key); + if (value != null) { + return value; + } + } + return null; + } + + @AutoValue + abstract static class State { + + abstract Attributes startAttributes(); + + abstract long startTimeNanos(); + } +} diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java new file mode 100644 index 00000000000..7dbcb9887de --- /dev/null +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java @@ -0,0 +1,106 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.instrumentation.api.instrumenter.http; + +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import java.util.HashSet; +import java.util.Set; +import java.util.function.BiConsumer; + +// this is temporary, see +// https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/3962#issuecomment-906606325 +@SuppressWarnings("rawtypes") +final class TemporaryMetricsView { + + private static final Set durationAlwaysInclude = buildDurationAlwaysInclude(); + private static final Set durationClientView = buildDurationClientView(); + private static final Set durationServerView = buildDurationServerView(); + private static final Set activeRequestsView = buildActiveRequestsView(); + + private static Set buildDurationAlwaysInclude() { + // the list of included metrics is from + // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/http-metrics.md#attributes + Set view = new HashSet<>(); + view.add(SemanticAttributes.HTTP_METHOD); + view.add(SemanticAttributes.HTTP_STATUS_CODE); // Optional + view.add(SemanticAttributes.HTTP_FLAVOR); // Optional + return view; + } + + private static Set buildDurationClientView() { + // We pull identifying attributes according to: + // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/http-metrics.md#attribute-alternatives + // We only pull net.peer.name and net.peer.port because http.url has too high cardinality + Set view = new HashSet<>(durationAlwaysInclude); + view.add(SemanticAttributes.NET_PEER_NAME); + view.add(SemanticAttributes.NET_PEER_PORT); + return view; + } + + private static Set buildDurationServerView() { + // We pull identifying attributes according to: + // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/http-metrics.md#attribute-alternatives + // With the following caveat: + // - we always rely on http.route + http.host in this repository. + // - we prefer http.route (which is scrubbed) over http.target (which is not scrubbed). + Set view = new HashSet<>(durationAlwaysInclude); + view.add(SemanticAttributes.HTTP_SCHEME); + view.add(SemanticAttributes.HTTP_HOST); + view.add(SemanticAttributes.HTTP_ROUTE); + return view; + } + + private static Set buildActiveRequestsView() { + // the list of included metrics is from + // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/http-metrics.md#attributes + Set view = new HashSet<>(); + view.add(SemanticAttributes.HTTP_METHOD); + view.add(SemanticAttributes.HTTP_HOST); + view.add(SemanticAttributes.HTTP_SCHEME); + view.add(SemanticAttributes.HTTP_FLAVOR); + view.add(SemanticAttributes.HTTP_SERVER_NAME); + return view; + } + + static Attributes applyClientDurationAndSizeView( + Attributes startAttributes, Attributes endAttributes) { + AttributesBuilder filtered = Attributes.builder(); + applyView(filtered, startAttributes, durationClientView); + applyView(filtered, endAttributes, durationClientView); + return filtered.build(); + } + + static Attributes applyServerDurationAndSizeView( + Attributes startAttributes, Attributes endAttributes) { + AttributesBuilder filtered = Attributes.builder(); + applyView(filtered, startAttributes, durationServerView); + applyView(filtered, endAttributes, durationServerView); + return filtered.build(); + } + + static Attributes applyActiveRequestsView(Attributes attributes) { + AttributesBuilder filtered = Attributes.builder(); + applyView(filtered, attributes, activeRequestsView); + return filtered.build(); + } + + @SuppressWarnings("unchecked") + private static void applyView( + AttributesBuilder filtered, Attributes attributes, Set view) { + attributes.forEach( + (BiConsumer) + (key, value) -> { + if (view.contains(key)) { + filtered.put(key, value); + } + }); + } + + private TemporaryMetricsView() {} +} diff --git a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/SpanExporterWithAttributeProcessorTest.java b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/SpanExporterWithAttributeProcessorTest.java index 971b933a21a..29859dbeecd 100644 --- a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/SpanExporterWithAttributeProcessorTest.java +++ b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/SpanExporterWithAttributeProcessorTest.java @@ -1373,7 +1373,7 @@ void actionInsertWithExtractTest() { SpanData resultSpan = result.get(0); assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("httpProtocol"))) - .isEqualTo("http"); + .isEqualTo("io/opentelemetry/instrumentation/api/instrumenter/http"); assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("httpDomain"))) .isEqualTo("example.com"); assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("httpPath"))) @@ -1420,7 +1420,7 @@ void actionInsertWithExtractDuplicateTest() { SpanData resultSpan = result.get(0); assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("httpProtocol"))) - .isEqualTo("http"); + .isEqualTo("io/opentelemetry/instrumentation/api/instrumenter/http"); assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("httpDomain"))) .isEqualTo("example.com"); assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("httpPath"))) diff --git a/agent/agent/build.gradle.kts b/agent/agent/build.gradle.kts index 307eada80fd..554c965d108 100644 --- a/agent/agent/build.gradle.kts +++ b/agent/agent/build.gradle.kts @@ -113,6 +113,9 @@ tasks { // into this package yet at the time exclusion takes place exclude("io/opentelemetry/javaagent/slf4j/impl/**") + exclude("io/opentelemetry/javaagent/shaded/instrumentation/api/instrumenter/http/HttpServerMetrics.class") + exclude("io/opentelemetry/javaagent/shaded/instrumentation/api/instrumenter/http/TemporaryMetricsView.class") + dependsOn(isolateJavaagentLibs) from(isolateJavaagentLibs.get().outputs) From d448696b9d1eca2fb8dd3f9dcb4a442232734ccf Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Wed, 10 Aug 2022 17:44:11 -0700 Subject: [PATCH 11/95] Hack httpservermetric onEnd --- .../agent/bootstrap}/DurationBucketizer.java | 28 +++++++++---------- .../instrumenter/http/HttpServerMetrics.java | 3 +- .../implementation/MetricDataMapper.java | 2 +- .../RequestCustomDimensionsExtractor.java | 6 ++-- 4 files changed, 19 insertions(+), 20 deletions(-) rename agent/{azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics => agent-bootstrap/src/main/java/com/microsoft/applicationinsights/agent/bootstrap}/DurationBucketizer.java (65%) diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DurationBucketizer.java b/agent/agent-bootstrap/src/main/java/com/microsoft/applicationinsights/agent/bootstrap/DurationBucketizer.java similarity index 65% rename from agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DurationBucketizer.java rename to agent/agent-bootstrap/src/main/java/com/microsoft/applicationinsights/agent/bootstrap/DurationBucketizer.java index 8db61ef5f4c..3a4543a5f6f 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DurationBucketizer.java +++ b/agent/agent-bootstrap/src/main/java/com/microsoft/applicationinsights/agent/bootstrap/DurationBucketizer.java @@ -19,7 +19,7 @@ * DEALINGS IN THE SOFTWARE. */ -package com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics; +package com.microsoft.applicationinsights.agent.bootstrap; import java.util.LinkedHashMap; import java.util.Map; @@ -27,24 +27,24 @@ public final class DurationBucketizer { // sorted HashMap - private static final Map performanceBuckets = new LinkedHashMap<>(); + private static final Map performanceBuckets = new LinkedHashMap<>(); static { - performanceBuckets.put("<250ms", 250.0); - performanceBuckets.put("250ms-500ms", 500.0); - performanceBuckets.put("500ms-1sec", 1000.0); - performanceBuckets.put("1sec-3sec", 3000.0); - performanceBuckets.put("3sec-7sec", 7000.0); - performanceBuckets.put("7sec-15sec", 15000.0); - performanceBuckets.put("15sec-30sec", 30000.0); - performanceBuckets.put("30sec-1min", 60000.0); - performanceBuckets.put("1min-2min", 120000.0); - performanceBuckets.put("2min-5min", 300000.0); - performanceBuckets.put(">=5min", Double.MAX_VALUE); + performanceBuckets.put("<250ms", 250L); + performanceBuckets.put("250ms-500ms", 500L); + performanceBuckets.put("500ms-1sec", 1000L); + performanceBuckets.put("1sec-3sec", 3000L); + performanceBuckets.put("3sec-7sec", 7000L); + performanceBuckets.put("7sec-15sec", 15000L); + performanceBuckets.put("15sec-30sec", 30000L); + performanceBuckets.put("30sec-1min", 60000L); + performanceBuckets.put("1min-2min", 120000L); + performanceBuckets.put("2min-5min", 300000L); + performanceBuckets.put(">=5min", Long.MAX_VALUE); } public static String getPerformanceBucket(double durationInMillis) { - for (Map.Entry entry : performanceBuckets.entrySet()) { + for (Map.Entry entry : performanceBuckets.entrySet()) { if (durationInMillis < entry.getValue()) { return entry.getKey(); } diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java index d5800a06b69..79a144d9bd9 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java @@ -8,6 +8,7 @@ import static java.util.logging.Level.FINE; import com.google.auto.value.AutoValue; +import com.microsoft.applicationinsights.agent.bootstrap.DurationBucketizer; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.metrics.DoubleHistogram; @@ -109,7 +110,7 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { durationAndSizeAttributes = durationAndSizeAttributes.toBuilder() - .put("AI perf bucket", getAiPerfBucket(duration)) + .put("ai.performance.bucket", DurationBucketizer.getPerformanceBucket(duration)) .build(); this.duration.record(duration / NANOS_PER_MS, durationAndSizeAttributes, context); diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index a162b5e18d0..0422933e654 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -159,7 +159,7 @@ public static void updateMetricPointBuilder( Long statusCode = pointData.getAttributes().get(AttributeKey.longKey("http.status_code")); updatePreAggMetricsCustomDimensions( metricTelemetryBuilder, - pointDataValue, + pointData.getAttributes().get(AttributeKey.stringKey("ai.performance.bucket")), statusCode, getSuccess(statusCode, captureHttpServer4xxAsError)); } else { diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestCustomDimensionsExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestCustomDimensionsExtractor.java index 2bf9a04f1f5..b7f7fef26b2 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestCustomDimensionsExtractor.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestCustomDimensionsExtractor.java @@ -21,8 +21,6 @@ package com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics; -import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.DurationBucketizer.getPerformanceBucket; - import com.azure.monitor.opentelemetry.exporter.implementation.builders.AbstractTelemetryBuilder; import com.azure.monitor.opentelemetry.exporter.implementation.models.ContextTagKeys; @@ -44,7 +42,7 @@ public final class RequestCustomDimensionsExtractor { public static void updatePreAggMetricsCustomDimensions( AbstractTelemetryBuilder metricTelemetryBuilder, - double value, + String perfBucket, long statusCode, boolean success) { metricTelemetryBuilder.addProperty(MS_METRIC_ID, REQUEST_METRIC_ID); @@ -53,7 +51,7 @@ public static void updatePreAggMetricsCustomDimensions( metricTelemetryBuilder.addProperty(MS_PROCESSED_BY_METRIC_EXTRACTORS, TRUE); // TODO figure out the correct duration/value - metricTelemetryBuilder.addProperty(PERFORMANCE_BUCKET, getPerformanceBucket(value)); + metricTelemetryBuilder.addProperty(PERFORMANCE_BUCKET, perfBucket); metricTelemetryBuilder.addProperty(REQUEST_RESULT_CODE, String.valueOf(statusCode)); metricTelemetryBuilder.addProperty(OPERATION_SYNTHETIC, FALSE); From 308b5e17aa26d61ca0f7bb190470433535ece25b Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Wed, 10 Aug 2022 17:45:48 -0700 Subject: [PATCH 12/95] Fix spotless --- .../instrumenter/http/HttpServerMetrics.java | 20 +++++++++++++++++-- .../http/TemporaryMetricsView.java | 20 +++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java index 79a144d9bd9..52bf3419301 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java @@ -1,6 +1,22 @@ /* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 + * ApplicationInsights-Java + * Copyright (c) Microsoft Corporation + * All rights reserved. + * + * MIT License + * Permission is hereby granted, free of charge, to any person obtaining a copy of this + * software and associated documentation files (the ""Software""), to deal in the Software + * without restriction, including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, and to permit + * persons to whom the Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. */ package io.opentelemetry.instrumentation.api.instrumenter.http; diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java index 7dbcb9887de..01f5f8e4a52 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java @@ -1,6 +1,22 @@ /* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 + * ApplicationInsights-Java + * Copyright (c) Microsoft Corporation + * All rights reserved. + * + * MIT License + * Permission is hereby granted, free of charge, to any person obtaining a copy of this + * software and associated documentation files (the ""Software""), to deal in the Software + * without restriction, including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, and to permit + * persons to whom the Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. */ package io.opentelemetry.instrumentation.api.instrumenter.http; From 0be0aa6d85eb277ed53a2f2d0185a5333d054fc5 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Wed, 10 Aug 2022 18:16:50 -0700 Subject: [PATCH 13/95] Shade HttpClientMetrics --- .../agent/bootstrap/DurationBucketizer.java | 2 + .../instrumenter/http/HttpClientMetrics.java | 135 ++++++++++++++++++ .../instrumenter/http/HttpServerMetrics.java | 5 +- .../http/TemporaryMetricsView.java | 3 + agent/agent/build.gradle.kts | 1 + 5 files changed, 144 insertions(+), 2 deletions(-) create mode 100644 agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java diff --git a/agent/agent-bootstrap/src/main/java/com/microsoft/applicationinsights/agent/bootstrap/DurationBucketizer.java b/agent/agent-bootstrap/src/main/java/com/microsoft/applicationinsights/agent/bootstrap/DurationBucketizer.java index 3a4543a5f6f..5fb5c08a2fb 100644 --- a/agent/agent-bootstrap/src/main/java/com/microsoft/applicationinsights/agent/bootstrap/DurationBucketizer.java +++ b/agent/agent-bootstrap/src/main/java/com/microsoft/applicationinsights/agent/bootstrap/DurationBucketizer.java @@ -26,6 +26,8 @@ public final class DurationBucketizer { + public static final String AI_PERFORMANCE_BUCKET = "ai.performance.bucket"; + // sorted HashMap private static final Map performanceBuckets = new LinkedHashMap<>(); diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java new file mode 100644 index 00000000000..287986c47a6 --- /dev/null +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java @@ -0,0 +1,135 @@ +package io.opentelemetry.instrumentation.api.instrumenter.http; + +import static com.microsoft.applicationinsights.agent.bootstrap.DurationBucketizer.AI_PERFORMANCE_BUCKET; +import static io.opentelemetry.instrumentation.api.instrumenter.http.TemporaryMetricsView.applyClientDurationAndSizeView; +import static java.util.logging.Level.FINE; + +import com.google.auto.value.AutoValue; +import com.microsoft.applicationinsights.agent.bootstrap.DurationBucketizer; +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.metrics.DoubleHistogram; +import io.opentelemetry.api.metrics.LongHistogram; +import io.opentelemetry.api.metrics.Meter; +import io.opentelemetry.context.Context; +import io.opentelemetry.context.ContextKey; +import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; +import io.opentelemetry.instrumentation.api.instrumenter.OperationMetrics; +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import java.util.concurrent.TimeUnit; +import java.util.logging.Logger; +import javax.annotation.Nullable; + +/** + * {@link OperationListener} which keeps track of HTTP + * client metrics. + */ +public final class HttpClientMetrics implements OperationListener { + + private static final double NANOS_PER_MS = TimeUnit.MILLISECONDS.toNanos(1); + + private static final ContextKey HTTP_CLIENT_REQUEST_METRICS_STATE = + ContextKey.named("http-client-request-metrics-state"); + + private static final Logger logger = Logger.getLogger(HttpClientMetrics.class.getName()); + + /** + * Returns a {@link OperationMetrics} which can be used to enable recording of {@link + * HttpClientMetrics} on an {@link + * io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder}. + */ + public static OperationMetrics get() { + return HttpClientMetrics::new; + } + + private final DoubleHistogram duration; + private final LongHistogram requestSize; + private final LongHistogram responseSize; + + private HttpClientMetrics(Meter meter) { + duration = + meter + .histogramBuilder("http.client.duration") + .setUnit("ms") + .setDescription("The duration of the outbound HTTP request") + .build(); + requestSize = + meter + .histogramBuilder("http.client.request.size") + .setUnit("By") + .setDescription("The size of HTTP request messages") + .ofLongs() + .build(); + responseSize = + meter + .histogramBuilder("http.client.response.size") + .setUnit("By") + .setDescription("The size of HTTP response messages") + .ofLongs() + .build(); + } + + @Override + public Context onStart(Context context, Attributes startAttributes, long startNanos) { + return context.with( + HTTP_CLIENT_REQUEST_METRICS_STATE, + new AutoValue_HttpClientMetrics_State(startAttributes, startNanos)); + } + + @Override + public void onEnd(Context context, Attributes endAttributes, long endNanos) { + State state = context.get(HTTP_CLIENT_REQUEST_METRICS_STATE); + if (state == null) { + logger.log( + FINE, + "No state present when ending context {0}. Cannot record HTTP request metrics.", + context); + return; + } + Attributes durationAndSizeAttributes = + applyClientDurationAndSizeView(state.startAttributes(), endAttributes); + + long duration = endNanos - state.startTimeNanos(); + logger.log(FINE, "################# HttpClientMetrics::duration: " + duration); + durationAndSizeAttributes = + durationAndSizeAttributes.toBuilder() + .put(AI_PERFORMANCE_BUCKET, DurationBucketizer.getPerformanceBucket(duration)) + .build(); + + this.duration.record(duration / NANOS_PER_MS, durationAndSizeAttributes, context); + Long requestLength = + getAttribute( + SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, endAttributes, state.startAttributes()); + if (requestLength != null) { + requestSize.record(requestLength, durationAndSizeAttributes); + } + Long responseLength = + getAttribute( + SemanticAttributes.HTTP_RESPONSE_CONTENT_LENGTH, + endAttributes, + state.startAttributes()); + if (responseLength != null) { + responseSize.record(responseLength, durationAndSizeAttributes); + } + } + + @Nullable + private static T getAttribute(AttributeKey key, Attributes... attributesList) { + for (Attributes attributes : attributesList) { + T value = attributes.get(key); + if (value != null) { + return value; + } + } + return null; + } + + @AutoValue + abstract static class State { + + abstract Attributes startAttributes(); + + abstract long startTimeNanos(); + } +} \ No newline at end of file diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java index 52bf3419301..ea30649e03d 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java @@ -21,6 +21,7 @@ package io.opentelemetry.instrumentation.api.instrumenter.http; +import static com.microsoft.applicationinsights.agent.bootstrap.DurationBucketizer.AI_PERFORMANCE_BUCKET; import static java.util.logging.Level.FINE; import com.google.auto.value.AutoValue; @@ -123,10 +124,10 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { TemporaryMetricsView.applyServerDurationAndSizeView(state.startAttributes(), endAttributes); long duration = endNanos - state.startTimeNanos(); - + logger.log(FINE, "################# HttpServerMetrics::duration: " + duration); durationAndSizeAttributes = durationAndSizeAttributes.toBuilder() - .put("ai.performance.bucket", DurationBucketizer.getPerformanceBucket(duration)) + .put(AI_PERFORMANCE_BUCKET, DurationBucketizer.getPerformanceBucket(duration)) .build(); this.duration.record(duration / NANOS_PER_MS, durationAndSizeAttributes, context); diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java index 01f5f8e4a52..f5837339abc 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java @@ -29,6 +29,8 @@ import java.util.Set; import java.util.function.BiConsumer; +import static com.microsoft.applicationinsights.agent.bootstrap.DurationBucketizer.AI_PERFORMANCE_BUCKET; + // this is temporary, see // https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/3962#issuecomment-906606325 @SuppressWarnings("rawtypes") @@ -44,6 +46,7 @@ private static Set buildDurationAlwaysInclude() { // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/http-metrics.md#attributes Set view = new HashSet<>(); view.add(SemanticAttributes.HTTP_METHOD); +// view.add(AttributeKey.stringKey(AI_PERFORMANCE_BUCKET)); view.add(SemanticAttributes.HTTP_STATUS_CODE); // Optional view.add(SemanticAttributes.HTTP_FLAVOR); // Optional return view; diff --git a/agent/agent/build.gradle.kts b/agent/agent/build.gradle.kts index 554c965d108..a1f2c110efe 100644 --- a/agent/agent/build.gradle.kts +++ b/agent/agent/build.gradle.kts @@ -113,6 +113,7 @@ tasks { // into this package yet at the time exclusion takes place exclude("io/opentelemetry/javaagent/slf4j/impl/**") + exclude("io/opentelemetry/javaagent/shaded/instrumentation/api/instrumenter/http/HttpClientMetrics.class") exclude("io/opentelemetry/javaagent/shaded/instrumentation/api/instrumenter/http/HttpServerMetrics.class") exclude("io/opentelemetry/javaagent/shaded/instrumentation/api/instrumenter/http/TemporaryMetricsView.class") From 17794bf0bc9704e81cb0a13898b9f0039ed83d86 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Wed, 10 Aug 2022 18:22:09 -0700 Subject: [PATCH 14/95] Fix conversion --- .../agent/bootstrap/DurationBucketizer.java | 2 +- .../instrumenter/http/HttpClientMetrics.java | 23 ++++++++++++++++++- .../http/TemporaryMetricsView.java | 4 +--- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/agent/agent-bootstrap/src/main/java/com/microsoft/applicationinsights/agent/bootstrap/DurationBucketizer.java b/agent/agent-bootstrap/src/main/java/com/microsoft/applicationinsights/agent/bootstrap/DurationBucketizer.java index 5fb5c08a2fb..d7e9e47b96e 100644 --- a/agent/agent-bootstrap/src/main/java/com/microsoft/applicationinsights/agent/bootstrap/DurationBucketizer.java +++ b/agent/agent-bootstrap/src/main/java/com/microsoft/applicationinsights/agent/bootstrap/DurationBucketizer.java @@ -45,7 +45,7 @@ public final class DurationBucketizer { performanceBuckets.put(">=5min", Long.MAX_VALUE); } - public static String getPerformanceBucket(double durationInMillis) { + public static String getPerformanceBucket(long durationInMillis) { for (Map.Entry entry : performanceBuckets.entrySet()) { if (durationInMillis < entry.getValue()) { return entry.getKey(); diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java index 287986c47a6..abb0bc56343 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java @@ -1,3 +1,24 @@ +/* + * ApplicationInsights-Java + * Copyright (c) Microsoft Corporation + * All rights reserved. + * + * MIT License + * Permission is hereby granted, free of charge, to any person obtaining a copy of this + * software and associated documentation files (the ""Software""), to deal in the Software + * without restriction, including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, and to permit + * persons to whom the Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + package io.opentelemetry.instrumentation.api.instrumenter.http; import static com.microsoft.applicationinsights.agent.bootstrap.DurationBucketizer.AI_PERFORMANCE_BUCKET; @@ -132,4 +153,4 @@ abstract static class State { abstract long startTimeNanos(); } -} \ No newline at end of file +} diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java index f5837339abc..6e7566b3e0f 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java @@ -29,8 +29,6 @@ import java.util.Set; import java.util.function.BiConsumer; -import static com.microsoft.applicationinsights.agent.bootstrap.DurationBucketizer.AI_PERFORMANCE_BUCKET; - // this is temporary, see // https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/3962#issuecomment-906606325 @SuppressWarnings("rawtypes") @@ -46,7 +44,7 @@ private static Set buildDurationAlwaysInclude() { // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/http-metrics.md#attributes Set view = new HashSet<>(); view.add(SemanticAttributes.HTTP_METHOD); -// view.add(AttributeKey.stringKey(AI_PERFORMANCE_BUCKET)); + // view.add(AttributeKey.stringKey(AI_PERFORMANCE_BUCKET)); view.add(SemanticAttributes.HTTP_STATUS_CODE); // Optional view.add(SemanticAttributes.HTTP_FLAVOR); // Optional return view; From 18156e658c98bc5a016d1d8906f8933fd6a09836 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Wed, 10 Aug 2022 18:57:59 -0700 Subject: [PATCH 15/95] Disable performanceBucket in unit test --- .../opentelemetry/exporter/PreAggregatedMetricsTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java index cd4fbcee4cc..00ca3b57afe 100644 --- a/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java +++ b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java @@ -26,7 +26,6 @@ import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.MS_METRIC_ID; import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.MS_PROCESSED_BY_METRIC_EXTRACTORS; import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.OPERATION_SYNTHETIC; -import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.PERFORMANCE_BUCKET; import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.REQUEST_METRIC_ID; import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.REQUEST_RESULT_CODE; import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.REQUEST_SUCCESS; @@ -158,7 +157,8 @@ private static Map generateExpectedProperties() { expectedMap.put(MS_METRIC_ID, REQUEST_METRIC_ID); expectedMap.put(MS_IS_AUTOCOLLECTED, TRUE); expectedMap.put(MS_PROCESSED_BY_METRIC_EXTRACTORS, TRUE); - expectedMap.put(PERFORMANCE_BUCKET, "<250ms"); + // TODO performance market is updated in HttpClientMetrics + // expectedMap.put(PERFORMANCE_BUCKET, "<250ms"); expectedMap.put(REQUEST_RESULT_CODE, "200"); expectedMap.put(OPERATION_SYNTHETIC, FALSE); expectedMap.put(REQUEST_SUCCESS, TRUE); From b38b24f16710853b16540853e3e14529bc4c8100 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 11 Aug 2022 15:21:43 -0700 Subject: [PATCH 16/95] Validate pre-agg in smoke test --- .../agent/bootstrap/DurationBucketizer.java | 28 +++---- .../instrumenter/http/HttpClientMetrics.java | 8 +- .../instrumenter/http/HttpServerMetrics.java | 4 +- .../smoketest/DurationBucketizer.java | 59 ++++++++++++++ .../smoketest/HttpClientSmokeTest.java | 79 +++++++++++++++++++ .../resources/applicationinsights.json | 10 +++ 6 files changed, 169 insertions(+), 19 deletions(-) create mode 100644 smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/DurationBucketizer.java create mode 100644 smoke-tests/apps/HttpClients/src/smokeTest/resources/applicationinsights.json diff --git a/agent/agent-bootstrap/src/main/java/com/microsoft/applicationinsights/agent/bootstrap/DurationBucketizer.java b/agent/agent-bootstrap/src/main/java/com/microsoft/applicationinsights/agent/bootstrap/DurationBucketizer.java index d7e9e47b96e..7070b00c677 100644 --- a/agent/agent-bootstrap/src/main/java/com/microsoft/applicationinsights/agent/bootstrap/DurationBucketizer.java +++ b/agent/agent-bootstrap/src/main/java/com/microsoft/applicationinsights/agent/bootstrap/DurationBucketizer.java @@ -29,24 +29,24 @@ public final class DurationBucketizer { public static final String AI_PERFORMANCE_BUCKET = "ai.performance.bucket"; // sorted HashMap - private static final Map performanceBuckets = new LinkedHashMap<>(); + private static final Map performanceBuckets = new LinkedHashMap<>(); static { - performanceBuckets.put("<250ms", 250L); - performanceBuckets.put("250ms-500ms", 500L); - performanceBuckets.put("500ms-1sec", 1000L); - performanceBuckets.put("1sec-3sec", 3000L); - performanceBuckets.put("3sec-7sec", 7000L); - performanceBuckets.put("7sec-15sec", 15000L); - performanceBuckets.put("15sec-30sec", 30000L); - performanceBuckets.put("30sec-1min", 60000L); - performanceBuckets.put("1min-2min", 120000L); - performanceBuckets.put("2min-5min", 300000L); - performanceBuckets.put(">=5min", Long.MAX_VALUE); + performanceBuckets.put("<250ms", 250d); + performanceBuckets.put("250ms-500ms", 500d); + performanceBuckets.put("500ms-1sec", 1000d); + performanceBuckets.put("1sec-3sec", 3000d); + performanceBuckets.put("3sec-7sec", 7000d); + performanceBuckets.put("7sec-15sec", 15000d); + performanceBuckets.put("15sec-30sec", 30000d); + performanceBuckets.put("30sec-1min", 60000d); + performanceBuckets.put("1min-2min", 120000d); + performanceBuckets.put("2min-5min", 300000d); + performanceBuckets.put(">=5min", Double.MAX_VALUE); } - public static String getPerformanceBucket(long durationInMillis) { - for (Map.Entry entry : performanceBuckets.entrySet()) { + public static String getPerformanceBucket(double durationInMillis) { + for (Map.Entry entry : performanceBuckets.entrySet()) { if (durationInMillis < entry.getValue()) { return entry.getKey(); } diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java index abb0bc56343..30f6840e15e 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java @@ -111,14 +111,16 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { Attributes durationAndSizeAttributes = applyClientDurationAndSizeView(state.startAttributes(), endAttributes); - long duration = endNanos - state.startTimeNanos(); - logger.log(FINE, "################# HttpClientMetrics::duration: " + duration); + double duration = (endNanos - state.startTimeNanos()) / NANOS_PER_MS; + System.out.println("################# HttpClientMetrics::duration: " + duration); + System.out.println( + "################# perfBucket: " + DurationBucketizer.getPerformanceBucket(duration)); durationAndSizeAttributes = durationAndSizeAttributes.toBuilder() .put(AI_PERFORMANCE_BUCKET, DurationBucketizer.getPerformanceBucket(duration)) .build(); - this.duration.record(duration / NANOS_PER_MS, durationAndSizeAttributes, context); + this.duration.record(duration, durationAndSizeAttributes, context); Long requestLength = getAttribute( SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, endAttributes, state.startAttributes()); diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java index ea30649e03d..747d1497d05 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java @@ -123,14 +123,14 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { Attributes durationAndSizeAttributes = TemporaryMetricsView.applyServerDurationAndSizeView(state.startAttributes(), endAttributes); - long duration = endNanos - state.startTimeNanos(); + double duration = (endNanos - state.startTimeNanos()) / NANOS_PER_MS; logger.log(FINE, "################# HttpServerMetrics::duration: " + duration); durationAndSizeAttributes = durationAndSizeAttributes.toBuilder() .put(AI_PERFORMANCE_BUCKET, DurationBucketizer.getPerformanceBucket(duration)) .build(); - this.duration.record(duration / NANOS_PER_MS, durationAndSizeAttributes, context); + this.duration.record(duration, durationAndSizeAttributes, context); Long requestLength = getAttribute( SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, endAttributes, state.startAttributes()); diff --git a/smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/DurationBucketizer.java b/smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/DurationBucketizer.java new file mode 100644 index 00000000000..82dccddc57e --- /dev/null +++ b/smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/DurationBucketizer.java @@ -0,0 +1,59 @@ +/* + * ApplicationInsights-Java + * Copyright (c) Microsoft Corporation + * All rights reserved. + * + * MIT License + * Permission is hereby granted, free of charge, to any person obtaining a copy of this + * software and associated documentation files (the ""Software""), to deal in the Software + * without restriction, including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, and to permit + * persons to whom the Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package com.microsoft.applicationinsights.smoketest; + +import java.util.LinkedHashMap; +import java.util.Map; + +// copied from link{com.microsoft.applicationinsights.agent.bootstrap.DurationBucketizer} +public final class DurationBucketizer { + + public static final String AI_PERFORMANCE_BUCKET = "ai.performance.bucket"; + + // sorted HashMap + private static final Map performanceBuckets = new LinkedHashMap<>(); + + static { + performanceBuckets.put("<250ms", 250d); + performanceBuckets.put("250ms-500ms", 500d); + performanceBuckets.put("500ms-1sec", 1000d); + performanceBuckets.put("1sec-3sec", 3000d); + performanceBuckets.put("3sec-7sec", 7000d); + performanceBuckets.put("7sec-15sec", 15000d); + performanceBuckets.put("15sec-30sec", 30000d); + performanceBuckets.put("30sec-1min", 60000d); + performanceBuckets.put("1min-2min", 120000d); + performanceBuckets.put("2min-5min", 300000d); + performanceBuckets.put(">=5min", Double.MAX_VALUE); + } + + public static String getPerformanceBucket(double durationInMillis) { + for (Map.Entry entry : performanceBuckets.entrySet()) { + if (durationInMillis < entry.getValue()) { + return entry.getKey(); + } + } + return ">=5min"; + } + + private DurationBucketizer() {} +} diff --git a/smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpClientSmokeTest.java b/smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpClientSmokeTest.java index 779be3cfb6b..cb87a727bc1 100644 --- a/smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpClientSmokeTest.java +++ b/smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpClientSmokeTest.java @@ -32,6 +32,14 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9; import static org.assertj.core.api.Assertions.assertThat; +import com.microsoft.applicationinsights.smoketest.schemav2.Data; +import com.microsoft.applicationinsights.smoketest.schemav2.DataPoint; +import com.microsoft.applicationinsights.smoketest.schemav2.Envelope; +import com.microsoft.applicationinsights.smoketest.schemav2.MetricData; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -134,6 +142,77 @@ private static void verify(String successUrlWithQueryString) throws Exception { telemetry.rd, telemetry.rdEnvelope, telemetry.rddEnvelope2, "GET /HttpClients/*"); SmokeTestExtension.assertParentChild( telemetry.rd, telemetry.rdEnvelope, telemetry.rddEnvelope3, "GET /HttpClients/*"); + + verifyPreAggregatedMetrics("http.client.duration"); + } + + private static void verifyPreAggregatedMetrics(String name) throws Exception { + List metrics = + testing.mockedIngestion.waitForItems( + SmokeTestExtension.getMetricPredicate(name), 3, 40, TimeUnit.SECONDS); + + // sort metrics based on result code + metrics.sort( + Comparator.comparing( + obj -> { + MetricData metricData = (MetricData) ((Data) obj.getData()).getBaseData(); + return metricData.getProperties().get("request/resultCode"); + })); + + // 1st pre-aggregated metric + Envelope envelope1 = metrics.get(0); + validateTags(envelope1); + MetricData md1 = (MetricData) ((Data) envelope1.getData()).getBaseData(); + validateMetricData(md1, "200"); + + // 2nd pre-aggregated metric + Envelope envelope2 = metrics.get(1); + validateTags(envelope2); + MetricData md2 = (MetricData) ((Data) envelope2.getData()).getBaseData(); + validateMetricData(md2, "404"); + + // 3rd pre-aggregated metric + Envelope envelope3 = metrics.get(2); + validateTags(envelope3); + MetricData md3 = (MetricData) ((Data) envelope3.getData()).getBaseData(); + validateMetricData(md3, "500"); + } + + private static void validateTags(Envelope envelope) { + Map tags = envelope.getTags(); + assertThat(tags.get("ai.internal.sdkVersion")).isNotNull(); + assertThat(tags).containsEntry("ai.cloud.roleInstance", "testroleinstance"); + assertThat(tags).containsEntry("ai.cloud.role", "testrolename"); + } + + private static void validateMetricData(MetricData metricData, String resultCode) { + List dataPoints = metricData.getMetrics(); + assertThat(dataPoints).hasSize(1); + DataPoint dataPoint = dataPoints.get(0); + assertThat(dataPoint.getCount()).isEqualTo(1); + assertThat(dataPoint.getValue()).isGreaterThan(0d).isLessThan(5 * 60 * 1000d); // (0 - 5) min + assertThat(dataPoint.getMin()).isGreaterThan(0d).isLessThan(5 * 60 * 1000d); // (0 - 5) min + assertThat(dataPoint.getMin()).isGreaterThan(0d).isLessThan(5 * 60 * 1000d); // (0 - 5) min + Map properties = metricData.getProperties(); + assertThat(properties.get("request/resultCode")).isEqualTo(resultCode); + + double value = metricData.getMetrics().get(0).getValue(); + assertThat(properties.get("request/performanceBucket")).isEqualTo(getPerformanceBucket(value)); + if ("200".equals(resultCode)) { + assertThat(properties.get("request/success")).isEqualTo("True"); + } else { + assertThat(properties.get("request/success")).isEqualTo("False"); + } + assertThat(properties.get("operation/synthetic")).isEqualTo("False"); + assertThat(properties.get("_MS.metricId")).isEqualTo("requests/duration"); + assertThat(properties.get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(properties.get("cloud/roleInstance")).isEqualTo("testoleinstance"); + assertThat(properties.get("cloud/roleName")).isEqualTo("testrolename"); + assertThat(properties.get("_MS.IsAutocollected")).isEqualTo("True"); + } + + private static String getPerformanceBucket(double duration) { + return DurationBucketizer.getPerformanceBucket(duration); } @Environment(TOMCAT_8_JAVA_8) diff --git a/smoke-tests/apps/HttpClients/src/smokeTest/resources/applicationinsights.json b/smoke-tests/apps/HttpClients/src/smokeTest/resources/applicationinsights.json new file mode 100644 index 00000000000..fabbaf6c881 --- /dev/null +++ b/smoke-tests/apps/HttpClients/src/smokeTest/resources/applicationinsights.json @@ -0,0 +1,10 @@ +{ + "connectionString": "InstrumentationKey=00000000-0000-0000-0000-0FEEDDADBEEF;IngestionEndpoint=http://host.docker.internal:6060/", + "role": { + "name": "testrolename", + "instance": "testroleinstance" + }, + "preview": { + "metricIntervalSeconds": 10 + } +} \ No newline at end of file From ecb893ca633386d2c1c33eddd6d180f652ef6e08 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 11 Aug 2022 15:22:26 -0700 Subject: [PATCH 17/95] Remove debug logs --- .../api/instrumenter/http/HttpClientMetrics.java | 3 --- .../api/instrumenter/http/HttpServerMetrics.java | 1 - 2 files changed, 4 deletions(-) diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java index 30f6840e15e..4c44ebdb32e 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java @@ -112,9 +112,6 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { applyClientDurationAndSizeView(state.startAttributes(), endAttributes); double duration = (endNanos - state.startTimeNanos()) / NANOS_PER_MS; - System.out.println("################# HttpClientMetrics::duration: " + duration); - System.out.println( - "################# perfBucket: " + DurationBucketizer.getPerformanceBucket(duration)); durationAndSizeAttributes = durationAndSizeAttributes.toBuilder() .put(AI_PERFORMANCE_BUCKET, DurationBucketizer.getPerformanceBucket(duration)) diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java index 747d1497d05..57f21b4e8e1 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java @@ -124,7 +124,6 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { TemporaryMetricsView.applyServerDurationAndSizeView(state.startAttributes(), endAttributes); double duration = (endNanos - state.startTimeNanos()) / NANOS_PER_MS; - logger.log(FINE, "################# HttpServerMetrics::duration: " + duration); durationAndSizeAttributes = durationAndSizeAttributes.toBuilder() .put(AI_PERFORMANCE_BUCKET, DurationBucketizer.getPerformanceBucket(duration)) From 3901f3dcf0090debcc09fceaea73626e372331b7 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 11 Aug 2022 15:23:34 -0700 Subject: [PATCH 18/95] Fix typo --- .../applicationinsights/smoketest/HttpClientSmokeTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpClientSmokeTest.java b/smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpClientSmokeTest.java index cb87a727bc1..4e89c259080 100644 --- a/smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpClientSmokeTest.java +++ b/smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpClientSmokeTest.java @@ -206,7 +206,7 @@ private static void validateMetricData(MetricData metricData, String resultCode) assertThat(properties.get("operation/synthetic")).isEqualTo("False"); assertThat(properties.get("_MS.metricId")).isEqualTo("requests/duration"); assertThat(properties.get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); - assertThat(properties.get("cloud/roleInstance")).isEqualTo("testoleinstance"); + assertThat(properties.get("cloud/roleInstance")).isEqualTo("testroleinstance"); assertThat(properties.get("cloud/roleName")).isEqualTo("testrolename"); assertThat(properties.get("_MS.IsAutocollected")).isEqualTo("True"); } From 659c2b260fd50806ec6eadb2c9728e74af386b08 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 11 Aug 2022 15:25:39 -0700 Subject: [PATCH 19/95] Remove commented out code --- .../api/instrumenter/http/TemporaryMetricsView.java | 1 - 1 file changed, 1 deletion(-) diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java index 6e7566b3e0f..01f5f8e4a52 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java @@ -44,7 +44,6 @@ private static Set buildDurationAlwaysInclude() { // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/http-metrics.md#attributes Set view = new HashSet<>(); view.add(SemanticAttributes.HTTP_METHOD); - // view.add(AttributeKey.stringKey(AI_PERFORMANCE_BUCKET)); view.add(SemanticAttributes.HTTP_STATUS_CODE); // Optional view.add(SemanticAttributes.HTTP_FLAVOR); // Optional return view; From 02a44408e497333695f00d3fc8152b502abfe8a5 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 11 Aug 2022 16:43:25 -0700 Subject: [PATCH 20/95] Fix rpc --- .../api/instrumenter/rpc/MetricView.java | 133 ++++++++++++++++++ .../instrumenter/rpc/RpcClientMetrics.java | 113 +++++++++++++++ .../instrumenter/rpc/RpcServerMetrics.java | 113 +++++++++++++++ agent/agent/build.gradle.kts | 4 + 4 files changed, 363 insertions(+) create mode 100644 agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricView.java create mode 100644 agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java create mode 100644 agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricView.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricView.java new file mode 100644 index 00000000000..d8ca7b330a2 --- /dev/null +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricView.java @@ -0,0 +1,133 @@ +/* + * ApplicationInsights-Java + * Copyright (c) Microsoft Corporation + * All rights reserved. + * + * MIT License + * Permission is hereby granted, free of charge, to any person obtaining a copy of this + * software and associated documentation files (the ""Software""), to deal in the Software + * without restriction, including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, and to permit + * persons to whom the Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package io.opentelemetry.instrumentation.api.instrumenter.rpc; + +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import java.util.HashSet; +import java.util.Set; +import java.util.function.BiConsumer; + +// this is temporary, see +// https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/3962#issuecomment-906606325 +@SuppressWarnings("rawtypes") +final class MetricsView { + + private static final Set alwaysInclude = buildAlwaysInclude(); + private static final Set clientView = buildClientView(); + private static final Set clientFallbackView = buildClientFallbackView(); + private static final Set serverView = buildServerView(); + private static final Set serverFallbackView = buildServerFallbackView(); + + private static Set buildAlwaysInclude() { + // the list of recommended metrics attributes is from + // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/rpc.md#attributes + Set view = new HashSet<>(); + view.add(SemanticAttributes.RPC_SYSTEM); + view.add(SemanticAttributes.RPC_SERVICE); + view.add(SemanticAttributes.RPC_METHOD); + return view; + } + + private static Set buildClientView() { + // the list of rpc client metrics attributes is from + // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/rpc.md#attributes + Set view = new HashSet<>(alwaysInclude); + view.add(SemanticAttributes.NET_PEER_NAME); + view.add(SemanticAttributes.NET_PEER_PORT); + view.add(SemanticAttributes.NET_TRANSPORT); + return view; + } + + private static Set buildClientFallbackView() { + // the list of rpc client metrics attributes is from + // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/rpc.md#attributes + Set view = new HashSet<>(alwaysInclude); + view.add(SemanticAttributes.NET_PEER_IP); + view.add(SemanticAttributes.NET_PEER_PORT); + view.add(SemanticAttributes.NET_TRANSPORT); + return view; + } + + private static Set buildServerView() { + // the list of rpc server metrics attributes is from + // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/rpc.md#attributes + Set view = new HashSet<>(alwaysInclude); + view.add(SemanticAttributes.NET_HOST_NAME); + view.add(SemanticAttributes.NET_TRANSPORT); + return view; + } + + private static Set buildServerFallbackView() { + // the list of rpc server metrics attributes is from + // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/rpc.md#attributes + Set view = new HashSet<>(alwaysInclude); + view.add(SemanticAttributes.NET_HOST_IP); + view.add(SemanticAttributes.NET_TRANSPORT); + return view; + } + + private static boolean containsAttribute( + AttributeKey key, Attributes startAttributes, Attributes endAttributes) { + return startAttributes.get(key) != null || endAttributes.get(key) != null; + } + + static Attributes applyClientView(Attributes startAttributes, Attributes endAttributes) { + Set fullSet = clientView; + if (!containsAttribute(SemanticAttributes.NET_PEER_NAME, startAttributes, endAttributes)) { + fullSet = clientFallbackView; + } + return applyView(fullSet, startAttributes, endAttributes); + } + + static Attributes applyServerView(Attributes startAttributes, Attributes endAttributes) { + Set fullSet = serverView; + if (!containsAttribute(SemanticAttributes.NET_HOST_NAME, startAttributes, endAttributes)) { + fullSet = serverFallbackView; + } + return applyView(fullSet, startAttributes, endAttributes); + } + + static Attributes applyView( + Set view, Attributes startAttributes, Attributes endAttributes) { + AttributesBuilder filtered = Attributes.builder(); + applyView(filtered, startAttributes, view); + applyView(filtered, endAttributes, view); + return filtered.build(); + } + + @SuppressWarnings("unchecked") + private static void applyView( + AttributesBuilder filtered, Attributes attributes, Set view) { + attributes.forEach( + (BiConsumer) + (key, value) -> { + if (view.contains(key)) { + filtered.put(key, value); + } + }); + } + + private MetricsView() {} +} diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java new file mode 100644 index 00000000000..742c4c3288b --- /dev/null +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java @@ -0,0 +1,113 @@ +/* + * ApplicationInsights-Java + * Copyright (c) Microsoft Corporation + * All rights reserved. + * + * MIT License + * Permission is hereby granted, free of charge, to any person obtaining a copy of this + * software and associated documentation files (the ""Software""), to deal in the Software + * without restriction, including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, and to permit + * persons to whom the Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package io.opentelemetry.instrumentation.api.instrumenter.rpc; + +import static com.microsoft.applicationinsights.agent.bootstrap.DurationBucketizer.AI_PERFORMANCE_BUCKET; +import static io.opentelemetry.instrumentation.api.instrumenter.rpc.MetricsView.applyClientView; +import static java.util.logging.Level.FINE; + +import com.google.auto.value.AutoValue; +import com.microsoft.applicationinsights.agent.bootstrap.DurationBucketizer; +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.metrics.DoubleHistogram; +import io.opentelemetry.api.metrics.Meter; +import io.opentelemetry.context.Context; +import io.opentelemetry.context.ContextKey; +import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; +import io.opentelemetry.instrumentation.api.instrumenter.OperationMetrics; +import java.util.concurrent.TimeUnit; +import java.util.logging.Logger; + +/** + * {@link OperationListener} which keeps track of RPC + * client metrics. + */ +public final class RpcClientMetrics implements OperationListener { + + private static final double NANOS_PER_MS = TimeUnit.MILLISECONDS.toNanos(1); + + private static final ContextKey RPC_CLIENT_REQUEST_METRICS_STATE = + ContextKey.named("rpc-client-request-metrics-state"); + + private static final Logger logger = Logger.getLogger(RpcClientMetrics.class.getName()); + + private final DoubleHistogram clientDurationHistogram; + + private RpcClientMetrics(Meter meter) { + clientDurationHistogram = + meter + .histogramBuilder("rpc.client.duration") + .setDescription("The duration of an outbound RPC invocation") + .setUnit("ms") + .build(); + } + + /** + * Returns a {@link OperationMetrics} which can be used to enable recording of {@link + * RpcClientMetrics} on an {@link + * io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder}. + */ + public static OperationMetrics get() { + return RpcClientMetrics::new; + } + + @Override + public Context onStart(Context context, Attributes startAttributes, long startNanos) { + return context.with( + RPC_CLIENT_REQUEST_METRICS_STATE, + new AutoValue_RpcClientMetrics_State(startAttributes, startNanos)); + } + + @Override + public void onEnd(Context context, Attributes endAttributes, long endNanos) { + State state = context.get(RPC_CLIENT_REQUEST_METRICS_STATE); + if (state == null) { + logger.log( + FINE, + "No state present when ending context {0}. Cannot record RPC request metrics.", + context); + return; + } + + double duration = (endNanos - state.startTimeNanos()) / NANOS_PER_MS; + System.out.println("##################### client.duration: " + duration); + System.out.println( + "##################### client.perfBucket: " + + DurationBucketizer.getPerformanceBucket(duration)); + endAttributes = + endAttributes.toBuilder() + .put(AI_PERFORMANCE_BUCKET, DurationBucketizer.getPerformanceBucket(duration)) + .build(); + + clientDurationHistogram.record( + duration, applyClientView(state.startAttributes(), endAttributes), context); + } + + @AutoValue + abstract static class State { + + abstract Attributes startAttributes(); + + abstract long startTimeNanos(); + } +} diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java new file mode 100644 index 00000000000..bfd3fa10592 --- /dev/null +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java @@ -0,0 +1,113 @@ +/* + * ApplicationInsights-Java + * Copyright (c) Microsoft Corporation + * All rights reserved. + * + * MIT License + * Permission is hereby granted, free of charge, to any person obtaining a copy of this + * software and associated documentation files (the ""Software""), to deal in the Software + * without restriction, including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, and to permit + * persons to whom the Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package io.opentelemetry.instrumentation.api.instrumenter.rpc; + +import static com.microsoft.applicationinsights.agent.bootstrap.DurationBucketizer.AI_PERFORMANCE_BUCKET; +import static io.opentelemetry.instrumentation.api.instrumenter.rpc.MetricsView.applyServerView; +import static java.util.logging.Level.FINE; + +import com.google.auto.value.AutoValue; +import com.microsoft.applicationinsights.agent.bootstrap.DurationBucketizer; +import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.api.metrics.DoubleHistogram; +import io.opentelemetry.api.metrics.Meter; +import io.opentelemetry.context.Context; +import io.opentelemetry.context.ContextKey; +import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; +import io.opentelemetry.instrumentation.api.instrumenter.OperationMetrics; +import java.util.concurrent.TimeUnit; +import java.util.logging.Logger; + +/** + * {@link OperationListener} which keeps track of RPC + * server metrics. + */ +public final class RpcServerMetrics implements OperationListener { + + private static final double NANOS_PER_MS = TimeUnit.MILLISECONDS.toNanos(1); + + private static final ContextKey RPC_SERVER_REQUEST_METRICS_STATE = + ContextKey.named("rpc-server-request-metrics-state"); + + private static final Logger logger = Logger.getLogger(RpcServerMetrics.class.getName()); + + private final DoubleHistogram serverDurationHistogram; + + private RpcServerMetrics(Meter meter) { + serverDurationHistogram = + meter + .histogramBuilder("rpc.server.duration") + .setDescription("The duration of an inbound RPC invocation") + .setUnit("ms") + .build(); + } + + /** + * Returns a {@link OperationMetrics} which can be used to enable recording of {@link + * RpcServerMetrics} on an {@link + * io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder}. + */ + public static OperationMetrics get() { + return RpcServerMetrics::new; + } + + @Override + public Context onStart(Context context, Attributes startAttributes, long startNanos) { + return context.with( + RPC_SERVER_REQUEST_METRICS_STATE, + new AutoValue_RpcServerMetrics_State(startAttributes, startNanos)); + } + + @Override + public void onEnd(Context context, Attributes endAttributes, long endNanos) { + State state = context.get(RPC_SERVER_REQUEST_METRICS_STATE); + if (state == null) { + logger.log( + FINE, + "No state present when ending context {0}. Cannot record RPC request metrics.", + context); + return; + } + + double duration = (endNanos - state.startTimeNanos()) / NANOS_PER_MS; + System.out.println("##################### server.duration: " + duration); + System.out.println( + "##################### server.perfBucket: " + + DurationBucketizer.getPerformanceBucket(duration)); + endAttributes = + endAttributes.toBuilder() + .put(AI_PERFORMANCE_BUCKET, DurationBucketizer.getPerformanceBucket(duration)) + .build(); + + serverDurationHistogram.record( + duration, applyServerView(state.startAttributes(), endAttributes), context); + } + + @AutoValue + abstract static class State { + + abstract Attributes startAttributes(); + + abstract long startTimeNanos(); + } +} diff --git a/agent/agent/build.gradle.kts b/agent/agent/build.gradle.kts index a1f2c110efe..9b354db8d92 100644 --- a/agent/agent/build.gradle.kts +++ b/agent/agent/build.gradle.kts @@ -117,6 +117,10 @@ tasks { exclude("io/opentelemetry/javaagent/shaded/instrumentation/api/instrumenter/http/HttpServerMetrics.class") exclude("io/opentelemetry/javaagent/shaded/instrumentation/api/instrumenter/http/TemporaryMetricsView.class") + exclude("io/opentelemetry/javaagent/shaded/instrumentation/api/instrumenter/rpc/RpcClientMetrics.class") + exclude("io/opentelemetry/javaagent/shaded/instrumentation/api/instrumenter/rpc/RpcServerMetrics.class") + exclude("io/opentelemetry/javaagent/shaded/instrumentation/api/instrumenter/rpc/MetricView.class") + dependsOn(isolateJavaagentLibs) from(isolateJavaagentLibs.get().outputs) From e7849db76b9f2f53ea9678725a56849575926263 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 11 Aug 2022 16:46:46 -0700 Subject: [PATCH 21/95] Fix ci tests --- .../processors/SpanExporterWithAttributeProcessorTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/SpanExporterWithAttributeProcessorTest.java b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/SpanExporterWithAttributeProcessorTest.java index 29859dbeecd..971b933a21a 100644 --- a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/SpanExporterWithAttributeProcessorTest.java +++ b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/SpanExporterWithAttributeProcessorTest.java @@ -1373,7 +1373,7 @@ void actionInsertWithExtractTest() { SpanData resultSpan = result.get(0); assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("httpProtocol"))) - .isEqualTo("io/opentelemetry/instrumentation/api/instrumenter/http"); + .isEqualTo("http"); assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("httpDomain"))) .isEqualTo("example.com"); assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("httpPath"))) @@ -1420,7 +1420,7 @@ void actionInsertWithExtractDuplicateTest() { SpanData resultSpan = result.get(0); assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("httpProtocol"))) - .isEqualTo("io/opentelemetry/instrumentation/api/instrumenter/http"); + .isEqualTo("http"); assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("httpDomain"))) .isEqualTo("example.com"); assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("httpPath"))) From fa446558b3b5b62fd03e1c93d708b67821f4a717 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 11 Aug 2022 17:22:18 -0700 Subject: [PATCH 22/95] Refactor --- .../api/instrumenter/http/HttpClientMetrics.java | 4 ++-- .../api/instrumenter/http/HttpServerMetrics.java | 4 ++-- .../instrumenter/rpc/{MetricView.java => MetricsView.java} | 0 .../api/instrumenter/rpc/RpcClientMetrics.java | 4 ++-- .../api/instrumenter/rpc/RpcServerMetrics.java | 4 ++-- .../api/instrumenter/utils}/DurationBucketizer.java | 2 +- agent/agent/build.gradle.kts | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) rename agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/{MetricView.java => MetricsView.java} (100%) rename agent/agent-bootstrap/src/main/java/{com/microsoft/applicationinsights/agent/bootstrap => io/opentelemetry/instrumentation/api/instrumenter/utils}/DurationBucketizer.java (97%) diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java index 4c44ebdb32e..18a9e0e7f7b 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java @@ -21,12 +21,12 @@ package io.opentelemetry.instrumentation.api.instrumenter.http; -import static com.microsoft.applicationinsights.agent.bootstrap.DurationBucketizer.AI_PERFORMANCE_BUCKET; +import static io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer.AI_PERFORMANCE_BUCKET; import static io.opentelemetry.instrumentation.api.instrumenter.http.TemporaryMetricsView.applyClientDurationAndSizeView; import static java.util.logging.Level.FINE; import com.google.auto.value.AutoValue; -import com.microsoft.applicationinsights.agent.bootstrap.DurationBucketizer; +import io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.metrics.DoubleHistogram; diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java index 57f21b4e8e1..3ec1e57ebb5 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java @@ -21,11 +21,11 @@ package io.opentelemetry.instrumentation.api.instrumenter.http; -import static com.microsoft.applicationinsights.agent.bootstrap.DurationBucketizer.AI_PERFORMANCE_BUCKET; +import static io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer.AI_PERFORMANCE_BUCKET; import static java.util.logging.Level.FINE; import com.google.auto.value.AutoValue; -import com.microsoft.applicationinsights.agent.bootstrap.DurationBucketizer; +import io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.metrics.DoubleHistogram; diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricView.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java similarity index 100% rename from agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricView.java rename to agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java index 742c4c3288b..f6061898e21 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java @@ -21,12 +21,12 @@ package io.opentelemetry.instrumentation.api.instrumenter.rpc; -import static com.microsoft.applicationinsights.agent.bootstrap.DurationBucketizer.AI_PERFORMANCE_BUCKET; +import static io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer.AI_PERFORMANCE_BUCKET; import static io.opentelemetry.instrumentation.api.instrumenter.rpc.MetricsView.applyClientView; import static java.util.logging.Level.FINE; import com.google.auto.value.AutoValue; -import com.microsoft.applicationinsights.agent.bootstrap.DurationBucketizer; +import io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.metrics.DoubleHistogram; import io.opentelemetry.api.metrics.Meter; diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java index bfd3fa10592..0550118eec6 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java @@ -21,12 +21,12 @@ package io.opentelemetry.instrumentation.api.instrumenter.rpc; -import static com.microsoft.applicationinsights.agent.bootstrap.DurationBucketizer.AI_PERFORMANCE_BUCKET; +import static io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer.AI_PERFORMANCE_BUCKET; import static io.opentelemetry.instrumentation.api.instrumenter.rpc.MetricsView.applyServerView; import static java.util.logging.Level.FINE; import com.google.auto.value.AutoValue; -import com.microsoft.applicationinsights.agent.bootstrap.DurationBucketizer; +import io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.metrics.DoubleHistogram; import io.opentelemetry.api.metrics.Meter; diff --git a/agent/agent-bootstrap/src/main/java/com/microsoft/applicationinsights/agent/bootstrap/DurationBucketizer.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/utils/DurationBucketizer.java similarity index 97% rename from agent/agent-bootstrap/src/main/java/com/microsoft/applicationinsights/agent/bootstrap/DurationBucketizer.java rename to agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/utils/DurationBucketizer.java index 7070b00c677..66af26bab70 100644 --- a/agent/agent-bootstrap/src/main/java/com/microsoft/applicationinsights/agent/bootstrap/DurationBucketizer.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/utils/DurationBucketizer.java @@ -19,7 +19,7 @@ * DEALINGS IN THE SOFTWARE. */ -package com.microsoft.applicationinsights.agent.bootstrap; +package io.opentelemetry.instrumentation.api.instrumenter.utils; import java.util.LinkedHashMap; import java.util.Map; diff --git a/agent/agent/build.gradle.kts b/agent/agent/build.gradle.kts index 9b354db8d92..c0999f0ce79 100644 --- a/agent/agent/build.gradle.kts +++ b/agent/agent/build.gradle.kts @@ -119,7 +119,7 @@ tasks { exclude("io/opentelemetry/javaagent/shaded/instrumentation/api/instrumenter/rpc/RpcClientMetrics.class") exclude("io/opentelemetry/javaagent/shaded/instrumentation/api/instrumenter/rpc/RpcServerMetrics.class") - exclude("io/opentelemetry/javaagent/shaded/instrumentation/api/instrumenter/rpc/MetricView.class") + exclude("io/opentelemetry/javaagent/shaded/instrumentation/api/instrumenter/rpc/MetricsView.class") dependsOn(isolateJavaagentLibs) from(isolateJavaagentLibs.get().outputs) From c028ac89ed58e92477d30b1d58aa4dd782c7d65f Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 11 Aug 2022 17:24:50 -0700 Subject: [PATCH 23/95] Add a new smoke test --- .../instrumenter/http/HttpClientMetrics.java | 4 +- .../instrumenter/http/HttpServerMetrics.java | 2 +- .../instrumenter/rpc/RpcClientMetrics.java | 4 +- .../instrumenter/rpc/RpcServerMetrics.java | 4 +- settings.gradle | 1 + .../HttpPreaggregatedMetrics/build.gradle.kts | 15 ++ .../HttpPreaggregatedMetricsTestServlet.java | 105 +++++++++ .../smoketest/DurationBucketizer.java | 59 +++++ .../HttpPreaggregatedMetricsSmokeTest.java | 201 ++++++++++++++++++ .../resources/applicationinsights.json | 10 + .../src/smokeTest/resources/logback-test.xml | 11 + 11 files changed, 409 insertions(+), 7 deletions(-) create mode 100644 smoke-tests/apps/HttpPreaggregatedMetrics/build.gradle.kts create mode 100644 smoke-tests/apps/HttpPreaggregatedMetrics/src/main/java/com/microsoft/applicationinsights/smoketestapp/HttpPreaggregatedMetricsTestServlet.java create mode 100644 smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/DurationBucketizer.java create mode 100644 smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java create mode 100644 smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/resources/applicationinsights.json create mode 100644 smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/resources/logback-test.xml diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java index 18a9e0e7f7b..66555aab5e4 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java @@ -21,12 +21,11 @@ package io.opentelemetry.instrumentation.api.instrumenter.http; -import static io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer.AI_PERFORMANCE_BUCKET; import static io.opentelemetry.instrumentation.api.instrumenter.http.TemporaryMetricsView.applyClientDurationAndSizeView; +import static io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer.AI_PERFORMANCE_BUCKET; import static java.util.logging.Level.FINE; import com.google.auto.value.AutoValue; -import io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.metrics.DoubleHistogram; @@ -36,6 +35,7 @@ import io.opentelemetry.context.ContextKey; import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; import io.opentelemetry.instrumentation.api.instrumenter.OperationMetrics; +import io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java index 3ec1e57ebb5..43b90bd94fc 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java @@ -25,7 +25,6 @@ import static java.util.logging.Level.FINE; import com.google.auto.value.AutoValue; -import io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.metrics.DoubleHistogram; @@ -36,6 +35,7 @@ import io.opentelemetry.context.ContextKey; import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; import io.opentelemetry.instrumentation.api.instrumenter.OperationMetrics; +import io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java index f6061898e21..895d74877c3 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java @@ -21,12 +21,11 @@ package io.opentelemetry.instrumentation.api.instrumenter.rpc; -import static io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer.AI_PERFORMANCE_BUCKET; import static io.opentelemetry.instrumentation.api.instrumenter.rpc.MetricsView.applyClientView; +import static io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer.AI_PERFORMANCE_BUCKET; import static java.util.logging.Level.FINE; import com.google.auto.value.AutoValue; -import io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.metrics.DoubleHistogram; import io.opentelemetry.api.metrics.Meter; @@ -34,6 +33,7 @@ import io.opentelemetry.context.ContextKey; import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; import io.opentelemetry.instrumentation.api.instrumenter.OperationMetrics; +import io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java index 0550118eec6..8923a248bf3 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java @@ -21,12 +21,11 @@ package io.opentelemetry.instrumentation.api.instrumenter.rpc; -import static io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer.AI_PERFORMANCE_BUCKET; import static io.opentelemetry.instrumentation.api.instrumenter.rpc.MetricsView.applyServerView; +import static io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer.AI_PERFORMANCE_BUCKET; import static java.util.logging.Level.FINE; import com.google.auto.value.AutoValue; -import io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.metrics.DoubleHistogram; import io.opentelemetry.api.metrics.Meter; @@ -34,6 +33,7 @@ import io.opentelemetry.context.ContextKey; import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; import io.opentelemetry.instrumentation.api.instrumenter.OperationMetrics; +import io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; diff --git a/settings.gradle b/settings.gradle index bac78513f3b..84b29301259 100644 --- a/settings.gradle +++ b/settings.gradle @@ -88,6 +88,7 @@ include ':smoke-tests:apps:gRPC' include ':smoke-tests:apps:HeartBeat' include ':smoke-tests:apps:HttpClients' include ':smoke-tests:apps:HttpHeaders' +include ':smoke-tests:apps:HttpPreaggregatedMetrics' include ':smoke-tests:apps:HttpServer4xx' include ':smoke-tests:apps:InheritedAttributes' include ':smoke-tests:apps:Jdbc' diff --git a/smoke-tests/apps/HttpPreaggregatedMetrics/build.gradle.kts b/smoke-tests/apps/HttpPreaggregatedMetrics/build.gradle.kts new file mode 100644 index 00000000000..df7ba21fe59 --- /dev/null +++ b/smoke-tests/apps/HttpPreaggregatedMetrics/build.gradle.kts @@ -0,0 +1,15 @@ +plugins { + id("ai.smoke-test-war") +} + +dependencies { + implementation("org.apache.httpcomponents:httpclient:4.5.13") + implementation("org.apache.httpcomponents:httpasyncclient:4.1.4") + implementation("commons-httpclient:commons-httpclient:3.1") + implementation("com.squareup.okhttp3:okhttp:3.12.1") + implementation("com.squareup.okhttp:okhttp:2.7.5") + implementation("org.springframework:spring-webflux:5.2.3.RELEASE") // for testing netty client + implementation("io.projectreactor.netty:reactor-netty:0.9.4.RELEASE") // needed for above + // this dependency is needed to make wildfly happy + implementation("com.fasterxml.jackson.core:jackson-databind:2.9.4") +} diff --git a/smoke-tests/apps/HttpPreaggregatedMetrics/src/main/java/com/microsoft/applicationinsights/smoketestapp/HttpPreaggregatedMetricsTestServlet.java b/smoke-tests/apps/HttpPreaggregatedMetrics/src/main/java/com/microsoft/applicationinsights/smoketestapp/HttpPreaggregatedMetricsTestServlet.java new file mode 100644 index 00000000000..aaf87aada9c --- /dev/null +++ b/smoke-tests/apps/HttpPreaggregatedMetrics/src/main/java/com/microsoft/applicationinsights/smoketestapp/HttpPreaggregatedMetricsTestServlet.java @@ -0,0 +1,105 @@ +/* + * ApplicationInsights-Java + * Copyright (c) Microsoft Corporation + * All rights reserved. + * + * MIT License + * Permission is hereby granted, free of charge, to any person obtaining a copy of this + * software and associated documentation files (the ""Software""), to deal in the Software + * without restriction, including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, and to permit + * persons to whom the Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package com.microsoft.applicationinsights.smoketestapp; + +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.apache.commons.httpclient.Cookie; +import org.apache.commons.httpclient.cookie.CookieSpecBase; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; +import org.apache.http.impl.nio.client.HttpAsyncClients; + +@WebServlet("/*") +public class HttpPreaggregatedMetricsTestServlet extends HttpServlet { + + private final CloseableHttpClient httpClient = + HttpClientBuilder.create().disableAutomaticRetries().build(); + private final CloseableHttpAsyncClient httpAsyncClient = HttpAsyncClients.createDefault(); + + public HttpPreaggregatedMetricsTestServlet() { + httpAsyncClient.start(); + } + + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException { + try { + doGetInternal(req); + resp.getWriter().println("hi!"); + } catch (ServletException e) { + throw e; + } catch (Exception e) { + throw new ServletException(e); + } + } + + // "/httpUrlConnection" + private void doGetInternal(HttpServletRequest req) throws Exception { + String pathInfo = req.getPathInfo(); + ExecuteGetUrl executeGetUrl = this::httpUrlConnection; + + if (executeGetUrl != null) { + executeGetUrl.execute("https://mock.codes/200?q=spaces%20test"); + try { + executeGetUrl.execute("https://mock.codes/404"); + } catch (Exception e) { + // HttpURLConnection throws exception on 404 and 500 + } + try { + executeGetUrl.execute("https://mock.codes/500"); + } catch (Exception e) { + // HttpURLConnection throws exception on 404 and 500 + } + } + } + + private void httpUrlConnection(String url) throws IOException { + URL obj = new URL(url); + HttpURLConnection connection = (HttpURLConnection) obj.openConnection(); + // calling getContentType() first, since this triggered a bug previously in the instrumentation + // previously + connection.getContentType(); + InputStream content = connection.getInputStream(); + // drain the content + byte[] buffer = new byte[1024]; + while (content.read(buffer) != -1) {} + content.close(); + } + + @FunctionalInterface + interface ExecuteGetUrl { + void execute(String url) throws Exception; + } + + public static class PermitAllCookiesSpec extends CookieSpecBase { + @Override + public void validate(String host, int port, String path, boolean secure, Cookie cookie) {} + } +} diff --git a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/DurationBucketizer.java b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/DurationBucketizer.java new file mode 100644 index 00000000000..82dccddc57e --- /dev/null +++ b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/DurationBucketizer.java @@ -0,0 +1,59 @@ +/* + * ApplicationInsights-Java + * Copyright (c) Microsoft Corporation + * All rights reserved. + * + * MIT License + * Permission is hereby granted, free of charge, to any person obtaining a copy of this + * software and associated documentation files (the ""Software""), to deal in the Software + * without restriction, including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, and to permit + * persons to whom the Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package com.microsoft.applicationinsights.smoketest; + +import java.util.LinkedHashMap; +import java.util.Map; + +// copied from link{com.microsoft.applicationinsights.agent.bootstrap.DurationBucketizer} +public final class DurationBucketizer { + + public static final String AI_PERFORMANCE_BUCKET = "ai.performance.bucket"; + + // sorted HashMap + private static final Map performanceBuckets = new LinkedHashMap<>(); + + static { + performanceBuckets.put("<250ms", 250d); + performanceBuckets.put("250ms-500ms", 500d); + performanceBuckets.put("500ms-1sec", 1000d); + performanceBuckets.put("1sec-3sec", 3000d); + performanceBuckets.put("3sec-7sec", 7000d); + performanceBuckets.put("7sec-15sec", 15000d); + performanceBuckets.put("15sec-30sec", 30000d); + performanceBuckets.put("30sec-1min", 60000d); + performanceBuckets.put("1min-2min", 120000d); + performanceBuckets.put("2min-5min", 300000d); + performanceBuckets.put(">=5min", Double.MAX_VALUE); + } + + public static String getPerformanceBucket(double durationInMillis) { + for (Map.Entry entry : performanceBuckets.entrySet()) { + if (durationInMillis < entry.getValue()) { + return entry.getKey(); + } + } + return ">=5min"; + } + + private DurationBucketizer() {} +} diff --git a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java new file mode 100644 index 00000000000..313a028cb89 --- /dev/null +++ b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java @@ -0,0 +1,201 @@ +/* + * ApplicationInsights-Java + * Copyright (c) Microsoft Corporation + * All rights reserved. + * + * MIT License + * Permission is hereby granted, free of charge, to any person obtaining a copy of this + * software and associated documentation files (the ""Software""), to deal in the Software + * without restriction, including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, and to permit + * persons to whom the Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package com.microsoft.applicationinsights.smoketest; + +import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.TOMCAT_8_JAVA_11; +import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.TOMCAT_8_JAVA_11_OPENJ9; +import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.TOMCAT_8_JAVA_17; +import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.TOMCAT_8_JAVA_18; +import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.TOMCAT_8_JAVA_19; +import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.TOMCAT_8_JAVA_8; +import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.TOMCAT_8_JAVA_8_OPENJ9; +import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8; +import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9; +import static org.assertj.core.api.Assertions.assertThat; + +import com.microsoft.applicationinsights.smoketest.schemav2.Data; +import com.microsoft.applicationinsights.smoketest.schemav2.DataPoint; +import com.microsoft.applicationinsights.smoketest.schemav2.Envelope; +import com.microsoft.applicationinsights.smoketest.schemav2.MetricData; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +@UseAgent +abstract class HttpPreaggregatedMetricsSmokeTest { + + @RegisterExtension static final SmokeTestExtension testing = new SmokeTestExtension(); + + @Test + @TargetUri("/httpUrlConnection") + void testHttpUrlConnection() throws Exception { + verify(); + } + + private static void verify() throws Exception { + verify("https://mock.codes/200?q=spaces%20test"); + } + + private static void verify(String successUrlWithQueryString) throws Exception { + Telemetry telemetry = testing.getTelemetry(3); + + assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getSuccess()).isTrue(); + // TODO (trask) add this check in all smoke tests? + assertThat(telemetry.rdEnvelope.getSampleRate()).isNull(); + + assertThat(telemetry.rdd1.getName()).isEqualTo("GET /200"); + assertThat(telemetry.rdd1.getData()).isEqualTo(successUrlWithQueryString); + assertThat(telemetry.rdd1.getType()).isEqualTo("Http"); + assertThat(telemetry.rdd1.getTarget()).isEqualTo("mock.codes"); + assertThat(telemetry.rdd1.getResultCode()).isEqualTo("200"); + assertThat(telemetry.rdd1.getProperties()).isEmpty(); + assertThat(telemetry.rdd1.getSuccess()).isTrue(); + assertThat(telemetry.rddEnvelope1.getSampleRate()).isNull(); + + assertThat(telemetry.rdd2.getName()).isEqualTo("GET /404"); + assertThat(telemetry.rdd2.getData()).isEqualTo("https://mock.codes/404"); + assertThat(telemetry.rdd2.getType()).isEqualTo("Http"); + assertThat(telemetry.rdd2.getTarget()).isEqualTo("mock.codes"); + assertThat(telemetry.rdd2.getResultCode()).isEqualTo("404"); + assertThat(telemetry.rdd2.getProperties()).isEmpty(); + assertThat(telemetry.rdd2.getSuccess()).isFalse(); + assertThat(telemetry.rddEnvelope2.getSampleRate()).isNull(); + + assertThat(telemetry.rdd3.getName()).isEqualTo("GET /500"); + assertThat(telemetry.rdd3.getData()).isEqualTo("https://mock.codes/500"); + assertThat(telemetry.rdd3.getType()).isEqualTo("Http"); + assertThat(telemetry.rdd3.getTarget()).isEqualTo("mock.codes"); + assertThat(telemetry.rdd3.getResultCode()).isEqualTo("500"); + assertThat(telemetry.rdd3.getProperties()).isEmpty(); + assertThat(telemetry.rdd3.getSuccess()).isFalse(); + assertThat(telemetry.rddEnvelope3.getSampleRate()).isNull(); + + SmokeTestExtension.assertParentChild( + telemetry.rd, telemetry.rdEnvelope, telemetry.rddEnvelope1, "GET /HttpClients/*"); + SmokeTestExtension.assertParentChild( + telemetry.rd, telemetry.rdEnvelope, telemetry.rddEnvelope2, "GET /HttpClients/*"); + SmokeTestExtension.assertParentChild( + telemetry.rd, telemetry.rdEnvelope, telemetry.rddEnvelope3, "GET /HttpClients/*"); + + verifyPreAggregatedMetrics("http.client.duration"); + } + + private static void verifyPreAggregatedMetrics(String name) throws Exception { + List metrics = + testing.mockedIngestion.waitForItems( + SmokeTestExtension.getMetricPredicate(name), 3, 40, TimeUnit.SECONDS); + + // sort metrics based on result code + metrics.sort( + Comparator.comparing( + obj -> { + MetricData metricData = (MetricData) ((Data) obj.getData()).getBaseData(); + return metricData.getProperties().get("request/resultCode"); + })); + + // 1st pre-aggregated metric + Envelope envelope1 = metrics.get(0); + validateTags(envelope1); + MetricData md1 = (MetricData) ((Data) envelope1.getData()).getBaseData(); + validateMetricData(md1, "200"); + + // 2nd pre-aggregated metric + Envelope envelope2 = metrics.get(1); + validateTags(envelope2); + MetricData md2 = (MetricData) ((Data) envelope2.getData()).getBaseData(); + validateMetricData(md2, "404"); + + // 3rd pre-aggregated metric + Envelope envelope3 = metrics.get(2); + validateTags(envelope3); + MetricData md3 = (MetricData) ((Data) envelope3.getData()).getBaseData(); + validateMetricData(md3, "500"); + } + + private static void validateTags(Envelope envelope) { + Map tags = envelope.getTags(); + assertThat(tags.get("ai.internal.sdkVersion")).isNotNull(); + assertThat(tags).containsEntry("ai.cloud.roleInstance", "testroleinstance"); + assertThat(tags).containsEntry("ai.cloud.role", "testrolename"); + } + + private static void validateMetricData(MetricData metricData, String resultCode) { + List dataPoints = metricData.getMetrics(); + assertThat(dataPoints).hasSize(1); + DataPoint dataPoint = dataPoints.get(0); + assertThat(dataPoint.getCount()).isEqualTo(1); + assertThat(dataPoint.getValue()).isGreaterThan(0d).isLessThan(5 * 60 * 1000d); // (0 - 5) min + assertThat(dataPoint.getMin()).isGreaterThan(0d).isLessThan(5 * 60 * 1000d); // (0 - 5) min + assertThat(dataPoint.getMin()).isGreaterThan(0d).isLessThan(5 * 60 * 1000d); // (0 - 5) min + Map properties = metricData.getProperties(); + assertThat(properties.get("request/resultCode")).isEqualTo(resultCode); + + double value = metricData.getMetrics().get(0).getValue(); + assertThat(properties.get("request/performanceBucket")).isEqualTo(getPerformanceBucket(value)); + if ("200".equals(resultCode)) { + assertThat(properties.get("request/success")).isEqualTo("True"); + } else { + assertThat(properties.get("request/success")).isEqualTo("False"); + } + assertThat(properties.get("operation/synthetic")).isEqualTo("False"); + assertThat(properties.get("_MS.metricId")).isEqualTo("requests/duration"); + assertThat(properties.get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(properties.get("cloud/roleInstance")).isEqualTo("testroleinstance"); + assertThat(properties.get("cloud/roleName")).isEqualTo("testrolename"); + assertThat(properties.get("_MS.IsAutocollected")).isEqualTo("True"); + } + + private static String getPerformanceBucket(double duration) { + return DurationBucketizer.getPerformanceBucket(duration); + } + + @Environment(TOMCAT_8_JAVA_8) + static class Tomcat8Java8Test extends HttpPreaggregatedMetricsSmokeTest {} + + @Environment(TOMCAT_8_JAVA_8_OPENJ9) + static class Tomcat8Java8OpenJ9Test extends HttpPreaggregatedMetricsSmokeTest {} + + @Environment(TOMCAT_8_JAVA_11) + static class Tomcat8Java11Test extends HttpPreaggregatedMetricsSmokeTest {} + + @Environment(TOMCAT_8_JAVA_11_OPENJ9) + static class Tomcat8Java11OpenJ9Test extends HttpPreaggregatedMetricsSmokeTest {} + + @Environment(TOMCAT_8_JAVA_17) + static class Tomcat8Java17Test extends HttpPreaggregatedMetricsSmokeTest {} + + @Environment(TOMCAT_8_JAVA_18) + static class Tomcat8Java18Test extends HttpPreaggregatedMetricsSmokeTest {} + + @Environment(TOMCAT_8_JAVA_19) + static class Tomcat8Java19Test extends HttpPreaggregatedMetricsSmokeTest {} + + @Environment(WILDFLY_13_JAVA_8) + static class Wildfly13Java8Test extends HttpPreaggregatedMetricsSmokeTest {} + + @Environment(WILDFLY_13_JAVA_8_OPENJ9) + static class Wildfly13Java8OpenJ9Test extends HttpPreaggregatedMetricsSmokeTest {} +} diff --git a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/resources/applicationinsights.json b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/resources/applicationinsights.json new file mode 100644 index 00000000000..fabbaf6c881 --- /dev/null +++ b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/resources/applicationinsights.json @@ -0,0 +1,10 @@ +{ + "connectionString": "InstrumentationKey=00000000-0000-0000-0000-0FEEDDADBEEF;IngestionEndpoint=http://host.docker.internal:6060/", + "role": { + "name": "testrolename", + "instance": "testroleinstance" + }, + "preview": { + "metricIntervalSeconds": 10 + } +} \ No newline at end of file diff --git a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/resources/logback-test.xml b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/resources/logback-test.xml new file mode 100644 index 00000000000..0cbbecd57ce --- /dev/null +++ b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/resources/logback-test.xml @@ -0,0 +1,11 @@ + + + + + %d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{36} - %msg%n + + + + + + From 07b42e0b0929548eb060af69c187ef4a1286b0f4 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 11 Aug 2022 17:36:10 -0700 Subject: [PATCH 24/95] Clean up smoke test --- .../HttpPreaggregatedMetricsTestServlet.java | 5 -- .../HttpPreaggregatedMetricsSmokeTest.java | 50 ++----------------- 2 files changed, 3 insertions(+), 52 deletions(-) diff --git a/smoke-tests/apps/HttpPreaggregatedMetrics/src/main/java/com/microsoft/applicationinsights/smoketestapp/HttpPreaggregatedMetricsTestServlet.java b/smoke-tests/apps/HttpPreaggregatedMetrics/src/main/java/com/microsoft/applicationinsights/smoketestapp/HttpPreaggregatedMetricsTestServlet.java index aaf87aada9c..86cfcf24e7e 100644 --- a/smoke-tests/apps/HttpPreaggregatedMetrics/src/main/java/com/microsoft/applicationinsights/smoketestapp/HttpPreaggregatedMetricsTestServlet.java +++ b/smoke-tests/apps/HttpPreaggregatedMetrics/src/main/java/com/microsoft/applicationinsights/smoketestapp/HttpPreaggregatedMetricsTestServlet.java @@ -97,9 +97,4 @@ private void httpUrlConnection(String url) throws IOException { interface ExecuteGetUrl { void execute(String url) throws Exception; } - - public static class PermitAllCookiesSpec extends CookieSpecBase { - @Override - public void validate(String host, int port, String path, boolean secure, Cookie cookie) {} - } } diff --git a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java index 313a028cb89..9dabb18b311 100644 --- a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java +++ b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java @@ -59,11 +59,10 @@ private static void verify() throws Exception { } private static void verify(String successUrlWithQueryString) throws Exception { - Telemetry telemetry = testing.getTelemetry(3); + Telemetry telemetry = testing.getTelemetry(1); assertThat(telemetry.rd.getProperties()).isEmpty(); assertThat(telemetry.rd.getSuccess()).isTrue(); - // TODO (trask) add this check in all smoke tests? assertThat(telemetry.rdEnvelope.getSampleRate()).isNull(); assertThat(telemetry.rdd1.getName()).isEqualTo("GET /200"); @@ -75,30 +74,8 @@ private static void verify(String successUrlWithQueryString) throws Exception { assertThat(telemetry.rdd1.getSuccess()).isTrue(); assertThat(telemetry.rddEnvelope1.getSampleRate()).isNull(); - assertThat(telemetry.rdd2.getName()).isEqualTo("GET /404"); - assertThat(telemetry.rdd2.getData()).isEqualTo("https://mock.codes/404"); - assertThat(telemetry.rdd2.getType()).isEqualTo("Http"); - assertThat(telemetry.rdd2.getTarget()).isEqualTo("mock.codes"); - assertThat(telemetry.rdd2.getResultCode()).isEqualTo("404"); - assertThat(telemetry.rdd2.getProperties()).isEmpty(); - assertThat(telemetry.rdd2.getSuccess()).isFalse(); - assertThat(telemetry.rddEnvelope2.getSampleRate()).isNull(); - - assertThat(telemetry.rdd3.getName()).isEqualTo("GET /500"); - assertThat(telemetry.rdd3.getData()).isEqualTo("https://mock.codes/500"); - assertThat(telemetry.rdd3.getType()).isEqualTo("Http"); - assertThat(telemetry.rdd3.getTarget()).isEqualTo("mock.codes"); - assertThat(telemetry.rdd3.getResultCode()).isEqualTo("500"); - assertThat(telemetry.rdd3.getProperties()).isEmpty(); - assertThat(telemetry.rdd3.getSuccess()).isFalse(); - assertThat(telemetry.rddEnvelope3.getSampleRate()).isNull(); - - SmokeTestExtension.assertParentChild( - telemetry.rd, telemetry.rdEnvelope, telemetry.rddEnvelope1, "GET /HttpClients/*"); - SmokeTestExtension.assertParentChild( - telemetry.rd, telemetry.rdEnvelope, telemetry.rddEnvelope2, "GET /HttpClients/*"); SmokeTestExtension.assertParentChild( - telemetry.rd, telemetry.rdEnvelope, telemetry.rddEnvelope3, "GET /HttpClients/*"); + telemetry.rd, telemetry.rdEnvelope, telemetry.rddEnvelope1, "GET /HttpPreaggregatedMetrics/*"); verifyPreAggregatedMetrics("http.client.duration"); } @@ -106,33 +83,12 @@ private static void verify(String successUrlWithQueryString) throws Exception { private static void verifyPreAggregatedMetrics(String name) throws Exception { List metrics = testing.mockedIngestion.waitForItems( - SmokeTestExtension.getMetricPredicate(name), 3, 40, TimeUnit.SECONDS); + SmokeTestExtension.getMetricPredicate(name), 1, 20, TimeUnit.SECONDS); - // sort metrics based on result code - metrics.sort( - Comparator.comparing( - obj -> { - MetricData metricData = (MetricData) ((Data) obj.getData()).getBaseData(); - return metricData.getProperties().get("request/resultCode"); - })); - - // 1st pre-aggregated metric Envelope envelope1 = metrics.get(0); validateTags(envelope1); MetricData md1 = (MetricData) ((Data) envelope1.getData()).getBaseData(); validateMetricData(md1, "200"); - - // 2nd pre-aggregated metric - Envelope envelope2 = metrics.get(1); - validateTags(envelope2); - MetricData md2 = (MetricData) ((Data) envelope2.getData()).getBaseData(); - validateMetricData(md2, "404"); - - // 3rd pre-aggregated metric - Envelope envelope3 = metrics.get(2); - validateTags(envelope3); - MetricData md3 = (MetricData) ((Data) envelope3.getData()).getBaseData(); - validateMetricData(md3, "500"); } private static void validateTags(Envelope envelope) { From 6defb032080adf044824b8132c6a7abdd321d7cb Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 11 Aug 2022 18:34:31 -0700 Subject: [PATCH 25/95] Add perfromanceBucket to http.client.duration and http.server.duration only --- .../instrumenter/http/HttpClientMetrics.java | 5 +- .../instrumenter/http/HttpServerMetrics.java | 5 +- .../smoketest/DurationBucketizer.java | 59 ------------------- 3 files changed, 6 insertions(+), 63 deletions(-) delete mode 100644 smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/DurationBucketizer.java diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java index 66555aab5e4..c351a5e6e38 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java @@ -112,12 +112,13 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { applyClientDurationAndSizeView(state.startAttributes(), endAttributes); double duration = (endNanos - state.startTimeNanos()) / NANOS_PER_MS; - durationAndSizeAttributes = + Attributes durationAttributes = durationAndSizeAttributes.toBuilder() .put(AI_PERFORMANCE_BUCKET, DurationBucketizer.getPerformanceBucket(duration)) .build(); + ; + this.duration.record(duration, durationAttributes, context); - this.duration.record(duration, durationAndSizeAttributes, context); Long requestLength = getAttribute( SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, endAttributes, state.startAttributes()); diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java index 43b90bd94fc..e215d2de362 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java @@ -124,12 +124,13 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { TemporaryMetricsView.applyServerDurationAndSizeView(state.startAttributes(), endAttributes); double duration = (endNanos - state.startTimeNanos()) / NANOS_PER_MS; - durationAndSizeAttributes = + Attributes durationAttributes = durationAndSizeAttributes.toBuilder() .put(AI_PERFORMANCE_BUCKET, DurationBucketizer.getPerformanceBucket(duration)) .build(); + ; + this.duration.record(duration, durationAttributes, context); - this.duration.record(duration, durationAndSizeAttributes, context); Long requestLength = getAttribute( SemanticAttributes.HTTP_REQUEST_CONTENT_LENGTH, endAttributes, state.startAttributes()); diff --git a/smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/DurationBucketizer.java b/smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/DurationBucketizer.java deleted file mode 100644 index 82dccddc57e..00000000000 --- a/smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/DurationBucketizer.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * ApplicationInsights-Java - * Copyright (c) Microsoft Corporation - * All rights reserved. - * - * MIT License - * Permission is hereby granted, free of charge, to any person obtaining a copy of this - * software and associated documentation files (the ""Software""), to deal in the Software - * without restriction, including without limitation the rights to use, copy, modify, merge, - * publish, distribute, sublicense, and/or sell copies of the Software, and to permit - * persons to whom the Software is furnished to do so, subject to the following conditions: - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE - * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -package com.microsoft.applicationinsights.smoketest; - -import java.util.LinkedHashMap; -import java.util.Map; - -// copied from link{com.microsoft.applicationinsights.agent.bootstrap.DurationBucketizer} -public final class DurationBucketizer { - - public static final String AI_PERFORMANCE_BUCKET = "ai.performance.bucket"; - - // sorted HashMap - private static final Map performanceBuckets = new LinkedHashMap<>(); - - static { - performanceBuckets.put("<250ms", 250d); - performanceBuckets.put("250ms-500ms", 500d); - performanceBuckets.put("500ms-1sec", 1000d); - performanceBuckets.put("1sec-3sec", 3000d); - performanceBuckets.put("3sec-7sec", 7000d); - performanceBuckets.put("7sec-15sec", 15000d); - performanceBuckets.put("15sec-30sec", 30000d); - performanceBuckets.put("30sec-1min", 60000d); - performanceBuckets.put("1min-2min", 120000d); - performanceBuckets.put("2min-5min", 300000d); - performanceBuckets.put(">=5min", Double.MAX_VALUE); - } - - public static String getPerformanceBucket(double durationInMillis) { - for (Map.Entry entry : performanceBuckets.entrySet()) { - if (durationInMillis < entry.getValue()) { - return entry.getKey(); - } - } - return ">=5min"; - } - - private DurationBucketizer() {} -} From 46556204dc7329371499609c45bb9a59f9b23d67 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 11 Aug 2022 18:35:01 -0700 Subject: [PATCH 26/95] Revert httpclient smoke test --- .../smoketest/HttpClientSmokeTest.java | 79 ------------------- 1 file changed, 79 deletions(-) diff --git a/smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpClientSmokeTest.java b/smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpClientSmokeTest.java index 4e89c259080..779be3cfb6b 100644 --- a/smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpClientSmokeTest.java +++ b/smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpClientSmokeTest.java @@ -32,14 +32,6 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9; import static org.assertj.core.api.Assertions.assertThat; -import com.microsoft.applicationinsights.smoketest.schemav2.Data; -import com.microsoft.applicationinsights.smoketest.schemav2.DataPoint; -import com.microsoft.applicationinsights.smoketest.schemav2.Envelope; -import com.microsoft.applicationinsights.smoketest.schemav2.MetricData; -import java.util.Comparator; -import java.util.List; -import java.util.Map; -import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -142,77 +134,6 @@ private static void verify(String successUrlWithQueryString) throws Exception { telemetry.rd, telemetry.rdEnvelope, telemetry.rddEnvelope2, "GET /HttpClients/*"); SmokeTestExtension.assertParentChild( telemetry.rd, telemetry.rdEnvelope, telemetry.rddEnvelope3, "GET /HttpClients/*"); - - verifyPreAggregatedMetrics("http.client.duration"); - } - - private static void verifyPreAggregatedMetrics(String name) throws Exception { - List metrics = - testing.mockedIngestion.waitForItems( - SmokeTestExtension.getMetricPredicate(name), 3, 40, TimeUnit.SECONDS); - - // sort metrics based on result code - metrics.sort( - Comparator.comparing( - obj -> { - MetricData metricData = (MetricData) ((Data) obj.getData()).getBaseData(); - return metricData.getProperties().get("request/resultCode"); - })); - - // 1st pre-aggregated metric - Envelope envelope1 = metrics.get(0); - validateTags(envelope1); - MetricData md1 = (MetricData) ((Data) envelope1.getData()).getBaseData(); - validateMetricData(md1, "200"); - - // 2nd pre-aggregated metric - Envelope envelope2 = metrics.get(1); - validateTags(envelope2); - MetricData md2 = (MetricData) ((Data) envelope2.getData()).getBaseData(); - validateMetricData(md2, "404"); - - // 3rd pre-aggregated metric - Envelope envelope3 = metrics.get(2); - validateTags(envelope3); - MetricData md3 = (MetricData) ((Data) envelope3.getData()).getBaseData(); - validateMetricData(md3, "500"); - } - - private static void validateTags(Envelope envelope) { - Map tags = envelope.getTags(); - assertThat(tags.get("ai.internal.sdkVersion")).isNotNull(); - assertThat(tags).containsEntry("ai.cloud.roleInstance", "testroleinstance"); - assertThat(tags).containsEntry("ai.cloud.role", "testrolename"); - } - - private static void validateMetricData(MetricData metricData, String resultCode) { - List dataPoints = metricData.getMetrics(); - assertThat(dataPoints).hasSize(1); - DataPoint dataPoint = dataPoints.get(0); - assertThat(dataPoint.getCount()).isEqualTo(1); - assertThat(dataPoint.getValue()).isGreaterThan(0d).isLessThan(5 * 60 * 1000d); // (0 - 5) min - assertThat(dataPoint.getMin()).isGreaterThan(0d).isLessThan(5 * 60 * 1000d); // (0 - 5) min - assertThat(dataPoint.getMin()).isGreaterThan(0d).isLessThan(5 * 60 * 1000d); // (0 - 5) min - Map properties = metricData.getProperties(); - assertThat(properties.get("request/resultCode")).isEqualTo(resultCode); - - double value = metricData.getMetrics().get(0).getValue(); - assertThat(properties.get("request/performanceBucket")).isEqualTo(getPerformanceBucket(value)); - if ("200".equals(resultCode)) { - assertThat(properties.get("request/success")).isEqualTo("True"); - } else { - assertThat(properties.get("request/success")).isEqualTo("False"); - } - assertThat(properties.get("operation/synthetic")).isEqualTo("False"); - assertThat(properties.get("_MS.metricId")).isEqualTo("requests/duration"); - assertThat(properties.get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); - assertThat(properties.get("cloud/roleInstance")).isEqualTo("testroleinstance"); - assertThat(properties.get("cloud/roleName")).isEqualTo("testrolename"); - assertThat(properties.get("_MS.IsAutocollected")).isEqualTo("True"); - } - - private static String getPerformanceBucket(double duration) { - return DurationBucketizer.getPerformanceBucket(duration); } @Environment(TOMCAT_8_JAVA_8) From 8d1abbdd5752f336154a298b04e533a845d47e4d Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 11 Aug 2022 18:35:39 -0700 Subject: [PATCH 27/95] Fix preaggregated metrics smoke test --- .../HttpPreaggregatedMetricsTestServlet.java | 14 +++- .../HttpPreaggregatedMetricsSmokeTest.java | 67 +++++++++++++------ 2 files changed, 57 insertions(+), 24 deletions(-) diff --git a/smoke-tests/apps/HttpPreaggregatedMetrics/src/main/java/com/microsoft/applicationinsights/smoketestapp/HttpPreaggregatedMetricsTestServlet.java b/smoke-tests/apps/HttpPreaggregatedMetrics/src/main/java/com/microsoft/applicationinsights/smoketestapp/HttpPreaggregatedMetricsTestServlet.java index 86cfcf24e7e..74b537dc962 100644 --- a/smoke-tests/apps/HttpPreaggregatedMetrics/src/main/java/com/microsoft/applicationinsights/smoketestapp/HttpPreaggregatedMetricsTestServlet.java +++ b/smoke-tests/apps/HttpPreaggregatedMetrics/src/main/java/com/microsoft/applicationinsights/smoketestapp/HttpPreaggregatedMetricsTestServlet.java @@ -30,8 +30,6 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.commons.httpclient.Cookie; -import org.apache.commons.httpclient.cookie.CookieSpecBase; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; @@ -63,7 +61,17 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se // "/httpUrlConnection" private void doGetInternal(HttpServletRequest req) throws Exception { String pathInfo = req.getPathInfo(); - ExecuteGetUrl executeGetUrl = this::httpUrlConnection; + final ExecuteGetUrl executeGetUrl; + switch (pathInfo) { + case "/": + executeGetUrl = null; + break; + case "/httpUrlConnection": + executeGetUrl = this::httpUrlConnection; + break; + default: + throw new ServletException("Unexpected url: " + pathInfo); + } if (executeGetUrl != null) { executeGetUrl.execute("https://mock.codes/200?q=spaces%20test"); diff --git a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java index 9dabb18b311..dbe37915eab 100644 --- a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java +++ b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java @@ -59,36 +59,61 @@ private static void verify() throws Exception { } private static void verify(String successUrlWithQueryString) throws Exception { - Telemetry telemetry = testing.getTelemetry(1); - - assertThat(telemetry.rd.getProperties()).isEmpty(); - assertThat(telemetry.rd.getSuccess()).isTrue(); - assertThat(telemetry.rdEnvelope.getSampleRate()).isNull(); + List clientMetrics = + testing.mockedIngestion.waitForItems( + SmokeTestExtension.getMetricPredicate("http.client.duration"), 3, 40, TimeUnit.SECONDS); + List serverMetrics = + testing.mockedIngestion.waitForItems( + SmokeTestExtension.getMetricPredicate("http.server.duration"), 2, 40, TimeUnit.SECONDS); - assertThat(telemetry.rdd1.getName()).isEqualTo("GET /200"); - assertThat(telemetry.rdd1.getData()).isEqualTo(successUrlWithQueryString); - assertThat(telemetry.rdd1.getType()).isEqualTo("Http"); - assertThat(telemetry.rdd1.getTarget()).isEqualTo("mock.codes"); - assertThat(telemetry.rdd1.getResultCode()).isEqualTo("200"); - assertThat(telemetry.rdd1.getProperties()).isEmpty(); - assertThat(telemetry.rdd1.getSuccess()).isTrue(); - assertThat(telemetry.rddEnvelope1.getSampleRate()).isNull(); + verifyHttpClientPreAggregatedMetrics(clientMetrics); + verifyHttpServerPreAggregatedMetrics(serverMetrics); + } - SmokeTestExtension.assertParentChild( - telemetry.rd, telemetry.rdEnvelope, telemetry.rddEnvelope1, "GET /HttpPreaggregatedMetrics/*"); + private static void verifyHttpClientPreAggregatedMetrics(List metrics) + throws Exception { + assertThat(metrics.size()).isEqualTo(3); + // sort metrics based on result code + metrics.sort( + Comparator.comparing( + obj -> { + MetricData metricData = (MetricData) ((Data) obj.getData()).getBaseData(); + return metricData.getProperties().get("request/resultCode"); + })); + + // 1st pre-aggregated metric + Envelope envelope1 = metrics.get(0); + validateTags(envelope1); + MetricData md1 = (MetricData) ((Data) envelope1.getData()).getBaseData(); + validateMetricData(md1, "200"); - verifyPreAggregatedMetrics("http.client.duration"); + // 2nd pre-aggregated metric + Envelope envelope2 = metrics.get(1); + validateTags(envelope2); + MetricData md2 = (MetricData) ((Data) envelope2.getData()).getBaseData(); + validateMetricData(md2, "404"); + + // 3rd pre-aggregated metric + Envelope envelope3 = metrics.get(2); + validateTags(envelope3); + MetricData md3 = (MetricData) ((Data) envelope3.getData()).getBaseData(); + validateMetricData(md3, "500"); } - private static void verifyPreAggregatedMetrics(String name) throws Exception { - List metrics = - testing.mockedIngestion.waitForItems( - SmokeTestExtension.getMetricPredicate(name), 1, 20, TimeUnit.SECONDS); - + private static void verifyHttpServerPreAggregatedMetrics(List metrics) + throws Exception { + assertThat(metrics.size()).isEqualTo(2); + // 1st pre-aggregated metric Envelope envelope1 = metrics.get(0); validateTags(envelope1); MetricData md1 = (MetricData) ((Data) envelope1.getData()).getBaseData(); validateMetricData(md1, "200"); + + // 2nd pre-aggregated metric + Envelope envelope2 = metrics.get(1); + validateTags(envelope2); + MetricData md2 = (MetricData) ((Data) envelope2.getData()).getBaseData(); + validateMetricData(md2, "200"); } private static void validateTags(Envelope envelope) { From d0b9c7d1c634a529f1a432eb8cd99a045e535a77 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 11 Aug 2022 18:38:32 -0700 Subject: [PATCH 28/95] Delete a todo that has been resolved --- .../opentelemetry/exporter/implementation/MetricDataMapper.java | 1 - 1 file changed, 1 deletion(-) diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index 0422933e654..a315bd884d6 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -155,7 +155,6 @@ public static void updateMetricPointBuilder( metricTelemetryBuilder.setMetricPoint(pointBuilder); if (isPreAggregated) { - // TODO update value if applicable Long statusCode = pointData.getAttributes().get(AttributeKey.longKey("http.status_code")); updatePreAggMetricsCustomDimensions( metricTelemetryBuilder, From 93474a036022a0b2e8f98aeeb26424395b445b1a Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 11 Aug 2022 18:49:18 -0700 Subject: [PATCH 29/95] Delete stdout --- .../api/instrumenter/rpc/RpcClientMetrics.java | 4 ---- .../api/instrumenter/rpc/RpcServerMetrics.java | 4 ---- 2 files changed, 8 deletions(-) diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java index 895d74877c3..fde769ca1c0 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java @@ -90,10 +90,6 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { } double duration = (endNanos - state.startTimeNanos()) / NANOS_PER_MS; - System.out.println("##################### client.duration: " + duration); - System.out.println( - "##################### client.perfBucket: " - + DurationBucketizer.getPerformanceBucket(duration)); endAttributes = endAttributes.toBuilder() .put(AI_PERFORMANCE_BUCKET, DurationBucketizer.getPerformanceBucket(duration)) diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java index 8923a248bf3..d0f58d93dfd 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java @@ -90,10 +90,6 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { } double duration = (endNanos - state.startTimeNanos()) / NANOS_PER_MS; - System.out.println("##################### server.duration: " + duration); - System.out.println( - "##################### server.perfBucket: " - + DurationBucketizer.getPerformanceBucket(duration)); endAttributes = endAttributes.toBuilder() .put(AI_PERFORMANCE_BUCKET, DurationBucketizer.getPerformanceBucket(duration)) From 8f667aa910bc53ccca8e62ac5b5b964bf399201f Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 11 Aug 2022 21:27:50 -0700 Subject: [PATCH 30/95] Delete unused dependencies and ivar --- smoke-tests/apps/HttpPreaggregatedMetrics/build.gradle.kts | 6 ------ .../smoketestapp/HttpPreaggregatedMetricsTestServlet.java | 4 ---- 2 files changed, 10 deletions(-) diff --git a/smoke-tests/apps/HttpPreaggregatedMetrics/build.gradle.kts b/smoke-tests/apps/HttpPreaggregatedMetrics/build.gradle.kts index df7ba21fe59..a9e435f4eec 100644 --- a/smoke-tests/apps/HttpPreaggregatedMetrics/build.gradle.kts +++ b/smoke-tests/apps/HttpPreaggregatedMetrics/build.gradle.kts @@ -3,13 +3,7 @@ plugins { } dependencies { - implementation("org.apache.httpcomponents:httpclient:4.5.13") implementation("org.apache.httpcomponents:httpasyncclient:4.1.4") - implementation("commons-httpclient:commons-httpclient:3.1") - implementation("com.squareup.okhttp3:okhttp:3.12.1") - implementation("com.squareup.okhttp:okhttp:2.7.5") - implementation("org.springframework:spring-webflux:5.2.3.RELEASE") // for testing netty client - implementation("io.projectreactor.netty:reactor-netty:0.9.4.RELEASE") // needed for above // this dependency is needed to make wildfly happy implementation("com.fasterxml.jackson.core:jackson-databind:2.9.4") } diff --git a/smoke-tests/apps/HttpPreaggregatedMetrics/src/main/java/com/microsoft/applicationinsights/smoketestapp/HttpPreaggregatedMetricsTestServlet.java b/smoke-tests/apps/HttpPreaggregatedMetrics/src/main/java/com/microsoft/applicationinsights/smoketestapp/HttpPreaggregatedMetricsTestServlet.java index 74b537dc962..49b5e192b98 100644 --- a/smoke-tests/apps/HttpPreaggregatedMetrics/src/main/java/com/microsoft/applicationinsights/smoketestapp/HttpPreaggregatedMetricsTestServlet.java +++ b/smoke-tests/apps/HttpPreaggregatedMetrics/src/main/java/com/microsoft/applicationinsights/smoketestapp/HttpPreaggregatedMetricsTestServlet.java @@ -30,16 +30,12 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; import org.apache.http.impl.nio.client.HttpAsyncClients; @WebServlet("/*") public class HttpPreaggregatedMetricsTestServlet extends HttpServlet { - private final CloseableHttpClient httpClient = - HttpClientBuilder.create().disableAutomaticRetries().build(); private final CloseableHttpAsyncClient httpAsyncClient = HttpAsyncClients.createDefault(); public HttpPreaggregatedMetricsTestServlet() { From 5a598cab871b87fcbfd7080d3abe3e4e8ded4bd9 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 11 Aug 2022 22:31:46 -0700 Subject: [PATCH 31/95] Verify rpc pre-aggregated metrics --- .../smoketest/DurationBucketizer.java | 59 ++++++++++++++ .../smoketest/GrpcTest.java | 78 +++++++++++++++++++ .../resources/applicationinsights.json | 10 +++ 3 files changed, 147 insertions(+) create mode 100644 smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/DurationBucketizer.java create mode 100644 smoke-tests/apps/gRPC/src/smokeTest/resources/applicationinsights.json diff --git a/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/DurationBucketizer.java b/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/DurationBucketizer.java new file mode 100644 index 00000000000..82dccddc57e --- /dev/null +++ b/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/DurationBucketizer.java @@ -0,0 +1,59 @@ +/* + * ApplicationInsights-Java + * Copyright (c) Microsoft Corporation + * All rights reserved. + * + * MIT License + * Permission is hereby granted, free of charge, to any person obtaining a copy of this + * software and associated documentation files (the ""Software""), to deal in the Software + * without restriction, including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, and to permit + * persons to whom the Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package com.microsoft.applicationinsights.smoketest; + +import java.util.LinkedHashMap; +import java.util.Map; + +// copied from link{com.microsoft.applicationinsights.agent.bootstrap.DurationBucketizer} +public final class DurationBucketizer { + + public static final String AI_PERFORMANCE_BUCKET = "ai.performance.bucket"; + + // sorted HashMap + private static final Map performanceBuckets = new LinkedHashMap<>(); + + static { + performanceBuckets.put("<250ms", 250d); + performanceBuckets.put("250ms-500ms", 500d); + performanceBuckets.put("500ms-1sec", 1000d); + performanceBuckets.put("1sec-3sec", 3000d); + performanceBuckets.put("3sec-7sec", 7000d); + performanceBuckets.put("7sec-15sec", 15000d); + performanceBuckets.put("15sec-30sec", 30000d); + performanceBuckets.put("30sec-1min", 60000d); + performanceBuckets.put("1min-2min", 120000d); + performanceBuckets.put("2min-5min", 300000d); + performanceBuckets.put(">=5min", Double.MAX_VALUE); + } + + public static String getPerformanceBucket(double durationInMillis) { + for (Map.Entry entry : performanceBuckets.entrySet()) { + if (durationInMillis < entry.getValue()) { + return entry.getKey(); + } + } + return ">=5min"; + } + + private DurationBucketizer() {} +} diff --git a/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java b/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java index 8bcb9ddf068..52192245d08 100644 --- a/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java +++ b/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java @@ -33,10 +33,14 @@ import static org.assertj.core.api.Assertions.assertThat; import com.microsoft.applicationinsights.smoketest.schemav2.Data; +import com.microsoft.applicationinsights.smoketest.schemav2.DataPoint; import com.microsoft.applicationinsights.smoketest.schemav2.Envelope; +import com.microsoft.applicationinsights.smoketest.schemav2.MetricData; import com.microsoft.applicationinsights.smoketest.schemav2.RemoteDependencyData; import com.microsoft.applicationinsights.smoketest.schemav2.RequestData; import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -49,6 +53,12 @@ abstract class GrpcTest { @TargetUri("/simple") void doSimpleTest() throws Exception { List rdList = testing.mockedIngestion.waitForItems("RequestData", 2); + List rpcClientDurationMetrics = + testing.mockedIngestion.waitForItems( + SmokeTestExtension.getMetricPredicate("rpc.client.duration"), 2, 40, TimeUnit.SECONDS); + List rpcServerMetrics = + testing.mockedIngestion.waitForItems( + SmokeTestExtension.getMetricPredicate("rpc.server.duration"), 2, 40, TimeUnit.SECONDS); Envelope rdEnvelope1 = getRequestEnvelope(rdList, "GET /simple"); Envelope rdEnvelope2 = getRequestEnvelope(rdList, "example.Greeter/SayHello"); @@ -82,6 +92,9 @@ void doSimpleTest() throws Exception { SmokeTestExtension.assertParentChild(rd1, rdEnvelope1, rddEnvelope, "GET /simple"); SmokeTestExtension.assertParentChild( rdd.getId(), rddEnvelope, rdEnvelope2, "GET /simple", "example.Greeter/SayHello", false); + + verifyRpcClientDurationPreAggregatedMetrics(rpcClientDurationMetrics); + verifyRpcServerDurationPreAggregatedMetrics(rpcServerMetrics); } @Test @@ -149,6 +162,71 @@ private static Envelope getDependencyEnvelope(List envelopes, String n throw new IllegalStateException("Could not find dependency with name: " + name); } + private static void verifyRpcClientDurationPreAggregatedMetrics(List metrics) + throws Exception { + assertThat(metrics.size()).isEqualTo(2); + + // 1st pre-aggregated metric + Envelope envelope1 = metrics.get(0); + validateTags(envelope1); + MetricData md1 = (MetricData) ((Data) envelope1.getData()).getBaseData(); + validateMetricData(md1); + + // 2nd pre-aggregated metric + Envelope envelope2 = metrics.get(1); + validateTags(envelope2); + MetricData md2 = (MetricData) ((Data) envelope2.getData()).getBaseData(); + validateMetricData(md2); + } + + private static void verifyRpcServerDurationPreAggregatedMetrics(List metrics) + throws Exception { + assertThat(metrics.size()).isEqualTo(2); + // 1st pre-aggregated metric + Envelope envelope1 = metrics.get(0); + validateTags(envelope1); + MetricData md1 = (MetricData) ((Data) envelope1.getData()).getBaseData(); + validateMetricData(md1); + + // 2nd pre-aggregated metric + Envelope envelope2 = metrics.get(1); + validateTags(envelope2); + MetricData md2 = (MetricData) ((Data) envelope2.getData()).getBaseData(); + validateMetricData(md2); + } + + private static void validateTags(Envelope envelope) { + Map tags = envelope.getTags(); + assertThat(tags.get("ai.internal.sdkVersion")).isNotNull(); + assertThat(tags).containsEntry("ai.cloud.roleInstance", "testroleinstance"); + assertThat(tags).containsEntry("ai.cloud.role", "testrolename"); + } + + private static void validateMetricData(MetricData metricData) { + List dataPoints = metricData.getMetrics(); + assertThat(dataPoints).hasSize(1); + DataPoint dataPoint = dataPoints.get(0); + assertThat(dataPoint.getCount()).isEqualTo(1); + assertThat(dataPoint.getValue()).isGreaterThan(0d).isLessThan(5 * 60 * 1000d); // (0 - 5) min + assertThat(dataPoint.getMin()).isGreaterThan(0d).isLessThan(5 * 60 * 1000d); // (0 - 5) min + assertThat(dataPoint.getMin()).isGreaterThan(0d).isLessThan(5 * 60 * 1000d); // (0 - 5) min + Map properties = metricData.getProperties(); + assertThat(properties.get("request/resultCode")).isNull(); + double value = metricData.getMetrics().get(0).getValue(); + assertThat(properties.get("request/performanceBucket")).isEqualTo(getPerformanceBucket(value)); + assertThat(properties.get("request/success")).isEqualTo("True"); + assertThat(properties.get("operation/synthetic")).isEqualTo("False"); + assertThat(properties.get("_MS.metricId")).isEqualTo("requests/duration"); + assertThat(properties.get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(properties.get("cloud/roleInstance")).isEqualTo("testroleinstance"); + assertThat(properties.get("cloud/roleName")).isEqualTo("testrolename"); + assertThat(properties.get("_MS.IsAutocollected")).isEqualTo("True"); + } + + private static String getPerformanceBucket(double duration) { + return DurationBucketizer.getPerformanceBucket(duration); + } + @Environment(JAVA_8) static class Java8Test extends GrpcTest {} diff --git a/smoke-tests/apps/gRPC/src/smokeTest/resources/applicationinsights.json b/smoke-tests/apps/gRPC/src/smokeTest/resources/applicationinsights.json new file mode 100644 index 00000000000..fabbaf6c881 --- /dev/null +++ b/smoke-tests/apps/gRPC/src/smokeTest/resources/applicationinsights.json @@ -0,0 +1,10 @@ +{ + "connectionString": "InstrumentationKey=00000000-0000-0000-0000-0FEEDDADBEEF;IngestionEndpoint=http://host.docker.internal:6060/", + "role": { + "name": "testrolename", + "instance": "testroleinstance" + }, + "preview": { + "metricIntervalSeconds": 10 + } +} \ No newline at end of file From cb2f9c6f621e4d8303a50e2d0f0a564e7ad9bd2f Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 11 Aug 2022 22:32:58 -0700 Subject: [PATCH 32/95] Generate rpcClientMetrics to check its metric content --- .../exporter/PreAggregatedMetricsTest.java | 75 ++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java index 00ca3b57afe..21eeacf1e88 100644 --- a/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java +++ b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java @@ -45,6 +45,7 @@ import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics; +import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcClientMetrics; import io.opentelemetry.sdk.metrics.SdkMeterProvider; import io.opentelemetry.sdk.metrics.data.MetricData; import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; @@ -69,7 +70,7 @@ void setup() { @SuppressWarnings("SystemOut") @Test - void testHttpClientRequestDuration() { + void generateHttpClientMetrics() { OperationListener listener = HttpClientMetrics.get().create(meterProvider.get("test")); Attributes requestAttributes = @@ -148,6 +149,78 @@ void testHttpClientRequestDuration() { .containsExactlyInAnyOrderEntriesOf(generateExpectedProperties()); } + @SuppressWarnings("SystemOut") + @Test + void generateRpcClientMetrics() { + OperationListener listener = RpcClientMetrics.get().create(meterProvider.get("test")); + + Attributes requestAttributes = + Attributes.builder() + .put(SemanticAttributes.RPC_SYSTEM, "grpc") + .put(SemanticAttributes.RPC_SERVICE, "myservice.EchoService") + .put(SemanticAttributes.RPC_METHOD, "exampleMethod") + .build(); + + Attributes responseAttributes1 = + Attributes.builder() + .put(SemanticAttributes.NET_PEER_NAME, "example.com") + .put(SemanticAttributes.NET_PEER_IP, "127.0.0.1") + .put(SemanticAttributes.NET_PEER_PORT, 8080) + .put(SemanticAttributes.NET_TRANSPORT, "ip_tcp") + .build(); + + Context parent = + Context.root() + .with( + Span.wrap( + SpanContext.create( + "ff01020304050600ff0a0b0c0d0e0f00", + "090a0b0c0d0e0f00", + TraceFlags.getSampled(), + TraceState.getDefault()))); + + Context context1 = listener.onStart(parent, requestAttributes, nanos(100)); + + assertThat(metricReader.collectAllMetrics()).isEmpty(); + + listener.onEnd(context1, responseAttributes1, nanos(250)); + + Collection metricDataCollection = metricReader.collectAllMetrics(); + for (MetricData metricData : metricDataCollection) { + System.out.println("metric: " + metricData); + } + + assertThat(metricDataCollection.size()).isEqualTo(1); + + assertThat(metricDataCollection) + .satisfiesExactlyInAnyOrder( + metric -> + assertThat(metric) + .hasName("rpc.client.duration") + .hasUnit("ms") + .hasHistogramSatisfying( + histogram -> + histogram.hasPointsSatisfying( + point -> + point + .hasSum(150 /* millis */) + .hasAttributesSatisfying( + equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"), + equalTo( + SemanticAttributes.RPC_SERVICE, + "myservice.EchoService"), + equalTo(SemanticAttributes.RPC_METHOD, "exampleMethod"), + equalTo( + SemanticAttributes.NET_PEER_NAME, "example.com"), + equalTo(SemanticAttributes.NET_PEER_PORT, 8080), + equalTo(SemanticAttributes.NET_TRANSPORT, "ip_tcp")) + .hasExemplarsSatisfying( + exemplar -> + exemplar + .hasTraceId("ff01020304050600ff0a0b0c0d0e0f00") + .hasSpanId("090a0b0c0d0e0f00"))))); + } + private static long nanos(int millis) { return TimeUnit.MILLISECONDS.toNanos(millis); } From ec5616aff78b66c8e7e9a4bdf3abac1323919900 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 11 Aug 2022 22:33:45 -0700 Subject: [PATCH 33/95] Fix NPE and fix perfBucket is not part of rpc metrics attributes --- .../instrumentation/api/instrumenter/rpc/MetricsView.java | 2 ++ .../RequestCustomDimensionsExtractor.java | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java index d8ca7b330a2..618894a3cac 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java @@ -24,6 +24,7 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.AttributesBuilder; +import io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.HashSet; import java.util.Set; @@ -47,6 +48,7 @@ private static Set buildAlwaysInclude() { view.add(SemanticAttributes.RPC_SYSTEM); view.add(SemanticAttributes.RPC_SERVICE); view.add(SemanticAttributes.RPC_METHOD); + view.add(AttributeKey.stringKey(DurationBucketizer.AI_PERFORMANCE_BUCKET)); return view; } diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestCustomDimensionsExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestCustomDimensionsExtractor.java index b7f7fef26b2..df53e6f01f4 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestCustomDimensionsExtractor.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestCustomDimensionsExtractor.java @@ -43,16 +43,18 @@ public final class RequestCustomDimensionsExtractor { public static void updatePreAggMetricsCustomDimensions( AbstractTelemetryBuilder metricTelemetryBuilder, String perfBucket, - long statusCode, + Long statusCode, boolean success) { metricTelemetryBuilder.addProperty(MS_METRIC_ID, REQUEST_METRIC_ID); metricTelemetryBuilder.addProperty(MS_IS_AUTOCOLLECTED, TRUE); // this flag will inform the ingestion service to stop post-aggregation metricTelemetryBuilder.addProperty(MS_PROCESSED_BY_METRIC_EXTRACTORS, TRUE); - // TODO figure out the correct duration/value metricTelemetryBuilder.addProperty(PERFORMANCE_BUCKET, perfBucket); - metricTelemetryBuilder.addProperty(REQUEST_RESULT_CODE, String.valueOf(statusCode)); + // TODO how to assign "request/result_code" to RPC duration metrics? + if (statusCode != null) { + metricTelemetryBuilder.addProperty(REQUEST_RESULT_CODE, String.valueOf(statusCode)); + } metricTelemetryBuilder.addProperty(OPERATION_SYNTHETIC, FALSE); if (metricTelemetryBuilder.build().getTags() != null) { From ea60a0a0f37ff47646810aa47d53e7e1c9a8e363 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Mon, 15 Aug 2022 14:43:49 -0700 Subject: [PATCH 34/95] Send rpc/http.client as dependencies/duration and rpc/http.server as requests/duration --- .../implementation/MetricDataMapper.java | 31 +++++++-- ...sionsExtractor.java => BaseExtractor.java} | 52 ++++++-------- .../DependencyExtractor.java | 69 +++++++++++++++++++ .../RequestExtractor.java | 58 ++++++++++++++++ .../exporter/PreAggregatedMetricsTest.java | 44 ++++++++---- 5 files changed, 203 insertions(+), 51 deletions(-) rename agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/{RequestCustomDimensionsExtractor.java => BaseExtractor.java} (57%) create mode 100644 agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java create mode 100644 agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index a315bd884d6..8aba557e8c2 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -21,7 +21,6 @@ package com.azure.monitor.opentelemetry.exporter.implementation; -import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.updatePreAggMetricsCustomDimensions; import static io.opentelemetry.api.internal.Utils.checkArgument; import static io.opentelemetry.sdk.metrics.data.MetricDataType.DOUBLE_GAUGE; import static io.opentelemetry.sdk.metrics.data.MetricDataType.DOUBLE_SUM; @@ -33,6 +32,8 @@ import com.azure.monitor.opentelemetry.exporter.implementation.builders.MetricPointBuilder; import com.azure.monitor.opentelemetry.exporter.implementation.builders.MetricTelemetryBuilder; import com.azure.monitor.opentelemetry.exporter.implementation.models.TelemetryItem; +import com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.DependencyExtractor; +import com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestExtractor; import com.azure.monitor.opentelemetry.exporter.implementation.utils.FormattedTime; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.sdk.metrics.data.DoublePointData; @@ -156,11 +157,29 @@ public static void updateMetricPointBuilder( if (isPreAggregated) { Long statusCode = pointData.getAttributes().get(AttributeKey.longKey("http.status_code")); - updatePreAggMetricsCustomDimensions( - metricTelemetryBuilder, - pointData.getAttributes().get(AttributeKey.stringKey("ai.performance.bucket")), - statusCode, - getSuccess(statusCode, captureHttpServer4xxAsError)); + String performanceBucket = + pointData.getAttributes().get(AttributeKey.stringKey("ai.performance.bucket")); + boolean success = getSuccess(statusCode, captureHttpServer4xxAsError); + if (metricData.getName().contains(".server.")) { + RequestExtractor requestExtractor = + new RequestExtractor(metricTelemetryBuilder, performanceBucket, statusCode, success); + requestExtractor.extract(); + } else if (metricData.getName().contains(".client.")) { + String dependencyType = + metricData.getName().startsWith("http") + ? "http" + : (String) pointData.getAttributes().get(SemanticAttributes.RPC_SYSTEM); + String target = pointData.getAttributes().get(AttributeKey.stringKey("target")); + DependencyExtractor dependencyExtractor = + new DependencyExtractor( + metricTelemetryBuilder, + performanceBucket, + statusCode, + success, + dependencyType, + target); + dependencyExtractor.extract(); + } } else { pointData .getAttributes() diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestCustomDimensionsExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/BaseExtractor.java similarity index 57% rename from agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestCustomDimensionsExtractor.java rename to agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/BaseExtractor.java index df53e6f01f4..df72f573215 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestCustomDimensionsExtractor.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/BaseExtractor.java @@ -24,57 +24,47 @@ import com.azure.monitor.opentelemetry.exporter.implementation.builders.AbstractTelemetryBuilder; import com.azure.monitor.opentelemetry.exporter.implementation.models.ContextTagKeys; -public final class RequestCustomDimensionsExtractor { +public abstract class BaseExtractor { // visible for testing public static final String MS_METRIC_ID = "_MS.metricId"; - public static final String REQUEST_METRIC_ID = "requests/duration"; public static final String MS_IS_AUTOCOLLECTED = "_MS.IsAutocollected"; + public static final String MS_PROCESSED_BY_METRIC_EXTRACTORS = "_MS.ProcessedByMetricExtractors"; public static final String TRUE = "True"; public static final String FALSE = "False"; - public static final String MS_PROCESSED_BY_METRIC_EXTRACTORS = "_MS.ProcessedByMetricExtractors"; - public static final String PERFORMANCE_BUCKET = "request/performanceBucket"; - public static final String REQUEST_RESULT_CODE = "request/resultCode"; public static final String OPERATION_SYNTHETIC = "operation/synthetic"; public static final String CLOUD_ROLE_NAME = "cloud/roleName"; public static final String CLOUD_ROLE_INSTANCE = "cloud/roleInstance"; - public static final String REQUEST_SUCCESS = "request/success"; - public static void updatePreAggMetricsCustomDimensions( - AbstractTelemetryBuilder metricTelemetryBuilder, - String perfBucket, - Long statusCode, - boolean success) { - metricTelemetryBuilder.addProperty(MS_METRIC_ID, REQUEST_METRIC_ID); - metricTelemetryBuilder.addProperty(MS_IS_AUTOCOLLECTED, TRUE); - // this flag will inform the ingestion service to stop post-aggregation - metricTelemetryBuilder.addProperty(MS_PROCESSED_BY_METRIC_EXTRACTORS, TRUE); + protected final AbstractTelemetryBuilder telemetryBuilder; - metricTelemetryBuilder.addProperty(PERFORMANCE_BUCKET, perfBucket); - // TODO how to assign "request/result_code" to RPC duration metrics? - if (statusCode != null) { - metricTelemetryBuilder.addProperty(REQUEST_RESULT_CODE, String.valueOf(statusCode)); - } - metricTelemetryBuilder.addProperty(OPERATION_SYNTHETIC, FALSE); + public BaseExtractor(AbstractTelemetryBuilder telemetryBuilder) { + this.telemetryBuilder = telemetryBuilder; + extractCommon(); + } + + private void extractCommon() { + telemetryBuilder.addProperty(MS_IS_AUTOCOLLECTED, TRUE); + // this flag will inform the ingestion service to stop post-aggregation + telemetryBuilder.addProperty(MS_PROCESSED_BY_METRIC_EXTRACTORS, TRUE); - if (metricTelemetryBuilder.build().getTags() != null) { + if (telemetryBuilder.build().getTags() != null) { String cloudName = - metricTelemetryBuilder.build().getTags().get(ContextTagKeys.AI_CLOUD_ROLE.toString()); + telemetryBuilder.build().getTags().get(ContextTagKeys.AI_CLOUD_ROLE.toString()); if (cloudName != null && !cloudName.isEmpty()) { - metricTelemetryBuilder.addProperty(CLOUD_ROLE_NAME, cloudName); + telemetryBuilder.addProperty(CLOUD_ROLE_NAME, cloudName); } String cloudRoleInstance = - metricTelemetryBuilder - .build() - .getTags() - .get(ContextTagKeys.AI_CLOUD_ROLE_INSTANCE.toString()); + telemetryBuilder.build().getTags().get(ContextTagKeys.AI_CLOUD_ROLE_INSTANCE.toString()); if (cloudRoleInstance != null && !cloudRoleInstance.isEmpty()) { - metricTelemetryBuilder.addProperty(CLOUD_ROLE_INSTANCE, cloudRoleInstance); + telemetryBuilder.addProperty(CLOUD_ROLE_INSTANCE, cloudRoleInstance); } } - metricTelemetryBuilder.addProperty(REQUEST_SUCCESS, success ? TRUE : FALSE); + + // This is not supported yet. Default to false. + telemetryBuilder.addProperty(OPERATION_SYNTHETIC, FALSE); } - private RequestCustomDimensionsExtractor() {} + public abstract void extract(); } diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java new file mode 100644 index 00000000000..f896515c62d --- /dev/null +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java @@ -0,0 +1,69 @@ +/* + * ApplicationInsights-Java + * Copyright (c) Microsoft Corporation + * All rights reserved. + * + * MIT License + * Permission is hereby granted, free of charge, to any person obtaining a copy of this + * software and associated documentation files (the ""Software""), to deal in the Software + * without restriction, including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, and to permit + * persons to whom the Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics; + +import com.azure.monitor.opentelemetry.exporter.implementation.builders.AbstractTelemetryBuilder; + +public class DependencyExtractor extends BaseExtractor { + + // visible for testing + public static final String DEPENDENCIES_DURATION = "dependencies/duration"; + public static final String DEPENDENCY_TYPE = "dependency/type"; + public static final String DEPENDENCY_PERFORMANCE_BUCKET = "dependency/performanceBucket"; + public static final String DEPENDENCY_SUCCESS = "dependency/success"; + public static final String DEPENDENCY_TARGET = "dependency/target"; + public static final String DEPENDENCY_RESULT_CODE = "dependency/resultCode"; + + private final String performanceBucket; + private final Long statusCode; + private final boolean success; + private final String type; + private final String target; + + public DependencyExtractor( + AbstractTelemetryBuilder telemetryBuilder, + String performanceBucket, + Long statusCode, + boolean success, + String type, + String target) { + super(telemetryBuilder); + this.performanceBucket = performanceBucket; + this.statusCode = statusCode; + this.success = success; + this.type = type; + this.target = target; + } + + @Override + public void extract() { + telemetryBuilder.addProperty(MS_METRIC_ID, DEPENDENCIES_DURATION); + telemetryBuilder.addProperty(DEPENDENCY_PERFORMANCE_BUCKET, performanceBucket); + // TODO OTEL will provide rpc.grpc.status_code & rpc.success, http.success + if (statusCode != null) { + telemetryBuilder.addProperty(DEPENDENCY_RESULT_CODE, String.valueOf(statusCode)); + } + telemetryBuilder.addProperty(DEPENDENCY_SUCCESS, success ? TRUE : FALSE); + telemetryBuilder.addProperty(DEPENDENCY_TYPE, type); + telemetryBuilder.addProperty(DEPENDENCY_TARGET, target); + } +} diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java new file mode 100644 index 00000000000..f90325f053c --- /dev/null +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java @@ -0,0 +1,58 @@ +/* + * ApplicationInsights-Java + * Copyright (c) Microsoft Corporation + * All rights reserved. + * + * MIT License + * Permission is hereby granted, free of charge, to any person obtaining a copy of this + * software and associated documentation files (the ""Software""), to deal in the Software + * without restriction, including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, and to permit + * persons to whom the Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics; + +import com.azure.monitor.opentelemetry.exporter.implementation.builders.AbstractTelemetryBuilder; + +public final class RequestExtractor extends BaseExtractor { + + private static final String REQUEST_METRIC_ID = "requests/duration"; + private static final String PERFORMANCE_BUCKET = "request/performanceBucket"; + private static final String REQUEST_RESULT_CODE = "request/resultCode"; + private static final String REQUEST_SUCCESS = "request/success"; + + private final String performanceBucket; + private final Long statusCode; + private final boolean success; + + public RequestExtractor( + AbstractTelemetryBuilder telemetryBuilder, + String performanceBucket, + Long statusCode, + boolean success) { + super(telemetryBuilder); + this.performanceBucket = performanceBucket; + this.statusCode = statusCode; + this.success = success; + } + + @Override + public void extract() { + telemetryBuilder.addProperty(MS_METRIC_ID, REQUEST_METRIC_ID); + telemetryBuilder.addProperty(PERFORMANCE_BUCKET, performanceBucket); + telemetryBuilder.addProperty(OPERATION_SYNTHETIC, FALSE); + if (statusCode != null) { + telemetryBuilder.addProperty(REQUEST_RESULT_CODE, String.valueOf(statusCode)); + } + telemetryBuilder.addProperty(REQUEST_SUCCESS, success ? TRUE : FALSE); + } +} diff --git a/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java index 21eeacf1e88..d2f13dd5202 100644 --- a/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java +++ b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java @@ -21,15 +21,16 @@ package com.azure.monitor.opentelemetry.exporter; -import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.FALSE; -import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.MS_IS_AUTOCOLLECTED; -import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.MS_METRIC_ID; -import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.MS_PROCESSED_BY_METRIC_EXTRACTORS; -import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.OPERATION_SYNTHETIC; -import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.REQUEST_METRIC_ID; -import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.REQUEST_RESULT_CODE; -import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.REQUEST_SUCCESS; -import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestCustomDimensionsExtractor.TRUE; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.DependencyExtractor.DEPENDENCIES_DURATION; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.DependencyExtractor.DEPENDENCY_RESULT_CODE; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.DependencyExtractor.DEPENDENCY_SUCCESS; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.DependencyExtractor.DEPENDENCY_TYPE; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.BaseExtractor.FALSE; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.BaseExtractor.MS_IS_AUTOCOLLECTED; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.BaseExtractor.MS_METRIC_ID; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.BaseExtractor.MS_PROCESSED_BY_METRIC_EXTRACTORS; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.BaseExtractor.OPERATION_SYNTHETIC; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.BaseExtractor.TRUE; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; @@ -146,7 +147,7 @@ void generateHttpClientMetrics() { MetricsData metricsData = (MetricsData) telemetryItem.getData().getBaseData(); assertThat(metricsData.getProperties()) - .containsExactlyInAnyOrderEntriesOf(generateExpectedProperties()); + .containsExactlyInAnyOrderEntriesOf(generateExpectedProperties("http")); } @SuppressWarnings("SystemOut") @@ -219,22 +220,37 @@ void generateRpcClientMetrics() { exemplar .hasTraceId("ff01020304050600ff0a0b0c0d0e0f00") .hasSpanId("090a0b0c0d0e0f00"))))); + + MetricTelemetryBuilder builder = MetricTelemetryBuilder.create(); + MetricData metricData = metricDataCollection.iterator().next(); + MetricDataMapper.updateMetricPointBuilder( + builder, metricData, metricData.getData().getPoints().iterator().next(), true, true); + TelemetryItem telemetryItem = builder.build(); + MetricsData metricsData = (MetricsData) telemetryItem.getData().getBaseData(); + + assertThat(metricsData.getProperties()) + .containsExactlyInAnyOrderEntriesOf(generateExpectedProperties("grpc")); } private static long nanos(int millis) { return TimeUnit.MILLISECONDS.toNanos(millis); } - private static Map generateExpectedProperties() { + private static Map generateExpectedProperties(String type) { Map expectedMap = new HashMap<>(); - expectedMap.put(MS_METRIC_ID, REQUEST_METRIC_ID); + expectedMap.put(MS_METRIC_ID, DEPENDENCIES_DURATION); expectedMap.put(MS_IS_AUTOCOLLECTED, TRUE); expectedMap.put(MS_PROCESSED_BY_METRIC_EXTRACTORS, TRUE); // TODO performance market is updated in HttpClientMetrics // expectedMap.put(PERFORMANCE_BUCKET, "<250ms"); - expectedMap.put(REQUEST_RESULT_CODE, "200"); expectedMap.put(OPERATION_SYNTHETIC, FALSE); - expectedMap.put(REQUEST_SUCCESS, TRUE); + expectedMap.put(DEPENDENCY_SUCCESS, TRUE); + if ("http".equals(type)) { + expectedMap.put(DEPENDENCY_TYPE, "http"); + expectedMap.put(DEPENDENCY_RESULT_CODE, "200"); + } else { + expectedMap.put(DEPENDENCY_TYPE, "grpc"); + } // TODO test cloud_role_name and cloud_role_instance // expectedMap.put( // CLOUD_ROLE_NAME, From 354c24edfd9344b293df2cfd7e35bba59c977292 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Mon, 15 Aug 2022 15:25:41 -0700 Subject: [PATCH 35/95] Stdout http.server.duration metric --- .../implementation/MetricDataMapper.java | 2 +- .../RequestExtractor.java | 12 +- .../exporter/PreAggregatedMetricsTest.java | 119 ++++++++++++++++-- 3 files changed, 119 insertions(+), 14 deletions(-) diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index 8aba557e8c2..41d12c125b8 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -156,7 +156,7 @@ public static void updateMetricPointBuilder( metricTelemetryBuilder.setMetricPoint(pointBuilder); if (isPreAggregated) { - Long statusCode = pointData.getAttributes().get(AttributeKey.longKey("http.status_code")); + Long statusCode = pointData.getAttributes().get(SemanticAttributes.HTTP_STATUS_CODE); String performanceBucket = pointData.getAttributes().get(AttributeKey.stringKey("ai.performance.bucket")); boolean success = getSuccess(statusCode, captureHttpServer4xxAsError); diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java index f90325f053c..71c1f54198e 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java @@ -25,10 +25,10 @@ public final class RequestExtractor extends BaseExtractor { - private static final String REQUEST_METRIC_ID = "requests/duration"; - private static final String PERFORMANCE_BUCKET = "request/performanceBucket"; - private static final String REQUEST_RESULT_CODE = "request/resultCode"; - private static final String REQUEST_SUCCESS = "request/success"; + public static final String REQUESTS_DURATION = "requests/duration"; + public static final String REQUEST_PERFORMANCE_BUCKET = "request/performanceBucket"; + public static final String REQUEST_RESULT_CODE = "request/resultCode"; + public static final String REQUEST_SUCCESS = "request/success"; private final String performanceBucket; private final Long statusCode; @@ -47,8 +47,8 @@ public RequestExtractor( @Override public void extract() { - telemetryBuilder.addProperty(MS_METRIC_ID, REQUEST_METRIC_ID); - telemetryBuilder.addProperty(PERFORMANCE_BUCKET, performanceBucket); + telemetryBuilder.addProperty(MS_METRIC_ID, REQUESTS_DURATION); + telemetryBuilder.addProperty(REQUEST_PERFORMANCE_BUCKET, performanceBucket); telemetryBuilder.addProperty(OPERATION_SYNTHETIC, FALSE); if (statusCode != null) { telemetryBuilder.addProperty(REQUEST_RESULT_CODE, String.valueOf(statusCode)); diff --git a/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java index d2f13dd5202..dadff50bc11 100644 --- a/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java +++ b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java @@ -21,16 +21,19 @@ package com.azure.monitor.opentelemetry.exporter; -import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.DependencyExtractor.DEPENDENCIES_DURATION; -import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.DependencyExtractor.DEPENDENCY_RESULT_CODE; -import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.DependencyExtractor.DEPENDENCY_SUCCESS; -import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.DependencyExtractor.DEPENDENCY_TYPE; import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.BaseExtractor.FALSE; import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.BaseExtractor.MS_IS_AUTOCOLLECTED; import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.BaseExtractor.MS_METRIC_ID; import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.BaseExtractor.MS_PROCESSED_BY_METRIC_EXTRACTORS; import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.BaseExtractor.OPERATION_SYNTHETIC; import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.BaseExtractor.TRUE; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.DependencyExtractor.DEPENDENCIES_DURATION; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.DependencyExtractor.DEPENDENCY_RESULT_CODE; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.DependencyExtractor.DEPENDENCY_SUCCESS; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.DependencyExtractor.DEPENDENCY_TYPE; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestExtractor.REQUESTS_DURATION; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestExtractor.REQUEST_RESULT_CODE; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestExtractor.REQUEST_SUCCESS; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.assertThat; import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo; @@ -46,6 +49,7 @@ import io.opentelemetry.context.Context; import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; import io.opentelemetry.instrumentation.api.instrumenter.http.HttpClientMetrics; +import io.opentelemetry.instrumentation.api.instrumenter.http.HttpServerMetrics; import io.opentelemetry.instrumentation.api.instrumenter.rpc.RpcClientMetrics; import io.opentelemetry.sdk.metrics.SdkMeterProvider; import io.opentelemetry.sdk.metrics.data.MetricData; @@ -147,7 +151,7 @@ void generateHttpClientMetrics() { MetricsData metricsData = (MetricsData) telemetryItem.getData().getBaseData(); assertThat(metricsData.getProperties()) - .containsExactlyInAnyOrderEntriesOf(generateExpectedProperties("http")); + .containsExactlyInAnyOrderEntriesOf(generateExpectedDependencyCustomDimensions("http")); } @SuppressWarnings("SystemOut") @@ -229,14 +233,93 @@ void generateRpcClientMetrics() { MetricsData metricsData = (MetricsData) telemetryItem.getData().getBaseData(); assertThat(metricsData.getProperties()) - .containsExactlyInAnyOrderEntriesOf(generateExpectedProperties("grpc")); + .containsExactlyInAnyOrderEntriesOf(generateExpectedDependencyCustomDimensions("grpc")); + } + + @SuppressWarnings("SystemOut") + @Test + void generateHttpServerMetrics() { + OperationListener listener = HttpServerMetrics.get().create(meterProvider.get("test")); + + Attributes requestAttributes = + Attributes.builder() + .put("http.method", "GET") + .put("http.host", "host") + .put("http.target", "/") + .put("http.scheme", "https") + .put("net.host.name", "localhost") + .put("net.host.port", 1234) + .put("http.request_content_length", 100) + .build(); + + Attributes responseAttributes = + Attributes.builder() + .put("http.flavor", "2.0") + .put("http.server_name", "server") + .put("http.status_code", 200) + .put("http.response_content_length", 200) + .build(); + + SpanContext spanContext1 = + SpanContext.create( + "ff01020304050600ff0a0b0c0d0e0f00", + "090a0b0c0d0e0f00", + TraceFlags.getSampled(), + TraceState.getDefault()); + Context parent1 = Context.root().with(Span.wrap(spanContext1)); + Context context1 = listener.onStart(parent1, requestAttributes, nanos(100)); + listener.onEnd(context1, responseAttributes, nanos(250)); + + Collection metricDataCollection = metricReader.collectAllMetrics(); + MetricData target = null; + for (MetricData metricData : metricDataCollection) { + if ("http.server.duration".equals(metricData.getName())) { + target = metricData; + System.out.println("metric: " + metricData); + } + } + + assertThat(target) + .satisfies( + metric -> + assertThat(metric) + .hasName("http.server.duration") + .hasUnit("ms") + .hasHistogramSatisfying( + histogram -> + histogram.hasPointsSatisfying( + point -> + point + .hasSum(150 /* millis */) + .hasAttributesSatisfying( + equalTo(SemanticAttributes.HTTP_SCHEME, "https"), + equalTo(SemanticAttributes.HTTP_HOST, "host"), + equalTo(SemanticAttributes.HTTP_METHOD, "GET"), + equalTo(SemanticAttributes.HTTP_STATUS_CODE, 200), + equalTo(SemanticAttributes.HTTP_FLAVOR, "2.0")) + .hasExemplarsSatisfying( + exemplar -> + exemplar + .hasTraceId(spanContext1.getTraceId()) + .hasSpanId(spanContext1.getSpanId()))))); + + listener.onEnd(context1, responseAttributes, nanos(250)); + MetricTelemetryBuilder builder = MetricTelemetryBuilder.create(); + MetricData metricData = target; + MetricDataMapper.updateMetricPointBuilder( + builder, metricData, metricData.getData().getPoints().iterator().next(), true, true); + TelemetryItem telemetryItem = builder.build(); + MetricsData metricsData = (MetricsData) telemetryItem.getData().getBaseData(); + + assertThat(metricsData.getProperties()) + .containsExactlyInAnyOrderEntriesOf(generateExpectedRequestCustomDimensions("http")); } private static long nanos(int millis) { return TimeUnit.MILLISECONDS.toNanos(millis); } - private static Map generateExpectedProperties(String type) { + private static Map generateExpectedDependencyCustomDimensions(String type) { Map expectedMap = new HashMap<>(); expectedMap.put(MS_METRIC_ID, DEPENDENCIES_DURATION); expectedMap.put(MS_IS_AUTOCOLLECTED, TRUE); @@ -260,4 +343,26 @@ private static Map generateExpectedProperties(String type) { // telemetryItem.getTags().get(ContextTagKeys.AI_CLOUD_ROLE_INSTANCE.toString())); return expectedMap; } + + private static Map generateExpectedRequestCustomDimensions(String type) { + Map expectedMap = new HashMap<>(); + expectedMap.put(MS_METRIC_ID, REQUESTS_DURATION); + expectedMap.put(MS_IS_AUTOCOLLECTED, TRUE); + expectedMap.put(MS_PROCESSED_BY_METRIC_EXTRACTORS, TRUE); + // TODO performance market is updated in HttpClientMetrics + // expectedMap.put(PERFORMANCE_BUCKET, "<250ms"); + expectedMap.put(OPERATION_SYNTHETIC, FALSE); + expectedMap.put(REQUEST_SUCCESS, TRUE); + if ("http".equals(type)) { + expectedMap.put(REQUEST_RESULT_CODE, "200"); + } + // TODO test cloud_role_name and cloud_role_instance + // expectedMap.put( + // CLOUD_ROLE_NAME, + // telemetryItem.getTags().get(ContextTagKeys.AI_CLOUD_ROLE.toString())); + // expectedMap.put( + // CLOUD_ROLE_INSTANCE, + // telemetryItem.getTags().get(ContextTagKeys.AI_CLOUD_ROLE_INSTANCE.toString())); + return expectedMap; + } } From 73ac8838632597fe733182e1fc9cdac1725b1cc0 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Mon, 15 Aug 2022 15:34:47 -0700 Subject: [PATCH 36/95] Add target to httpClientMetrics' attributes --- .../instrumenter/http/HttpClientMetrics.java | 110 ++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java index c351a5e6e38..30070cdcc5e 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java @@ -115,6 +115,7 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { Attributes durationAttributes = durationAndSizeAttributes.toBuilder() .put(AI_PERFORMANCE_BUCKET, DurationBucketizer.getPerformanceBucket(duration)) + .put("target", getTargetForHttpClientSpan(durationAndSizeAttributes)) .build(); ; this.duration.record(duration, durationAttributes, context); @@ -135,6 +136,115 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { } } + private static String getTargetForHttpClientSpan(Attributes attributes) { + // from the spec, at least one of the following sets of attributes is required: + // * http.url + // * http.scheme, http.host, http.target + // * http.scheme, net.peer.name, net.peer.port, http.target + // * http.scheme, net.peer.ip, net.peer.port, http.target + String target = getTargetFromPeerService(attributes); + if (target != null) { + return target; + } + // note http.host includes the port (at least when non-default) + target = attributes.get(SemanticAttributes.HTTP_HOST); + if (target != null) { + String scheme = attributes.get(SemanticAttributes.HTTP_SCHEME); + if ("http".equals(scheme)) { + if (target.endsWith(":80")) { + target = target.substring(0, target.length() - 3); + } + } else if ("https".equals(scheme)) { + if (target.endsWith(":443")) { + target = target.substring(0, target.length() - 4); + } + } + return target; + } + String url = attributes.get(SemanticAttributes.HTTP_URL); + if (url != null) { + target = getTargetFromUrl(url); + if (target != null) { + return target; + } + } + String scheme = attributes.get(SemanticAttributes.HTTP_SCHEME); + int defaultPort; + if ("http".equals(scheme)) { + defaultPort = 80; + } else if ("https".equals(scheme)) { + defaultPort = 443; + } else { + defaultPort = 0; + } + target = getTargetFromNetAttributes(attributes, defaultPort); + if (target != null) { + return target; + } + // this should not happen, just a failsafe + return "Http"; + } + + @Nullable + private static String getTargetFromPeerService(Attributes attributes) { + // do not append port to peer.service + return attributes.get(SemanticAttributes.PEER_SERVICE); + } + + @Nullable + private static String getTargetFromNetAttributes(Attributes attributes, int defaultPort) { + String target = getHostFromNetAttributes(attributes); + if (target == null) { + return null; + } + // append net.peer.port to target + Long port = attributes.get(SemanticAttributes.NET_PEER_PORT); + if (port != null && port != defaultPort) { + return target + ":" + port; + } + return target; + } + + @Nullable + private static String getHostFromNetAttributes(Attributes attributes) { + String host = attributes.get(SemanticAttributes.NET_PEER_NAME); + if (host != null) { + return host; + } + return attributes.get(SemanticAttributes.NET_PEER_IP); + } + + @Nullable + private static String getTargetFromUrl(String url) { + int schemeEndIndex = url.indexOf(':'); + if (schemeEndIndex == -1) { + // not a valid url + return null; + } + + int len = url.length(); + if (schemeEndIndex + 2 < len + && url.charAt(schemeEndIndex + 1) == '/' + && url.charAt(schemeEndIndex + 2) == '/') { + // has authority component + // look for + // '/' - start of path + // '?' or end of string - empty path + int index; + for (index = schemeEndIndex + 3; index < len; index++) { + char c = url.charAt(index); + if (c == '/' || c == '?' || c == '#') { + break; + } + } + String target = url.substring(schemeEndIndex + 3, index); + return target.isEmpty() ? null : target; + } else { + // has no authority + return null; + } + } + @Nullable private static T getAttribute(AttributeKey key, Attributes... attributesList) { for (Attributes attributes : attributesList) { From 650f81c332527cc14aa6426896c76f421538f43a Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Tue, 16 Aug 2022 10:29:28 -0700 Subject: [PATCH 37/95] Add taret to rpcClientMetrics --- .../instrumenter/rpc/RpcClientMetrics.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java index fde769ca1c0..486d2c1cc47 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java @@ -34,8 +34,10 @@ import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; import io.opentelemetry.instrumentation.api.instrumenter.OperationMetrics; import io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer; +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; +import javax.annotation.Nullable; /** * {@link OperationListener} which keeps track of Date: Tue, 16 Aug 2022 10:40:53 -0700 Subject: [PATCH 38/95] Add target to rpcclientmetrics --- .../HttpPreaggregatedMetricsSmokeTest.java | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java index dbe37915eab..75aa0c44cd6 100644 --- a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java +++ b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java @@ -78,26 +78,26 @@ private static void verifyHttpClientPreAggregatedMetrics(List metrics) Comparator.comparing( obj -> { MetricData metricData = (MetricData) ((Data) obj.getData()).getBaseData(); - return metricData.getProperties().get("request/resultCode"); + return metricData.getProperties().get("dependency/resultCode"); })); // 1st pre-aggregated metric Envelope envelope1 = metrics.get(0); validateTags(envelope1); MetricData md1 = (MetricData) ((Data) envelope1.getData()).getBaseData(); - validateMetricData(md1, "200"); + validateMetricData("client", md1, "200"); // 2nd pre-aggregated metric Envelope envelope2 = metrics.get(1); validateTags(envelope2); MetricData md2 = (MetricData) ((Data) envelope2.getData()).getBaseData(); - validateMetricData(md2, "404"); + validateMetricData("client", md2, "404"); // 3rd pre-aggregated metric Envelope envelope3 = metrics.get(2); validateTags(envelope3); MetricData md3 = (MetricData) ((Data) envelope3.getData()).getBaseData(); - validateMetricData(md3, "500"); + validateMetricData("client", md3, "500"); } private static void verifyHttpServerPreAggregatedMetrics(List metrics) @@ -107,13 +107,13 @@ private static void verifyHttpServerPreAggregatedMetrics(List metrics) Envelope envelope1 = metrics.get(0); validateTags(envelope1); MetricData md1 = (MetricData) ((Data) envelope1.getData()).getBaseData(); - validateMetricData(md1, "200"); + validateMetricData("server", md1, "200"); // 2nd pre-aggregated metric Envelope envelope2 = metrics.get(1); validateTags(envelope2); MetricData md2 = (MetricData) ((Data) envelope2.getData()).getBaseData(); - validateMetricData(md2, "200"); + validateMetricData("server", md2, "200"); } private static void validateTags(Envelope envelope) { @@ -123,7 +123,7 @@ private static void validateTags(Envelope envelope) { assertThat(tags).containsEntry("ai.cloud.role", "testrolename"); } - private static void validateMetricData(MetricData metricData, String resultCode) { + private static void validateMetricData(String type, MetricData metricData, String resultCode) { List dataPoints = metricData.getMetrics(); assertThat(dataPoints).hasSize(1); DataPoint dataPoint = dataPoints.get(0); @@ -132,14 +132,18 @@ private static void validateMetricData(MetricData metricData, String resultCode) assertThat(dataPoint.getMin()).isGreaterThan(0d).isLessThan(5 * 60 * 1000d); // (0 - 5) min assertThat(dataPoint.getMin()).isGreaterThan(0d).isLessThan(5 * 60 * 1000d); // (0 - 5) min Map properties = metricData.getProperties(); - assertThat(properties.get("request/resultCode")).isEqualTo(resultCode); - double value = metricData.getMetrics().get(0).getValue(); - assertThat(properties.get("request/performanceBucket")).isEqualTo(getPerformanceBucket(value)); - if ("200".equals(resultCode)) { - assertThat(properties.get("request/success")).isEqualTo("True"); + String expectedResultCode = "200".equals(resultCode) ? "True" : "False"; + if ("client".equals(type)) { + assertThat(properties.get("dependency/resultCode")).isEqualTo(resultCode); + assertThat(properties.get("dependency/performanceBucket")) + .isEqualTo(getPerformanceBucket(value)); + assertThat(properties.get("dependency/success")).isEqualTo(expectedResultCode); } else { - assertThat(properties.get("request/success")).isEqualTo("False"); + assertThat(properties.get("request/resultCode")).isEqualTo(resultCode); + assertThat(properties.get("request/performanceBucket")) + .isEqualTo(getPerformanceBucket(value)); + assertThat(properties.get("request/success")).isEqualTo(expectedResultCode); } assertThat(properties.get("operation/synthetic")).isEqualTo("False"); assertThat(properties.get("_MS.metricId")).isEqualTo("requests/duration"); From 54faf3e1a148d7ef431989d14f4501dc50112c1a Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Tue, 16 Aug 2022 10:55:09 -0700 Subject: [PATCH 39/95] Fix smoke test --- .../exporter/implementation/MetricDataMapper.java | 2 ++ .../smoketest/HttpPreaggregatedMetricsSmokeTest.java | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index 41d12c125b8..15fe2d33472 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -170,6 +170,8 @@ public static void updateMetricPointBuilder( ? "http" : (String) pointData.getAttributes().get(SemanticAttributes.RPC_SYSTEM); String target = pointData.getAttributes().get(AttributeKey.stringKey("target")); + // TODO debug target - to be removed + logger.debug("############### target: " + target); DependencyExtractor dependencyExtractor = new DependencyExtractor( metricTelemetryBuilder, diff --git a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java index 75aa0c44cd6..3ec0164faf6 100644 --- a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java +++ b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java @@ -135,18 +135,21 @@ private static void validateMetricData(String type, MetricData metricData, Strin double value = metricData.getMetrics().get(0).getValue(); String expectedResultCode = "200".equals(resultCode) ? "True" : "False"; if ("client".equals(type)) { + assertThat(properties.get("_MS.metricId")).isEqualTo("dependencies/duration"); assertThat(properties.get("dependency/resultCode")).isEqualTo(resultCode); assertThat(properties.get("dependency/performanceBucket")) .isEqualTo(getPerformanceBucket(value)); assertThat(properties.get("dependency/success")).isEqualTo(expectedResultCode); + assertThat(properties.get("dependency/target")).isNotNull(); + assertThat(properties.get("dependency/type")).isNotNull(); } else { + assertThat(properties.get("_MS.metricId")).isEqualTo("requests/duration"); assertThat(properties.get("request/resultCode")).isEqualTo(resultCode); assertThat(properties.get("request/performanceBucket")) .isEqualTo(getPerformanceBucket(value)); assertThat(properties.get("request/success")).isEqualTo(expectedResultCode); } assertThat(properties.get("operation/synthetic")).isEqualTo("False"); - assertThat(properties.get("_MS.metricId")).isEqualTo("requests/duration"); assertThat(properties.get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(properties.get("cloud/roleInstance")).isEqualTo("testroleinstance"); assertThat(properties.get("cloud/roleName")).isEqualTo("testrolename"); From 1be480720fef1ea228c4b4f5c5ce27e163a08cf4 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Tue, 16 Aug 2022 11:29:02 -0700 Subject: [PATCH 40/95] Fix rpc smoke test --- .../api/instrumenter/rpc/MetricsView.java | 1 + .../implementation/MetricDataMapper.java | 4 +-- .../DependencyExtractor.java | 2 ++ .../smoketest/GrpcTest.java | 28 ++++++++++++------- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java index 618894a3cac..c6582666026 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java @@ -49,6 +49,7 @@ private static Set buildAlwaysInclude() { view.add(SemanticAttributes.RPC_SERVICE); view.add(SemanticAttributes.RPC_METHOD); view.add(AttributeKey.stringKey(DurationBucketizer.AI_PERFORMANCE_BUCKET)); + view.add(AttributeKey.stringKey("target")); return view; } diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index 15fe2d33472..722a4761c31 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -168,10 +168,8 @@ public static void updateMetricPointBuilder( String dependencyType = metricData.getName().startsWith("http") ? "http" - : (String) pointData.getAttributes().get(SemanticAttributes.RPC_SYSTEM); + : pointData.getAttributes().get(SemanticAttributes.RPC_SYSTEM); String target = pointData.getAttributes().get(AttributeKey.stringKey("target")); - // TODO debug target - to be removed - logger.debug("############### target: " + target); DependencyExtractor dependencyExtractor = new DependencyExtractor( metricTelemetryBuilder, diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java index f896515c62d..ec47d879bf1 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java @@ -39,6 +39,7 @@ public class DependencyExtractor extends BaseExtractor { private final String type; private final String target; + @SuppressWarnings("SystemOut") public DependencyExtractor( AbstractTelemetryBuilder telemetryBuilder, String performanceBucket, @@ -54,6 +55,7 @@ public DependencyExtractor( this.target = target; } + @SuppressWarnings("SystemOut") @Override public void extract() { telemetryBuilder.addProperty(MS_METRIC_ID, DEPENDENCIES_DURATION); diff --git a/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java b/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java index 52192245d08..c3cd775c32c 100644 --- a/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java +++ b/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java @@ -170,13 +170,13 @@ private static void verifyRpcClientDurationPreAggregatedMetrics(List m Envelope envelope1 = metrics.get(0); validateTags(envelope1); MetricData md1 = (MetricData) ((Data) envelope1.getData()).getBaseData(); - validateMetricData(md1); + validateMetricData("client", md1); // 2nd pre-aggregated metric Envelope envelope2 = metrics.get(1); validateTags(envelope2); MetricData md2 = (MetricData) ((Data) envelope2.getData()).getBaseData(); - validateMetricData(md2); + validateMetricData("client", md2); } private static void verifyRpcServerDurationPreAggregatedMetrics(List metrics) @@ -186,13 +186,13 @@ private static void verifyRpcServerDurationPreAggregatedMetrics(List m Envelope envelope1 = metrics.get(0); validateTags(envelope1); MetricData md1 = (MetricData) ((Data) envelope1.getData()).getBaseData(); - validateMetricData(md1); + validateMetricData("server", md1); // 2nd pre-aggregated metric Envelope envelope2 = metrics.get(1); validateTags(envelope2); MetricData md2 = (MetricData) ((Data) envelope2.getData()).getBaseData(); - validateMetricData(md2); + validateMetricData("server", md2); } private static void validateTags(Envelope envelope) { @@ -202,7 +202,7 @@ private static void validateTags(Envelope envelope) { assertThat(tags).containsEntry("ai.cloud.role", "testrolename"); } - private static void validateMetricData(MetricData metricData) { + private static void validateMetricData(String type, MetricData metricData) { List dataPoints = metricData.getMetrics(); assertThat(dataPoints).hasSize(1); DataPoint dataPoint = dataPoints.get(0); @@ -211,12 +211,20 @@ private static void validateMetricData(MetricData metricData) { assertThat(dataPoint.getMin()).isGreaterThan(0d).isLessThan(5 * 60 * 1000d); // (0 - 5) min assertThat(dataPoint.getMin()).isGreaterThan(0d).isLessThan(5 * 60 * 1000d); // (0 - 5) min Map properties = metricData.getProperties(); - assertThat(properties.get("request/resultCode")).isNull(); - double value = metricData.getMetrics().get(0).getValue(); - assertThat(properties.get("request/performanceBucket")).isEqualTo(getPerformanceBucket(value)); - assertThat(properties.get("request/success")).isEqualTo("True"); + String performanceBucket = getPerformanceBucket(metricData.getMetrics().get(0).getValue()); + if ("client".equals(type)) { + assertThat(properties.get("dependency/resultCode")).isNull(); + assertThat(properties.get("dependency/performanceBucket")).isEqualTo(performanceBucket); + assertThat(properties.get("_MS.metricId")).isEqualTo("dependencies/duration"); + assertThat(properties.get("dependency/target")).isNotNull(); + assertThat(properties.get("dependency/type")).isEqualTo("grpc"); + } else { + assertThat(properties.get("_MS.metricId")).isEqualTo("requests/duration"); + assertThat(properties.get("request/resultCode")).isNull(); + assertThat(properties.get("request/performanceBucket")).isEqualTo(performanceBucket); + assertThat(properties.get("request/success")).isEqualTo("True"); + } assertThat(properties.get("operation/synthetic")).isEqualTo("False"); - assertThat(properties.get("_MS.metricId")).isEqualTo("requests/duration"); assertThat(properties.get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(properties.get("cloud/roleInstance")).isEqualTo("testroleinstance"); assertThat(properties.get("cloud/roleName")).isEqualTo("testrolename"); From 5251d59ea163841f8389449b107cea39be8968ed Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Tue, 16 Aug 2022 11:30:27 -0700 Subject: [PATCH 41/95] Remove stdout suppressWarning --- .../preaggregatedmetrics/DependencyExtractor.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java index ec47d879bf1..f896515c62d 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java @@ -39,7 +39,6 @@ public class DependencyExtractor extends BaseExtractor { private final String type; private final String target; - @SuppressWarnings("SystemOut") public DependencyExtractor( AbstractTelemetryBuilder telemetryBuilder, String performanceBucket, @@ -55,7 +54,6 @@ public DependencyExtractor( this.target = target; } - @SuppressWarnings("SystemOut") @Override public void extract() { telemetryBuilder.addProperty(MS_METRIC_ID, DEPENDENCIES_DURATION); From ba69e1c3b81c8d8406c6fde6f104caf8c9b35682 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Wed, 17 Aug 2022 16:48:22 -0700 Subject: [PATCH 42/95] Debug 'ai.user.userAgent' --- .../opentelemetry/exporter/implementation/SpanDataMapper.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java index 0312a41a032..54fd88eec7e 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java @@ -59,6 +59,7 @@ import java.util.function.Consumer; import java.util.function.Supplier; import javax.annotation.Nullable; +import org.slf4j.LoggerFactory; // TODO (trask) move this class into internal package public final class SpanDataMapper { @@ -920,6 +921,8 @@ private static void setExtraAttributes( } if (stringKey.equals(SemanticAttributes.HTTP_USER_AGENT.getKey()) && value instanceof String) { + LoggerFactory.getLogger(SpanDataMapper.class) + .debug("##################### ai.user.userAgent: {}", value); telemetryBuilder.addTag("ai.user.userAgent", (String) value); return; } From 3e2bdb83a47651b873ad41b6e0e33f1024f4afe3 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 18 Aug 2022 13:06:27 -0700 Subject: [PATCH 43/95] Remove perf bucket and add isSynthetic --- .../DurationBucketizer.java => Utils.java} | 51 ++++++++-------- .../instrumenter/http/HttpClientMetrics.java | 15 +++-- .../instrumenter/http/HttpServerMetrics.java | 12 ++-- .../api/instrumenter/rpc/MetricsView.java | 8 ++- .../instrumenter/rpc/RpcClientMetrics.java | 9 +-- .../instrumenter/rpc/RpcServerMetrics.java | 11 ++-- .../implementation/MetricDataMapper.java | 18 +++--- .../implementation/SpanDataMapper.java | 3 - .../preaggregatedmetrics/BaseExtractor.java | 9 ++- .../DependencyExtractor.java | 10 +--- .../RequestExtractor.java | 11 +--- .../exporter/PreAggregatedMetricsTest.java | 2 - .../smoketest/DurationBucketizer.java | 59 ------------------- .../HttpPreaggregatedMetricsSmokeTest.java | 9 --- .../smoketest/DurationBucketizer.java | 59 ------------------- .../smoketest/GrpcTest.java | 13 +--- 16 files changed, 78 insertions(+), 221 deletions(-) rename agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/{utils/DurationBucketizer.java => Utils.java} (50%) delete mode 100644 smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/DurationBucketizer.java delete mode 100644 smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/DurationBucketizer.java diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/utils/DurationBucketizer.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/Utils.java similarity index 50% rename from agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/utils/DurationBucketizer.java rename to agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/Utils.java index 66af26bab70..0c1dba2430f 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/utils/DurationBucketizer.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/Utils.java @@ -19,40 +19,39 @@ * DEALINGS IN THE SOFTWARE. */ -package io.opentelemetry.instrumentation.api.instrumenter.utils; +package io.opentelemetry.instrumentation.api.instrumenter; -import java.util.LinkedHashMap; -import java.util.Map; +import io.opentelemetry.api.common.AttributeKey; +import io.opentelemetry.api.common.Attributes; +import javax.annotation.Nullable; -public final class DurationBucketizer { +public final class Utils { - public static final String AI_PERFORMANCE_BUCKET = "ai.performance.bucket"; + public static final String IS_SYNTHETIC = "isSynthetic"; + public static final String TARGET = "target"; - // sorted HashMap - private static final Map performanceBuckets = new LinkedHashMap<>(); - - static { - performanceBuckets.put("<250ms", 250d); - performanceBuckets.put("250ms-500ms", 500d); - performanceBuckets.put("500ms-1sec", 1000d); - performanceBuckets.put("1sec-3sec", 3000d); - performanceBuckets.put("3sec-7sec", 7000d); - performanceBuckets.put("7sec-15sec", 15000d); - performanceBuckets.put("15sec-30sec", 30000d); - performanceBuckets.put("30sec-1min", 60000d); - performanceBuckets.put("1min-2min", 120000d); - performanceBuckets.put("2min-5min", 300000d); - performanceBuckets.put(">=5min", Double.MAX_VALUE); + @SuppressWarnings("SystemOut") + public static boolean isUserAgentBot(Attributes endAttributes, Attributes startAttributes) { + String aiUserAgent = + getAttribute(AttributeKey.stringKey("ai.user.userAgent"), endAttributes, startAttributes); + // TODO to be removed debug log + System.out.println("############## HttpServerMetrics::aiUserAgent: " + aiUserAgent); + if (aiUserAgent != null && aiUserAgent.indexOf("AlwaysOn") >= 0) { + return true; + } + return false; } - public static String getPerformanceBucket(double durationInMillis) { - for (Map.Entry entry : performanceBuckets.entrySet()) { - if (durationInMillis < entry.getValue()) { - return entry.getKey(); + @Nullable + private static T getAttribute(AttributeKey key, Attributes... attributesList) { + for (Attributes attributes : attributesList) { + T value = attributes.get(key); + if (value != null) { + return value; } } - return ">=5min"; + return null; } - private DurationBucketizer() {} + private Utils() {} } diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java index 30070cdcc5e..697c87f03ec 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java @@ -21,8 +21,10 @@ package io.opentelemetry.instrumentation.api.instrumenter.http; +import static io.opentelemetry.instrumentation.api.instrumenter.Utils.IS_SYNTHETIC; +import static io.opentelemetry.instrumentation.api.instrumenter.Utils.TARGET; +import static io.opentelemetry.instrumentation.api.instrumenter.Utils.isUserAgentBot; import static io.opentelemetry.instrumentation.api.instrumenter.http.TemporaryMetricsView.applyClientDurationAndSizeView; -import static io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer.AI_PERFORMANCE_BUCKET; import static java.util.logging.Level.FINE; import com.google.auto.value.AutoValue; @@ -35,7 +37,6 @@ import io.opentelemetry.context.ContextKey; import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; import io.opentelemetry.instrumentation.api.instrumenter.OperationMetrics; -import io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; @@ -111,14 +112,16 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { Attributes durationAndSizeAttributes = applyClientDurationAndSizeView(state.startAttributes(), endAttributes); - double duration = (endNanos - state.startTimeNanos()) / NANOS_PER_MS; Attributes durationAttributes = durationAndSizeAttributes.toBuilder() - .put(AI_PERFORMANCE_BUCKET, DurationBucketizer.getPerformanceBucket(duration)) - .put("target", getTargetForHttpClientSpan(durationAndSizeAttributes)) + .put( + IS_SYNTHETIC, + String.valueOf(isUserAgentBot(endAttributes, state.startAttributes()))) + .put(TARGET, getTargetForHttpClientSpan(durationAndSizeAttributes)) .build(); ; - this.duration.record(duration, durationAttributes, context); + this.duration.record( + (endNanos - state.startTimeNanos()) / NANOS_PER_MS, durationAttributes, context); Long requestLength = getAttribute( diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java index e215d2de362..c365f6464ba 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java @@ -21,7 +21,8 @@ package io.opentelemetry.instrumentation.api.instrumenter.http; -import static io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer.AI_PERFORMANCE_BUCKET; +import static io.opentelemetry.instrumentation.api.instrumenter.Utils.IS_SYNTHETIC; +import static io.opentelemetry.instrumentation.api.instrumenter.Utils.isUserAgentBot; import static java.util.logging.Level.FINE; import com.google.auto.value.AutoValue; @@ -35,7 +36,6 @@ import io.opentelemetry.context.ContextKey; import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; import io.opentelemetry.instrumentation.api.instrumenter.OperationMetrics; -import io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; @@ -123,13 +123,15 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { Attributes durationAndSizeAttributes = TemporaryMetricsView.applyServerDurationAndSizeView(state.startAttributes(), endAttributes); - double duration = (endNanos - state.startTimeNanos()) / NANOS_PER_MS; Attributes durationAttributes = durationAndSizeAttributes.toBuilder() - .put(AI_PERFORMANCE_BUCKET, DurationBucketizer.getPerformanceBucket(duration)) + .put( + IS_SYNTHETIC, + String.valueOf(isUserAgentBot(endAttributes, state.startAttributes()))) .build(); ; - this.duration.record(duration, durationAttributes, context); + this.duration.record( + (endNanos - state.startTimeNanos()) / NANOS_PER_MS, durationAttributes, context); Long requestLength = getAttribute( diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java index c6582666026..ec48fa450ee 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java @@ -21,10 +21,12 @@ package io.opentelemetry.instrumentation.api.instrumenter.rpc; +import static io.opentelemetry.instrumentation.api.instrumenter.Utils.IS_SYNTHETIC; +import static io.opentelemetry.instrumentation.api.instrumenter.Utils.TARGET; + import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.common.AttributesBuilder; -import io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.HashSet; import java.util.Set; @@ -48,8 +50,8 @@ private static Set buildAlwaysInclude() { view.add(SemanticAttributes.RPC_SYSTEM); view.add(SemanticAttributes.RPC_SERVICE); view.add(SemanticAttributes.RPC_METHOD); - view.add(AttributeKey.stringKey(DurationBucketizer.AI_PERFORMANCE_BUCKET)); - view.add(AttributeKey.stringKey("target")); + view.add(AttributeKey.stringKey(TARGET)); + view.add(AttributeKey.stringKey(IS_SYNTHETIC)); return view; } diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java index 486d2c1cc47..b656b23808e 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java @@ -21,8 +21,10 @@ package io.opentelemetry.instrumentation.api.instrumenter.rpc; +import static io.opentelemetry.instrumentation.api.instrumenter.Utils.IS_SYNTHETIC; +import static io.opentelemetry.instrumentation.api.instrumenter.Utils.TARGET; +import static io.opentelemetry.instrumentation.api.instrumenter.Utils.isUserAgentBot; import static io.opentelemetry.instrumentation.api.instrumenter.rpc.MetricsView.applyClientView; -import static io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer.AI_PERFORMANCE_BUCKET; import static java.util.logging.Level.FINE; import com.google.auto.value.AutoValue; @@ -33,7 +35,6 @@ import io.opentelemetry.context.ContextKey; import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; import io.opentelemetry.instrumentation.api.instrumenter.OperationMetrics; -import io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; @@ -98,8 +99,8 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { } endAttributes = endAttributes.toBuilder() - .put(AI_PERFORMANCE_BUCKET, DurationBucketizer.getPerformanceBucket(duration)) - .put("target", target) + .put(IS_SYNTHETIC, isUserAgentBot(endAttributes, state.startAttributes())) + .put(TARGET, target) .build(); clientDurationHistogram.record( diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java index d0f58d93dfd..b1789e0b922 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java @@ -21,8 +21,9 @@ package io.opentelemetry.instrumentation.api.instrumenter.rpc; +import static io.opentelemetry.instrumentation.api.instrumenter.Utils.IS_SYNTHETIC; +import static io.opentelemetry.instrumentation.api.instrumenter.Utils.isUserAgentBot; import static io.opentelemetry.instrumentation.api.instrumenter.rpc.MetricsView.applyServerView; -import static io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer.AI_PERFORMANCE_BUCKET; import static java.util.logging.Level.FINE; import com.google.auto.value.AutoValue; @@ -33,7 +34,6 @@ import io.opentelemetry.context.ContextKey; import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; import io.opentelemetry.instrumentation.api.instrumenter.OperationMetrics; -import io.opentelemetry.instrumentation.api.instrumenter.utils.DurationBucketizer; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; @@ -89,14 +89,15 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { return; } - double duration = (endNanos - state.startTimeNanos()) / NANOS_PER_MS; endAttributes = endAttributes.toBuilder() - .put(AI_PERFORMANCE_BUCKET, DurationBucketizer.getPerformanceBucket(duration)) + .put(IS_SYNTHETIC, isUserAgentBot(endAttributes, state.startAttributes())) .build(); serverDurationHistogram.record( - duration, applyServerView(state.startAttributes(), endAttributes), context); + (endNanos - state.startTimeNanos()) / NANOS_PER_MS, + applyServerView(state.startAttributes(), endAttributes), + context); } @AutoValue diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index 722a4761c31..7af9bec6099 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -157,12 +157,16 @@ public static void updateMetricPointBuilder( if (isPreAggregated) { Long statusCode = pointData.getAttributes().get(SemanticAttributes.HTTP_STATUS_CODE); - String performanceBucket = - pointData.getAttributes().get(AttributeKey.stringKey("ai.performance.bucket")); boolean success = getSuccess(statusCode, captureHttpServer4xxAsError); + String isSyntheticString = + pointData.getAttributes().get(AttributeKey.stringKey("isSynthetic")); + boolean isSynthetic = false; + if (isSyntheticString != null) { + isSynthetic = Boolean.valueOf(isSyntheticString); + } if (metricData.getName().contains(".server.")) { RequestExtractor requestExtractor = - new RequestExtractor(metricTelemetryBuilder, performanceBucket, statusCode, success); + new RequestExtractor(metricTelemetryBuilder, statusCode, success, isSynthetic); requestExtractor.extract(); } else if (metricData.getName().contains(".client.")) { String dependencyType = @@ -170,14 +174,10 @@ public static void updateMetricPointBuilder( ? "http" : pointData.getAttributes().get(SemanticAttributes.RPC_SYSTEM); String target = pointData.getAttributes().get(AttributeKey.stringKey("target")); + DependencyExtractor dependencyExtractor = new DependencyExtractor( - metricTelemetryBuilder, - performanceBucket, - statusCode, - success, - dependencyType, - target); + metricTelemetryBuilder, statusCode, success, dependencyType, target, isSynthetic); dependencyExtractor.extract(); } } else { diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java index 54fd88eec7e..0312a41a032 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java @@ -59,7 +59,6 @@ import java.util.function.Consumer; import java.util.function.Supplier; import javax.annotation.Nullable; -import org.slf4j.LoggerFactory; // TODO (trask) move this class into internal package public final class SpanDataMapper { @@ -921,8 +920,6 @@ private static void setExtraAttributes( } if (stringKey.equals(SemanticAttributes.HTTP_USER_AGENT.getKey()) && value instanceof String) { - LoggerFactory.getLogger(SpanDataMapper.class) - .debug("##################### ai.user.userAgent: {}", value); telemetryBuilder.addTag("ai.user.userAgent", (String) value); return; } diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/BaseExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/BaseExtractor.java index df72f573215..2b37f900324 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/BaseExtractor.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/BaseExtractor.java @@ -38,12 +38,12 @@ public abstract class BaseExtractor { protected final AbstractTelemetryBuilder telemetryBuilder; - public BaseExtractor(AbstractTelemetryBuilder telemetryBuilder) { + public BaseExtractor(AbstractTelemetryBuilder telemetryBuilder, boolean isSynthetic) { this.telemetryBuilder = telemetryBuilder; - extractCommon(); + extractCommon(isSynthetic); } - private void extractCommon() { + private void extractCommon(boolean isSynthetic) { telemetryBuilder.addProperty(MS_IS_AUTOCOLLECTED, TRUE); // this flag will inform the ingestion service to stop post-aggregation telemetryBuilder.addProperty(MS_PROCESSED_BY_METRIC_EXTRACTORS, TRUE); @@ -62,8 +62,7 @@ private void extractCommon() { } } - // This is not supported yet. Default to false. - telemetryBuilder.addProperty(OPERATION_SYNTHETIC, FALSE); + telemetryBuilder.addProperty(OPERATION_SYNTHETIC, isSynthetic ? TRUE : FALSE); } public abstract void extract(); diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java index f896515c62d..6d863ce8676 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java @@ -28,12 +28,10 @@ public class DependencyExtractor extends BaseExtractor { // visible for testing public static final String DEPENDENCIES_DURATION = "dependencies/duration"; public static final String DEPENDENCY_TYPE = "dependency/type"; - public static final String DEPENDENCY_PERFORMANCE_BUCKET = "dependency/performanceBucket"; public static final String DEPENDENCY_SUCCESS = "dependency/success"; public static final String DEPENDENCY_TARGET = "dependency/target"; public static final String DEPENDENCY_RESULT_CODE = "dependency/resultCode"; - private final String performanceBucket; private final Long statusCode; private final boolean success; private final String type; @@ -41,13 +39,12 @@ public class DependencyExtractor extends BaseExtractor { public DependencyExtractor( AbstractTelemetryBuilder telemetryBuilder, - String performanceBucket, Long statusCode, boolean success, String type, - String target) { - super(telemetryBuilder); - this.performanceBucket = performanceBucket; + String target, + boolean isSynthetic) { + super(telemetryBuilder, isSynthetic); this.statusCode = statusCode; this.success = success; this.type = type; @@ -57,7 +54,6 @@ public DependencyExtractor( @Override public void extract() { telemetryBuilder.addProperty(MS_METRIC_ID, DEPENDENCIES_DURATION); - telemetryBuilder.addProperty(DEPENDENCY_PERFORMANCE_BUCKET, performanceBucket); // TODO OTEL will provide rpc.grpc.status_code & rpc.success, http.success if (statusCode != null) { telemetryBuilder.addProperty(DEPENDENCY_RESULT_CODE, String.valueOf(statusCode)); diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java index 71c1f54198e..8f35b927d50 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java @@ -26,21 +26,18 @@ public final class RequestExtractor extends BaseExtractor { public static final String REQUESTS_DURATION = "requests/duration"; - public static final String REQUEST_PERFORMANCE_BUCKET = "request/performanceBucket"; public static final String REQUEST_RESULT_CODE = "request/resultCode"; public static final String REQUEST_SUCCESS = "request/success"; - private final String performanceBucket; private final Long statusCode; private final boolean success; public RequestExtractor( AbstractTelemetryBuilder telemetryBuilder, - String performanceBucket, Long statusCode, - boolean success) { - super(telemetryBuilder); - this.performanceBucket = performanceBucket; + boolean success, + boolean isSynthetic) { + super(telemetryBuilder, isSynthetic); this.statusCode = statusCode; this.success = success; } @@ -48,8 +45,6 @@ public RequestExtractor( @Override public void extract() { telemetryBuilder.addProperty(MS_METRIC_ID, REQUESTS_DURATION); - telemetryBuilder.addProperty(REQUEST_PERFORMANCE_BUCKET, performanceBucket); - telemetryBuilder.addProperty(OPERATION_SYNTHETIC, FALSE); if (statusCode != null) { telemetryBuilder.addProperty(REQUEST_RESULT_CODE, String.valueOf(statusCode)); } diff --git a/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java index dadff50bc11..15eed33a45a 100644 --- a/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java +++ b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java @@ -349,8 +349,6 @@ private static Map generateExpectedRequestCustomDimensions(Strin expectedMap.put(MS_METRIC_ID, REQUESTS_DURATION); expectedMap.put(MS_IS_AUTOCOLLECTED, TRUE); expectedMap.put(MS_PROCESSED_BY_METRIC_EXTRACTORS, TRUE); - // TODO performance market is updated in HttpClientMetrics - // expectedMap.put(PERFORMANCE_BUCKET, "<250ms"); expectedMap.put(OPERATION_SYNTHETIC, FALSE); expectedMap.put(REQUEST_SUCCESS, TRUE); if ("http".equals(type)) { diff --git a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/DurationBucketizer.java b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/DurationBucketizer.java deleted file mode 100644 index 82dccddc57e..00000000000 --- a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/DurationBucketizer.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * ApplicationInsights-Java - * Copyright (c) Microsoft Corporation - * All rights reserved. - * - * MIT License - * Permission is hereby granted, free of charge, to any person obtaining a copy of this - * software and associated documentation files (the ""Software""), to deal in the Software - * without restriction, including without limitation the rights to use, copy, modify, merge, - * publish, distribute, sublicense, and/or sell copies of the Software, and to permit - * persons to whom the Software is furnished to do so, subject to the following conditions: - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE - * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -package com.microsoft.applicationinsights.smoketest; - -import java.util.LinkedHashMap; -import java.util.Map; - -// copied from link{com.microsoft.applicationinsights.agent.bootstrap.DurationBucketizer} -public final class DurationBucketizer { - - public static final String AI_PERFORMANCE_BUCKET = "ai.performance.bucket"; - - // sorted HashMap - private static final Map performanceBuckets = new LinkedHashMap<>(); - - static { - performanceBuckets.put("<250ms", 250d); - performanceBuckets.put("250ms-500ms", 500d); - performanceBuckets.put("500ms-1sec", 1000d); - performanceBuckets.put("1sec-3sec", 3000d); - performanceBuckets.put("3sec-7sec", 7000d); - performanceBuckets.put("7sec-15sec", 15000d); - performanceBuckets.put("15sec-30sec", 30000d); - performanceBuckets.put("30sec-1min", 60000d); - performanceBuckets.put("1min-2min", 120000d); - performanceBuckets.put("2min-5min", 300000d); - performanceBuckets.put(">=5min", Double.MAX_VALUE); - } - - public static String getPerformanceBucket(double durationInMillis) { - for (Map.Entry entry : performanceBuckets.entrySet()) { - if (durationInMillis < entry.getValue()) { - return entry.getKey(); - } - } - return ">=5min"; - } - - private DurationBucketizer() {} -} diff --git a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java index 3ec0164faf6..7c9b8ab534f 100644 --- a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java +++ b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java @@ -132,21 +132,16 @@ private static void validateMetricData(String type, MetricData metricData, Strin assertThat(dataPoint.getMin()).isGreaterThan(0d).isLessThan(5 * 60 * 1000d); // (0 - 5) min assertThat(dataPoint.getMin()).isGreaterThan(0d).isLessThan(5 * 60 * 1000d); // (0 - 5) min Map properties = metricData.getProperties(); - double value = metricData.getMetrics().get(0).getValue(); String expectedResultCode = "200".equals(resultCode) ? "True" : "False"; if ("client".equals(type)) { assertThat(properties.get("_MS.metricId")).isEqualTo("dependencies/duration"); assertThat(properties.get("dependency/resultCode")).isEqualTo(resultCode); - assertThat(properties.get("dependency/performanceBucket")) - .isEqualTo(getPerformanceBucket(value)); assertThat(properties.get("dependency/success")).isEqualTo(expectedResultCode); assertThat(properties.get("dependency/target")).isNotNull(); assertThat(properties.get("dependency/type")).isNotNull(); } else { assertThat(properties.get("_MS.metricId")).isEqualTo("requests/duration"); assertThat(properties.get("request/resultCode")).isEqualTo(resultCode); - assertThat(properties.get("request/performanceBucket")) - .isEqualTo(getPerformanceBucket(value)); assertThat(properties.get("request/success")).isEqualTo(expectedResultCode); } assertThat(properties.get("operation/synthetic")).isEqualTo("False"); @@ -156,10 +151,6 @@ private static void validateMetricData(String type, MetricData metricData, Strin assertThat(properties.get("_MS.IsAutocollected")).isEqualTo("True"); } - private static String getPerformanceBucket(double duration) { - return DurationBucketizer.getPerformanceBucket(duration); - } - @Environment(TOMCAT_8_JAVA_8) static class Tomcat8Java8Test extends HttpPreaggregatedMetricsSmokeTest {} diff --git a/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/DurationBucketizer.java b/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/DurationBucketizer.java deleted file mode 100644 index 82dccddc57e..00000000000 --- a/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/DurationBucketizer.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * ApplicationInsights-Java - * Copyright (c) Microsoft Corporation - * All rights reserved. - * - * MIT License - * Permission is hereby granted, free of charge, to any person obtaining a copy of this - * software and associated documentation files (the ""Software""), to deal in the Software - * without restriction, including without limitation the rights to use, copy, modify, merge, - * publish, distribute, sublicense, and/or sell copies of the Software, and to permit - * persons to whom the Software is furnished to do so, subject to the following conditions: - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE - * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -package com.microsoft.applicationinsights.smoketest; - -import java.util.LinkedHashMap; -import java.util.Map; - -// copied from link{com.microsoft.applicationinsights.agent.bootstrap.DurationBucketizer} -public final class DurationBucketizer { - - public static final String AI_PERFORMANCE_BUCKET = "ai.performance.bucket"; - - // sorted HashMap - private static final Map performanceBuckets = new LinkedHashMap<>(); - - static { - performanceBuckets.put("<250ms", 250d); - performanceBuckets.put("250ms-500ms", 500d); - performanceBuckets.put("500ms-1sec", 1000d); - performanceBuckets.put("1sec-3sec", 3000d); - performanceBuckets.put("3sec-7sec", 7000d); - performanceBuckets.put("7sec-15sec", 15000d); - performanceBuckets.put("15sec-30sec", 30000d); - performanceBuckets.put("30sec-1min", 60000d); - performanceBuckets.put("1min-2min", 120000d); - performanceBuckets.put("2min-5min", 300000d); - performanceBuckets.put(">=5min", Double.MAX_VALUE); - } - - public static String getPerformanceBucket(double durationInMillis) { - for (Map.Entry entry : performanceBuckets.entrySet()) { - if (durationInMillis < entry.getValue()) { - return entry.getKey(); - } - } - return ">=5min"; - } - - private DurationBucketizer() {} -} diff --git a/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java b/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java index c3cd775c32c..a44ae5b3331 100644 --- a/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java +++ b/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java @@ -162,8 +162,7 @@ private static Envelope getDependencyEnvelope(List envelopes, String n throw new IllegalStateException("Could not find dependency with name: " + name); } - private static void verifyRpcClientDurationPreAggregatedMetrics(List metrics) - throws Exception { + private static void verifyRpcClientDurationPreAggregatedMetrics(List metrics) { assertThat(metrics.size()).isEqualTo(2); // 1st pre-aggregated metric @@ -179,8 +178,7 @@ private static void verifyRpcClientDurationPreAggregatedMetrics(List m validateMetricData("client", md2); } - private static void verifyRpcServerDurationPreAggregatedMetrics(List metrics) - throws Exception { + private static void verifyRpcServerDurationPreAggregatedMetrics(List metrics) { assertThat(metrics.size()).isEqualTo(2); // 1st pre-aggregated metric Envelope envelope1 = metrics.get(0); @@ -211,17 +209,14 @@ private static void validateMetricData(String type, MetricData metricData) { assertThat(dataPoint.getMin()).isGreaterThan(0d).isLessThan(5 * 60 * 1000d); // (0 - 5) min assertThat(dataPoint.getMin()).isGreaterThan(0d).isLessThan(5 * 60 * 1000d); // (0 - 5) min Map properties = metricData.getProperties(); - String performanceBucket = getPerformanceBucket(metricData.getMetrics().get(0).getValue()); if ("client".equals(type)) { assertThat(properties.get("dependency/resultCode")).isNull(); - assertThat(properties.get("dependency/performanceBucket")).isEqualTo(performanceBucket); assertThat(properties.get("_MS.metricId")).isEqualTo("dependencies/duration"); assertThat(properties.get("dependency/target")).isNotNull(); assertThat(properties.get("dependency/type")).isEqualTo("grpc"); } else { assertThat(properties.get("_MS.metricId")).isEqualTo("requests/duration"); assertThat(properties.get("request/resultCode")).isNull(); - assertThat(properties.get("request/performanceBucket")).isEqualTo(performanceBucket); assertThat(properties.get("request/success")).isEqualTo("True"); } assertThat(properties.get("operation/synthetic")).isEqualTo("False"); @@ -231,10 +226,6 @@ private static void validateMetricData(String type, MetricData metricData) { assertThat(properties.get("_MS.IsAutocollected")).isEqualTo("True"); } - private static String getPerformanceBucket(double duration) { - return DurationBucketizer.getPerformanceBucket(duration); - } - @Environment(JAVA_8) static class Java8Test extends GrpcTest {} From c8d4f0c67609a9430ec351c21c3dafd5e54ebe9f Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 18 Aug 2022 13:27:41 -0700 Subject: [PATCH 44/95] Address comments --- .../api/instrumenter/http/HttpClientMetrics.java | 4 +++- .../api/instrumenter/http/HttpServerMetrics.java | 4 +++- .../api/instrumenter/rpc/RpcClientMetrics.java | 7 +++++-- .../api/instrumenter/rpc/RpcServerMetrics.java | 2 ++ .../exporter/implementation/MetricDataMapper.java | 3 +-- .../preaggregatedmetrics/BaseExtractor.java | 13 +++++++------ .../smokeTest/resources/applicationinsights.json | 10 ---------- .../apps/HttpPreaggregatedMetrics/build.gradle.kts | 2 -- 8 files changed, 21 insertions(+), 24 deletions(-) delete mode 100644 smoke-tests/apps/HttpClients/src/smokeTest/resources/applicationinsights.json diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java index 697c87f03ec..d2edfd1cb41 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java @@ -112,6 +112,7 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { Attributes durationAndSizeAttributes = applyClientDurationAndSizeView(state.startAttributes(), endAttributes); + // START APPLICATION INSIGHTS CODE Attributes durationAttributes = durationAndSizeAttributes.toBuilder() .put( @@ -119,7 +120,8 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { String.valueOf(isUserAgentBot(endAttributes, state.startAttributes()))) .put(TARGET, getTargetForHttpClientSpan(durationAndSizeAttributes)) .build(); - ; + // END APPLICATION INSIGHTS CODE + this.duration.record( (endNanos - state.startTimeNanos()) / NANOS_PER_MS, durationAttributes, context); diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java index c365f6464ba..c7c8b412476 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java @@ -123,13 +123,15 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { Attributes durationAndSizeAttributes = TemporaryMetricsView.applyServerDurationAndSizeView(state.startAttributes(), endAttributes); + // START APPLICATION INSIGHTS CODE Attributes durationAttributes = durationAndSizeAttributes.toBuilder() .put( IS_SYNTHETIC, String.valueOf(isUserAgentBot(endAttributes, state.startAttributes()))) .build(); - ; + // END APPLICATION INSIGHTS CODE + this.duration.record( (endNanos - state.startTimeNanos()) / NANOS_PER_MS, durationAttributes, context); diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java index b656b23808e..777cf7bed45 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java @@ -92,7 +92,7 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { return; } - double duration = (endNanos - state.startTimeNanos()) / NANOS_PER_MS; + // START APPLICATION INSIGHTS CODE String target = getTargetFromPeerAttributes(endAttributes, 0); if (target == null) { target = endAttributes.get(SemanticAttributes.RPC_SYSTEM); @@ -102,9 +102,12 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { .put(IS_SYNTHETIC, isUserAgentBot(endAttributes, state.startAttributes())) .put(TARGET, target) .build(); + // END APPLICATION INSIGHTS CODE clientDurationHistogram.record( - duration, applyClientView(state.startAttributes(), endAttributes), context); + (endNanos - state.startTimeNanos()) / NANOS_PER_MS, + applyClientView(state.startAttributes(), endAttributes), + context); } @Nullable diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java index b1789e0b922..150d99e5f03 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java @@ -89,10 +89,12 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { return; } + // START APPLICATION INSIGHTS CODE endAttributes = endAttributes.toBuilder() .put(IS_SYNTHETIC, isUserAgentBot(endAttributes, state.startAttributes())) .build(); + // END APPLICATION INSIGHTS CODE serverDurationHistogram.record( (endNanos - state.startTimeNanos()) / NANOS_PER_MS, diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index 7af9bec6099..2da33ce321a 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -192,7 +192,6 @@ private static boolean getSuccess(Long statusCode, boolean captureHttpServer4xxA if (captureHttpServer4xxAsError) { return statusCode == null || statusCode < 400; } - - return true; + return statusCode == null || statusCode < 500; } } diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/BaseExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/BaseExtractor.java index 2b37f900324..977673f8ab1 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/BaseExtractor.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/BaseExtractor.java @@ -22,7 +22,9 @@ package com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics; import com.azure.monitor.opentelemetry.exporter.implementation.builders.AbstractTelemetryBuilder; +import com.azure.monitor.opentelemetry.exporter.implementation.builders.MetricTelemetryBuilder; import com.azure.monitor.opentelemetry.exporter.implementation.models.ContextTagKeys; +import java.util.Map; public abstract class BaseExtractor { @@ -38,7 +40,7 @@ public abstract class BaseExtractor { protected final AbstractTelemetryBuilder telemetryBuilder; - public BaseExtractor(AbstractTelemetryBuilder telemetryBuilder, boolean isSynthetic) { + public BaseExtractor(MetricTelemetryBuilder telemetryBuilder, boolean isSynthetic) { this.telemetryBuilder = telemetryBuilder; extractCommon(isSynthetic); } @@ -48,15 +50,14 @@ private void extractCommon(boolean isSynthetic) { // this flag will inform the ingestion service to stop post-aggregation telemetryBuilder.addProperty(MS_PROCESSED_BY_METRIC_EXTRACTORS, TRUE); - if (telemetryBuilder.build().getTags() != null) { - String cloudName = - telemetryBuilder.build().getTags().get(ContextTagKeys.AI_CLOUD_ROLE.toString()); + Map tags = telemetryBuilder.build().getTags(); + if (tags != null) { + String cloudName = tags.get(ContextTagKeys.AI_CLOUD_ROLE.toString()); if (cloudName != null && !cloudName.isEmpty()) { telemetryBuilder.addProperty(CLOUD_ROLE_NAME, cloudName); } - String cloudRoleInstance = - telemetryBuilder.build().getTags().get(ContextTagKeys.AI_CLOUD_ROLE_INSTANCE.toString()); + String cloudRoleInstance = tags.get(ContextTagKeys.AI_CLOUD_ROLE_INSTANCE.toString()); if (cloudRoleInstance != null && !cloudRoleInstance.isEmpty()) { telemetryBuilder.addProperty(CLOUD_ROLE_INSTANCE, cloudRoleInstance); } diff --git a/smoke-tests/apps/HttpClients/src/smokeTest/resources/applicationinsights.json b/smoke-tests/apps/HttpClients/src/smokeTest/resources/applicationinsights.json deleted file mode 100644 index fabbaf6c881..00000000000 --- a/smoke-tests/apps/HttpClients/src/smokeTest/resources/applicationinsights.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "connectionString": "InstrumentationKey=00000000-0000-0000-0000-0FEEDDADBEEF;IngestionEndpoint=http://host.docker.internal:6060/", - "role": { - "name": "testrolename", - "instance": "testroleinstance" - }, - "preview": { - "metricIntervalSeconds": 10 - } -} \ No newline at end of file diff --git a/smoke-tests/apps/HttpPreaggregatedMetrics/build.gradle.kts b/smoke-tests/apps/HttpPreaggregatedMetrics/build.gradle.kts index a9e435f4eec..8d13585aaf1 100644 --- a/smoke-tests/apps/HttpPreaggregatedMetrics/build.gradle.kts +++ b/smoke-tests/apps/HttpPreaggregatedMetrics/build.gradle.kts @@ -4,6 +4,4 @@ plugins { dependencies { implementation("org.apache.httpcomponents:httpasyncclient:4.1.4") - // this dependency is needed to make wildfly happy - implementation("com.fasterxml.jackson.core:jackson-databind:2.9.4") } From a0270bf46b2f5c8b4a5016514af0d0089cdca712 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 18 Aug 2022 13:32:45 -0700 Subject: [PATCH 45/95] Fix compilation errors --- .../preaggregatedmetrics/DependencyExtractor.java | 3 ++- .../implementation/preaggregatedmetrics/RequestExtractor.java | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java index 6d863ce8676..131c3b6182e 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java @@ -22,6 +22,7 @@ package com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics; import com.azure.monitor.opentelemetry.exporter.implementation.builders.AbstractTelemetryBuilder; +import com.azure.monitor.opentelemetry.exporter.implementation.builders.MetricTelemetryBuilder; public class DependencyExtractor extends BaseExtractor { @@ -38,7 +39,7 @@ public class DependencyExtractor extends BaseExtractor { private final String target; public DependencyExtractor( - AbstractTelemetryBuilder telemetryBuilder, + MetricTelemetryBuilder telemetryBuilder, Long statusCode, boolean success, String type, diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java index 8f35b927d50..76bb1bc7517 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java @@ -22,6 +22,7 @@ package com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics; import com.azure.monitor.opentelemetry.exporter.implementation.builders.AbstractTelemetryBuilder; +import com.azure.monitor.opentelemetry.exporter.implementation.builders.MetricTelemetryBuilder; public final class RequestExtractor extends BaseExtractor { @@ -33,7 +34,7 @@ public final class RequestExtractor extends BaseExtractor { private final boolean success; public RequestExtractor( - AbstractTelemetryBuilder telemetryBuilder, + MetricTelemetryBuilder telemetryBuilder, Long statusCode, boolean success, boolean isSynthetic) { From 9185a538163cff21762dab0816eb3814cff503ec Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 18 Aug 2022 13:41:54 -0700 Subject: [PATCH 46/95] Remove unused imports --- .../implementation/preaggregatedmetrics/DependencyExtractor.java | 1 - .../implementation/preaggregatedmetrics/RequestExtractor.java | 1 - 2 files changed, 2 deletions(-) diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java index 131c3b6182e..d2f3b8f6619 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java @@ -21,7 +21,6 @@ package com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics; -import com.azure.monitor.opentelemetry.exporter.implementation.builders.AbstractTelemetryBuilder; import com.azure.monitor.opentelemetry.exporter.implementation.builders.MetricTelemetryBuilder; public class DependencyExtractor extends BaseExtractor { diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java index 76bb1bc7517..6457d90fcc3 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java @@ -21,7 +21,6 @@ package com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics; -import com.azure.monitor.opentelemetry.exporter.implementation.builders.AbstractTelemetryBuilder; import com.azure.monitor.opentelemetry.exporter.implementation.builders.MetricTelemetryBuilder; public final class RequestExtractor extends BaseExtractor { From 769a1e7a3f1b84e09b43cfd32069b97d3365a7a7 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 18 Aug 2022 15:44:56 -0700 Subject: [PATCH 47/95] Add MS_ProcessedByMetricExtractors to request/dependency not pre-agg metrics --- .../implementation/SpanDataMapper.java | 10 ++++ .../preaggregatedmetrics/BaseExtractor.java | 4 -- .../HttpPreaggregatedMetricsTestServlet.java | 8 --- .../HttpPreaggregatedMetricsSmokeTest.java | 55 +++++++++++++++++++ .../smoketest/GrpcTest.java | 1 - 5 files changed, 65 insertions(+), 13 deletions(-) diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java index 0312a41a032..7220a8a3c61 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java @@ -63,6 +63,9 @@ // TODO (trask) move this class into internal package public final class SpanDataMapper { + // visible for testing + public static final String MS_PROCESSED_BY_METRIC_EXTRACTORS = "_MS.ProcessedByMetricExtractors"; + private static final ClientLogger LOGGER = new ClientLogger(SpanDataMapper.class); private static final Set SQL_DB_SYSTEMS; @@ -379,6 +382,11 @@ private void applyHttpClientSpan( String url = attributes.get(SemanticAttributes.HTTP_URL); telemetryBuilder.setData(url); + + // TODO is it safe to assume that all http instrumentations support duration? + // http.client.request.size and http.client.response.size will not get post-aggregated + // http.server.request.size and http.server.response.size will not get post aggregated + telemetryBuilder.addProperty(MS_PROCESSED_BY_METRIC_EXTRACTORS, "True"); } @Nullable @@ -491,6 +499,8 @@ private static void applyRpcClientSpan( target = rpcSystem; } telemetryBuilder.setTarget(target); + // RPC client/server metrics only has duration + telemetryBuilder.addProperty(MS_PROCESSED_BY_METRIC_EXTRACTORS, "True"); } private static void applyDatabaseClientSpan( diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/BaseExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/BaseExtractor.java index 977673f8ab1..f8b22428c56 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/BaseExtractor.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/BaseExtractor.java @@ -31,7 +31,6 @@ public abstract class BaseExtractor { // visible for testing public static final String MS_METRIC_ID = "_MS.metricId"; public static final String MS_IS_AUTOCOLLECTED = "_MS.IsAutocollected"; - public static final String MS_PROCESSED_BY_METRIC_EXTRACTORS = "_MS.ProcessedByMetricExtractors"; public static final String TRUE = "True"; public static final String FALSE = "False"; public static final String OPERATION_SYNTHETIC = "operation/synthetic"; @@ -47,9 +46,6 @@ public BaseExtractor(MetricTelemetryBuilder telemetryBuilder, boolean isSyntheti private void extractCommon(boolean isSynthetic) { telemetryBuilder.addProperty(MS_IS_AUTOCOLLECTED, TRUE); - // this flag will inform the ingestion service to stop post-aggregation - telemetryBuilder.addProperty(MS_PROCESSED_BY_METRIC_EXTRACTORS, TRUE); - Map tags = telemetryBuilder.build().getTags(); if (tags != null) { String cloudName = tags.get(ContextTagKeys.AI_CLOUD_ROLE.toString()); diff --git a/smoke-tests/apps/HttpPreaggregatedMetrics/src/main/java/com/microsoft/applicationinsights/smoketestapp/HttpPreaggregatedMetricsTestServlet.java b/smoke-tests/apps/HttpPreaggregatedMetrics/src/main/java/com/microsoft/applicationinsights/smoketestapp/HttpPreaggregatedMetricsTestServlet.java index 49b5e192b98..580765485bd 100644 --- a/smoke-tests/apps/HttpPreaggregatedMetrics/src/main/java/com/microsoft/applicationinsights/smoketestapp/HttpPreaggregatedMetricsTestServlet.java +++ b/smoke-tests/apps/HttpPreaggregatedMetrics/src/main/java/com/microsoft/applicationinsights/smoketestapp/HttpPreaggregatedMetricsTestServlet.java @@ -30,18 +30,10 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.http.impl.nio.client.CloseableHttpAsyncClient; -import org.apache.http.impl.nio.client.HttpAsyncClients; @WebServlet("/*") public class HttpPreaggregatedMetricsTestServlet extends HttpServlet { - private final CloseableHttpAsyncClient httpAsyncClient = HttpAsyncClients.createDefault(); - - public HttpPreaggregatedMetricsTestServlet() { - httpAsyncClient.start(); - } - @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException { try { diff --git a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java index 7c9b8ab534f..3c0f0c57044 100644 --- a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java +++ b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java @@ -59,6 +59,8 @@ private static void verify() throws Exception { } private static void verify(String successUrlWithQueryString) throws Exception { + verifyHttpclientRequest(successUrlWithQueryString); + List clientMetrics = testing.mockedIngestion.waitForItems( SmokeTestExtension.getMetricPredicate("http.client.duration"), 3, 40, TimeUnit.SECONDS); @@ -70,6 +72,59 @@ private static void verify(String successUrlWithQueryString) throws Exception { verifyHttpServerPreAggregatedMetrics(serverMetrics); } + private static void verifyHttpclientRequest(String successUrlWithQueryString) throws Exception { + Telemetry telemetry = testing.getTelemetry(3); + + assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rdd1.getData()).isEqualTo(successUrlWithQueryString); + assertThat(telemetry.rd.getSuccess()).isTrue(); + assertThat(telemetry.rdEnvelope.getSampleRate()).isNull(); + assertThat(telemetry.rdd1.getName()).isEqualTo("GET /200"); + assertThat(telemetry.rdd1.getType()).isEqualTo("Http"); + assertThat(telemetry.rdd1.getTarget()).isEqualTo("mock.codes"); + assertThat(telemetry.rdd1.getResultCode()).isEqualTo("200"); + assertThat(telemetry.rdd1.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); + assertThat(telemetry.rdd1.getSuccess()).isTrue(); + assertThat(telemetry.rddEnvelope1.getSampleRate()).isNull(); + + assertThat(telemetry.rdd2.getName()).isEqualTo("GET /404"); + assertThat(telemetry.rdd2.getData()).isEqualTo("https://mock.codes/404"); + assertThat(telemetry.rdd2.getType()).isEqualTo("Http"); + assertThat(telemetry.rdd2.getTarget()).isEqualTo("mock.codes"); + assertThat(telemetry.rdd2.getResultCode()).isEqualTo("404"); + assertThat(telemetry.rdd1.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); + assertThat(telemetry.rdd2.getSuccess()).isFalse(); + assertThat(telemetry.rddEnvelope2.getSampleRate()).isNull(); + + assertThat(telemetry.rdd3.getName()).isEqualTo("GET /500"); + assertThat(telemetry.rdd3.getData()).isEqualTo("https://mock.codes/500"); + assertThat(telemetry.rdd3.getType()).isEqualTo("Http"); + assertThat(telemetry.rdd3.getTarget()).isEqualTo("mock.codes"); + assertThat(telemetry.rdd3.getResultCode()).isEqualTo("500"); + assertThat(telemetry.rdd1.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); + assertThat(telemetry.rdd3.getSuccess()).isFalse(); + assertThat(telemetry.rddEnvelope3.getSampleRate()).isNull(); + + SmokeTestExtension.assertParentChild( + telemetry.rd, + telemetry.rdEnvelope, + telemetry.rddEnvelope1, + "GET /HttpPreaggregatedMetrics/*"); + SmokeTestExtension.assertParentChild( + telemetry.rd, + telemetry.rdEnvelope, + telemetry.rddEnvelope2, + "GET /HttpPreaggregatedMetrics/*"); + SmokeTestExtension.assertParentChild( + telemetry.rd, + telemetry.rdEnvelope, + telemetry.rddEnvelope3, + "GET /HttpPreaggregatedMetrics/*"); + } + private static void verifyHttpClientPreAggregatedMetrics(List metrics) throws Exception { assertThat(metrics.size()).isEqualTo(3); diff --git a/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java b/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java index a44ae5b3331..45014a3546a 100644 --- a/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java +++ b/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java @@ -220,7 +220,6 @@ private static void validateMetricData(String type, MetricData metricData) { assertThat(properties.get("request/success")).isEqualTo("True"); } assertThat(properties.get("operation/synthetic")).isEqualTo("False"); - assertThat(properties.get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(properties.get("cloud/roleInstance")).isEqualTo("testroleinstance"); assertThat(properties.get("cloud/roleName")).isEqualTo("testrolename"); assertThat(properties.get("_MS.IsAutocollected")).isEqualTo("True"); From 346179ccf7add034ad091e2177fba78b8a49018e Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 18 Aug 2022 15:51:38 -0700 Subject: [PATCH 48/95] Remove an assert --- .../smoketest/HttpPreaggregatedMetricsSmokeTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java index 3c0f0c57044..227fa69da5c 100644 --- a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java +++ b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java @@ -200,7 +200,6 @@ private static void validateMetricData(String type, MetricData metricData, Strin assertThat(properties.get("request/success")).isEqualTo(expectedResultCode); } assertThat(properties.get("operation/synthetic")).isEqualTo("False"); - assertThat(properties.get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(properties.get("cloud/roleInstance")).isEqualTo("testroleinstance"); assertThat(properties.get("cloud/roleName")).isEqualTo("testrolename"); assertThat(properties.get("_MS.IsAutocollected")).isEqualTo("True"); From 9c223f6db916831a9eeb76d9292aeae28e6fc9ad Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 18 Aug 2022 15:53:02 -0700 Subject: [PATCH 49/95] Rename a method --- .../smoketest/HttpPreaggregatedMetricsSmokeTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java index 227fa69da5c..9a85c83cd81 100644 --- a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java +++ b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java @@ -59,7 +59,7 @@ private static void verify() throws Exception { } private static void verify(String successUrlWithQueryString) throws Exception { - verifyHttpclientRequest(successUrlWithQueryString); + verifyHttpclientRequestsAndDependencies(successUrlWithQueryString); List clientMetrics = testing.mockedIngestion.waitForItems( @@ -72,7 +72,7 @@ private static void verify(String successUrlWithQueryString) throws Exception { verifyHttpServerPreAggregatedMetrics(serverMetrics); } - private static void verifyHttpclientRequest(String successUrlWithQueryString) throws Exception { + private static void verifyHttpclientRequestsAndDependencies(String successUrlWithQueryString) throws Exception { Telemetry telemetry = testing.getTelemetry(3); assertThat(telemetry.rd.getProperties()).isEmpty(); From 4fcee8a35ddfe79578cfe19d5e20e69bbf79f326 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 18 Aug 2022 16:26:57 -0700 Subject: [PATCH 50/95] Fix tests --- .../exporter/implementation/SpanDataMapper.java | 12 ++++++++++++ .../exporter/PreAggregatedMetricsTest.java | 3 --- .../smoketest/HttpPreaggregatedMetricsSmokeTest.java | 3 ++- .../applicationinsights/smoketest/GrpcTest.java | 6 +++--- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java index 7220a8a3c61..6f78d75dbba 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java @@ -667,6 +667,8 @@ private TelemetryItem exportRequest(SpanData span, float samplingPercentage) { telemetryBuilder.addTag(ContextTagKeys.AI_DEVICE_OS_VERSION.toString(), deviceOsVersion); } + addFlagForPreAggMetrics(telemetryBuilder, span); + // TODO(trask)? for batch consumer, enqueuedTime should be the average of this attribute // across all links Long enqueuedTime = attributes.get(AZURE_SDK_ENQUEUED_TIME); @@ -684,6 +686,16 @@ private TelemetryItem exportRequest(SpanData span, float samplingPercentage) { return telemetryBuilder.build(); } + private static void addFlagForPreAggMetrics( + RequestTelemetryBuilder telemetryBuilder, SpanData span) { + Attributes attributes = span.getAttributes(); + String httpMethod = attributes.get(SemanticAttributes.HTTP_METHOD); + String rpcSystem = attributes.get(SemanticAttributes.RPC_SYSTEM); + if (httpMethod != null || rpcSystem != null) { + telemetryBuilder.addProperty(MS_PROCESSED_BY_METRIC_EXTRACTORS, "True"); + } + } + private boolean getSuccess(SpanData span) { switch (span.getStatus().getStatusCode()) { case ERROR: diff --git a/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java index 15eed33a45a..1d899f4d737 100644 --- a/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java +++ b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java @@ -24,7 +24,6 @@ import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.BaseExtractor.FALSE; import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.BaseExtractor.MS_IS_AUTOCOLLECTED; import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.BaseExtractor.MS_METRIC_ID; -import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.BaseExtractor.MS_PROCESSED_BY_METRIC_EXTRACTORS; import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.BaseExtractor.OPERATION_SYNTHETIC; import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.BaseExtractor.TRUE; import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.DependencyExtractor.DEPENDENCIES_DURATION; @@ -323,7 +322,6 @@ private static Map generateExpectedDependencyCustomDimensions(St Map expectedMap = new HashMap<>(); expectedMap.put(MS_METRIC_ID, DEPENDENCIES_DURATION); expectedMap.put(MS_IS_AUTOCOLLECTED, TRUE); - expectedMap.put(MS_PROCESSED_BY_METRIC_EXTRACTORS, TRUE); // TODO performance market is updated in HttpClientMetrics // expectedMap.put(PERFORMANCE_BUCKET, "<250ms"); expectedMap.put(OPERATION_SYNTHETIC, FALSE); @@ -348,7 +346,6 @@ private static Map generateExpectedRequestCustomDimensions(Strin Map expectedMap = new HashMap<>(); expectedMap.put(MS_METRIC_ID, REQUESTS_DURATION); expectedMap.put(MS_IS_AUTOCOLLECTED, TRUE); - expectedMap.put(MS_PROCESSED_BY_METRIC_EXTRACTORS, TRUE); expectedMap.put(OPERATION_SYNTHETIC, FALSE); expectedMap.put(REQUEST_SUCCESS, TRUE); if ("http".equals(type)) { diff --git a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java index 9a85c83cd81..dd8ca3d9d03 100644 --- a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java +++ b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java @@ -72,7 +72,8 @@ private static void verify(String successUrlWithQueryString) throws Exception { verifyHttpServerPreAggregatedMetrics(serverMetrics); } - private static void verifyHttpclientRequestsAndDependencies(String successUrlWithQueryString) throws Exception { + private static void verifyHttpclientRequestsAndDependencies(String successUrlWithQueryString) + throws Exception { Telemetry telemetry = testing.getTelemetry(3); assertThat(telemetry.rd.getProperties()).isEmpty(); diff --git a/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java b/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java index 45014a3546a..c8bebc1ea9c 100644 --- a/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java +++ b/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java @@ -81,7 +81,7 @@ void doSimpleTest() throws Exception { assertThat(rdd.getTarget()).isEqualTo("localhost:10203"); - assertThat(rd1.getProperties()).isEmpty(); + assertThat(rd1.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(rd1.getSuccess()).isTrue(); assertThat(rdd.getProperties()).isEmpty(); @@ -123,10 +123,10 @@ void doConversationTest() throws Exception { assertThat(rdd.getTarget()).isEqualTo("localhost:10203"); - assertThat(rd1.getProperties()).isEmpty(); + assertThat(rd1.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(rd1.getSuccess()).isTrue(); - assertThat(rdd.getProperties()).isEmpty(); + assertThat(rdd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(rdd.getSuccess()).isTrue(); // TODO (trask): verify rd2 From f6974b0b30e311a0b528f82e3e548efcc39c2883 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 18 Aug 2022 16:28:03 -0700 Subject: [PATCH 51/95] Fix test --- .../com/microsoft/applicationinsights/smoketest/GrpcTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java b/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java index c8bebc1ea9c..64494e7b16e 100644 --- a/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java +++ b/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java @@ -84,7 +84,7 @@ void doSimpleTest() throws Exception { assertThat(rd1.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(rd1.getSuccess()).isTrue(); - assertThat(rdd.getProperties()).isEmpty(); + assertThat(rdd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(rdd.getSuccess()).isTrue(); // TODO (trask): verify rd2 From 872d82167ae1798af3976bccf41e7ced4e8d0b7d Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 18 Aug 2022 16:58:36 -0700 Subject: [PATCH 52/95] Fix ci tests --- .../smoketest/HttpPreaggregatedMetricsSmokeTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java index dd8ca3d9d03..d97938b6467 100644 --- a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java +++ b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java @@ -76,7 +76,7 @@ private static void verifyHttpclientRequestsAndDependencies(String successUrlWit throws Exception { Telemetry telemetry = testing.getTelemetry(3); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(telemetry.rdd1.getData()).isEqualTo(successUrlWithQueryString); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rdEnvelope.getSampleRate()).isNull(); From 0e3a638515f58c17185b052ed8d0709e3d7db3ea Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 18 Aug 2022 17:10:39 -0700 Subject: [PATCH 53/95] Fix spotless --- .../smoketest/HttpPreaggregatedMetricsSmokeTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java index d97938b6467..d3c91f5586f 100644 --- a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java +++ b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java @@ -76,7 +76,8 @@ private static void verifyHttpclientRequestsAndDependencies(String successUrlWit throws Exception { Telemetry telemetry = testing.getTelemetry(3); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rdd1.getData()).isEqualTo(successUrlWithQueryString); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rdEnvelope.getSampleRate()).isNull(); From a6f2e995c24572463473012dafc457752828ba8f Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Fri, 19 Aug 2022 12:49:47 -0700 Subject: [PATCH 54/95] Reimplement the logic for adding _MS.ProcessedByMetricExtractors --- .../api/instrumenter/Utils.java | 1 + .../instrumenter/http/HttpClientMetrics.java | 7 ++++ .../instrumenter/http/HttpServerMetrics.java | 7 ++++ .../instrumenter/rpc/RpcClientMetrics.java | 7 ++++ .../instrumenter/rpc/RpcServerMetrics.java | 7 ++++ .../implementation/SpanDataMapper.java | 39 +++++++++---------- 6 files changed, 48 insertions(+), 20 deletions(-) diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/Utils.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/Utils.java index 0c1dba2430f..afcc5bc8179 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/Utils.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/Utils.java @@ -29,6 +29,7 @@ public final class Utils { public static final String IS_SYNTHETIC = "isSynthetic"; public static final String TARGET = "target"; + public static final String IS_PRE_AGGREGATED = "isPreAggregated"; @SuppressWarnings("SystemOut") public static boolean isUserAgentBot(Attributes endAttributes, Attributes startAttributes) { diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java index d2edfd1cb41..219b417febf 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java @@ -21,6 +21,7 @@ package io.opentelemetry.instrumentation.api.instrumenter.http; +import static io.opentelemetry.instrumentation.api.instrumenter.Utils.IS_PRE_AGGREGATED; import static io.opentelemetry.instrumentation.api.instrumenter.Utils.IS_SYNTHETIC; import static io.opentelemetry.instrumentation.api.instrumenter.Utils.TARGET; import static io.opentelemetry.instrumentation.api.instrumenter.Utils.isUserAgentBot; @@ -33,6 +34,7 @@ import io.opentelemetry.api.metrics.DoubleHistogram; import io.opentelemetry.api.metrics.LongHistogram; import io.opentelemetry.api.metrics.Meter; +import io.opentelemetry.api.trace.Span; import io.opentelemetry.context.Context; import io.opentelemetry.context.ContextKey; import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; @@ -113,6 +115,11 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { applyClientDurationAndSizeView(state.startAttributes(), endAttributes); // START APPLICATION INSIGHTS CODE + + // this is needed for detecting telemetry signals that will trigger pre-aggregated metrics via + // auto instrumentations + Span.fromContext(context).setAttribute(IS_PRE_AGGREGATED, "True"); + Attributes durationAttributes = durationAndSizeAttributes.toBuilder() .put( diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java index c7c8b412476..72b19e7aa1a 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java @@ -21,6 +21,7 @@ package io.opentelemetry.instrumentation.api.instrumenter.http; +import static io.opentelemetry.instrumentation.api.instrumenter.Utils.IS_PRE_AGGREGATED; import static io.opentelemetry.instrumentation.api.instrumenter.Utils.IS_SYNTHETIC; import static io.opentelemetry.instrumentation.api.instrumenter.Utils.isUserAgentBot; import static java.util.logging.Level.FINE; @@ -32,6 +33,7 @@ import io.opentelemetry.api.metrics.LongHistogram; import io.opentelemetry.api.metrics.LongUpDownCounter; import io.opentelemetry.api.metrics.Meter; +import io.opentelemetry.api.trace.Span; import io.opentelemetry.context.Context; import io.opentelemetry.context.ContextKey; import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; @@ -124,6 +126,11 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { TemporaryMetricsView.applyServerDurationAndSizeView(state.startAttributes(), endAttributes); // START APPLICATION INSIGHTS CODE + + // this is needed for detecting telemetry signals that will trigger pre-aggregated metrics via + // auto instrumentations + Span.fromContext(context).setAttribute(IS_PRE_AGGREGATED, "True"); + Attributes durationAttributes = durationAndSizeAttributes.toBuilder() .put( diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java index 777cf7bed45..f22b39e3426 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java @@ -21,6 +21,7 @@ package io.opentelemetry.instrumentation.api.instrumenter.rpc; +import static io.opentelemetry.instrumentation.api.instrumenter.Utils.IS_PRE_AGGREGATED; import static io.opentelemetry.instrumentation.api.instrumenter.Utils.IS_SYNTHETIC; import static io.opentelemetry.instrumentation.api.instrumenter.Utils.TARGET; import static io.opentelemetry.instrumentation.api.instrumenter.Utils.isUserAgentBot; @@ -31,6 +32,7 @@ import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.metrics.DoubleHistogram; import io.opentelemetry.api.metrics.Meter; +import io.opentelemetry.api.trace.Span; import io.opentelemetry.context.Context; import io.opentelemetry.context.ContextKey; import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; @@ -93,6 +95,11 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { } // START APPLICATION INSIGHTS CODE + + // this is needed for detecting telemetry signals that will trigger pre-aggregated metrics via + // auto instrumentations + Span.fromContext(context).setAttribute(IS_PRE_AGGREGATED, "True"); + String target = getTargetFromPeerAttributes(endAttributes, 0); if (target == null) { target = endAttributes.get(SemanticAttributes.RPC_SYSTEM); diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java index 150d99e5f03..03f7f4db0de 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java @@ -21,6 +21,7 @@ package io.opentelemetry.instrumentation.api.instrumenter.rpc; +import static io.opentelemetry.instrumentation.api.instrumenter.Utils.IS_PRE_AGGREGATED; import static io.opentelemetry.instrumentation.api.instrumenter.Utils.IS_SYNTHETIC; import static io.opentelemetry.instrumentation.api.instrumenter.Utils.isUserAgentBot; import static io.opentelemetry.instrumentation.api.instrumenter.rpc.MetricsView.applyServerView; @@ -30,6 +31,7 @@ import io.opentelemetry.api.common.Attributes; import io.opentelemetry.api.metrics.DoubleHistogram; import io.opentelemetry.api.metrics.Meter; +import io.opentelemetry.api.trace.Span; import io.opentelemetry.context.Context; import io.opentelemetry.context.ContextKey; import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; @@ -90,6 +92,11 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { } // START APPLICATION INSIGHTS CODE + + // this is needed for detecting telemetry signals that will trigger pre-aggregated metrics via + // auto instrumentations + Span.fromContext(context).setAttribute(IS_PRE_AGGREGATED, "True"); + endAttributes = endAttributes.toBuilder() .put(IS_SYNTHETIC, isUserAgentBot(endAttributes, state.startAttributes())) diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java index 6f78d75dbba..c21f85097b7 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java @@ -177,10 +177,12 @@ public void map(SpanData span, Consumer consumer) { } public TelemetryItem map(SpanData span, float samplingPercentage) { + boolean isPreAggregated = checkIsPreAggregated(span); if (isRequest(span)) { - return exportRequest(span, samplingPercentage); + return exportRequest(span, samplingPercentage, isPreAggregated); } else { - return exportRemoteDependency(span, span.getKind() == SpanKind.INTERNAL, samplingPercentage); + return exportRemoteDependency( + span, span.getKind() == SpanKind.INTERNAL, samplingPercentage, isPreAggregated); } } @@ -205,8 +207,13 @@ public static boolean isRequest(SpanData span) { } } + private static boolean checkIsPreAggregated(SpanData span) { + String isPreAggregated = span.getAttributes().get(AttributeKey.stringKey("isPreAggregated")); + return isPreAggregated != null && Boolean.valueOf(isPreAggregated); + } + private TelemetryItem exportRemoteDependency( - SpanData span, boolean inProc, float samplingPercentage) { + SpanData span, boolean inProc, float samplingPercentage, boolean isPreAggregated) { RemoteDependencyTelemetryBuilder telemetryBuilder = RemoteDependencyTelemetryBuilder.create(); telemetryInitializer.accept(telemetryBuilder, span.getResource()); @@ -233,6 +240,10 @@ private TelemetryItem exportRemoteDependency( applySemanticConventions(telemetryBuilder, span); } + if (isPreAggregated) { + telemetryBuilder.addProperty(MS_PROCESSED_BY_METRIC_EXTRACTORS, "True"); + } + return telemetryBuilder.build(); } @@ -382,11 +393,6 @@ private void applyHttpClientSpan( String url = attributes.get(SemanticAttributes.HTTP_URL); telemetryBuilder.setData(url); - - // TODO is it safe to assume that all http instrumentations support duration? - // http.client.request.size and http.client.response.size will not get post-aggregated - // http.server.request.size and http.server.response.size will not get post aggregated - telemetryBuilder.addProperty(MS_PROCESSED_BY_METRIC_EXTRACTORS, "True"); } @Nullable @@ -580,7 +586,8 @@ private static int getDefaultPortForDbSystem(String dbSystem) { } } - private TelemetryItem exportRequest(SpanData span, float samplingPercentage) { + private TelemetryItem exportRequest( + SpanData span, float samplingPercentage, boolean isPreAggregated) { RequestTelemetryBuilder telemetryBuilder = RequestTelemetryBuilder.create(); telemetryInitializer.accept(telemetryBuilder, span.getResource()); @@ -667,7 +674,9 @@ private TelemetryItem exportRequest(SpanData span, float samplingPercentage) { telemetryBuilder.addTag(ContextTagKeys.AI_DEVICE_OS_VERSION.toString(), deviceOsVersion); } - addFlagForPreAggMetrics(telemetryBuilder, span); + if (isPreAggregated) { + telemetryBuilder.addProperty(MS_PROCESSED_BY_METRIC_EXTRACTORS, "True"); + } // TODO(trask)? for batch consumer, enqueuedTime should be the average of this attribute // across all links @@ -686,16 +695,6 @@ private TelemetryItem exportRequest(SpanData span, float samplingPercentage) { return telemetryBuilder.build(); } - private static void addFlagForPreAggMetrics( - RequestTelemetryBuilder telemetryBuilder, SpanData span) { - Attributes attributes = span.getAttributes(); - String httpMethod = attributes.get(SemanticAttributes.HTTP_METHOD); - String rpcSystem = attributes.get(SemanticAttributes.RPC_SYSTEM); - if (httpMethod != null || rpcSystem != null) { - telemetryBuilder.addProperty(MS_PROCESSED_BY_METRIC_EXTRACTORS, "True"); - } - } - private boolean getSuccess(SpanData span) { switch (span.getStatus().getStatusCode()) { case ERROR: From 50d798458c5571fce3585b0eb13b5fefe7ba1159 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Mon, 22 Aug 2022 09:25:28 -0700 Subject: [PATCH 55/95] Remove isPreAggregated attribute --- .../opentelemetry/exporter/implementation/SpanDataMapper.java | 3 +++ .../microsoft/applicationinsights/smoketest/AzureSdkTest.java | 2 +- .../microsoft/applicationinsights/smoketest/CassandraTest.java | 2 +- .../applicationinsights/smoketest/SpringBootAutoTest.java | 3 ++- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java index c21f85097b7..d1750089678 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java @@ -952,6 +952,9 @@ private static void setExtraAttributes( && !stringKey.startsWith("http.response.header.")) { return; } + if (stringKey.equals("isPreAggregated")) { + return; + } String val = convertToString(value, key.getType()); if (value != null) { telemetryBuilder.addProperty(key.getKey(), val); diff --git a/smoke-tests/apps/AzureSdk/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/AzureSdkTest.java b/smoke-tests/apps/AzureSdk/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/AzureSdkTest.java index d9d2b6d6eec..ce02981d268 100644 --- a/smoke-tests/apps/AzureSdk/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/AzureSdkTest.java +++ b/smoke-tests/apps/AzureSdk/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/AzureSdkTest.java @@ -50,7 +50,7 @@ void test() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(telemetry.rd.getMeasurements()).isEmpty(); assertThat(telemetry.rdd1.getName()).isEqualTo("hello"); diff --git a/smoke-tests/apps/Cassandra/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CassandraTest.java b/smoke-tests/apps/Cassandra/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CassandraTest.java index 398140fde43..248856d606d 100644 --- a/smoke-tests/apps/Cassandra/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CassandraTest.java +++ b/smoke-tests/apps/Cassandra/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CassandraTest.java @@ -55,7 +55,7 @@ void cassandra() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(telemetry.rd.getMeasurements()).isEmpty(); assertThat(telemetry.rdd1.getName()).isEqualTo("SELECT test.test"); diff --git a/smoke-tests/apps/TelemetryProcessors/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java b/smoke-tests/apps/TelemetryProcessors/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java index b5dc4bc5c59..fb0e587f649 100644 --- a/smoke-tests/apps/TelemetryProcessors/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java +++ b/smoke-tests/apps/TelemetryProcessors/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java @@ -52,7 +52,8 @@ void doMostBasicTest() throws Exception { assertThat(telemetry.rd.getProperties()).containsEntry("sensitiveAttribute1", "sensitiveData1"); assertThat(telemetry.rd.getProperties().get("httpPath")) .isEqualTo("*/TelemetryProcessors/test*"); - assertThat(telemetry.rd.getProperties()).hasSize(4); + assertThat(telemetry.rd.getProperties()).hasSize(5); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(telemetry.rd.getSuccess()).isTrue(); // Log processor test List logs = testing.mockedIngestion.getMessageDataInRequest(); From 8c4ce320959b5c9255a5298e5b1c2c4b746f4293 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Mon, 22 Aug 2022 09:25:49 -0700 Subject: [PATCH 56/95] Fix spotless --- .../microsoft/applicationinsights/smoketest/AzureSdkTest.java | 3 ++- .../microsoft/applicationinsights/smoketest/CassandraTest.java | 3 ++- .../applicationinsights/smoketest/SpringBootAutoTest.java | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/smoke-tests/apps/AzureSdk/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/AzureSdkTest.java b/smoke-tests/apps/AzureSdk/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/AzureSdkTest.java index ce02981d268..e090d25359a 100644 --- a/smoke-tests/apps/AzureSdk/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/AzureSdkTest.java +++ b/smoke-tests/apps/AzureSdk/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/AzureSdkTest.java @@ -50,7 +50,8 @@ void test() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getMeasurements()).isEmpty(); assertThat(telemetry.rdd1.getName()).isEqualTo("hello"); diff --git a/smoke-tests/apps/Cassandra/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CassandraTest.java b/smoke-tests/apps/Cassandra/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CassandraTest.java index 248856d606d..9c42bd83a20 100644 --- a/smoke-tests/apps/Cassandra/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CassandraTest.java +++ b/smoke-tests/apps/Cassandra/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CassandraTest.java @@ -55,7 +55,8 @@ void cassandra() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getMeasurements()).isEmpty(); assertThat(telemetry.rdd1.getName()).isEqualTo("SELECT test.test"); diff --git a/smoke-tests/apps/TelemetryProcessors/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java b/smoke-tests/apps/TelemetryProcessors/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java index fb0e587f649..bce21d1f5f0 100644 --- a/smoke-tests/apps/TelemetryProcessors/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java +++ b/smoke-tests/apps/TelemetryProcessors/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java @@ -53,7 +53,8 @@ void doMostBasicTest() throws Exception { assertThat(telemetry.rd.getProperties().get("httpPath")) .isEqualTo("*/TelemetryProcessors/test*"); assertThat(telemetry.rd.getProperties()).hasSize(5); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getSuccess()).isTrue(); // Log processor test List logs = testing.mockedIngestion.getMessageDataInRequest(); From 278b5260eb801bbf90edb4e79c8ff803fc0e14bf Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Mon, 22 Aug 2022 09:46:00 -0700 Subject: [PATCH 57/95] Address comments --- .../api/instrumenter/{Utils.java => UserAgents.java} | 4 ++-- .../api/instrumenter/http/HttpClientMetrics.java | 8 ++++---- .../api/instrumenter/http/HttpServerMetrics.java | 6 +++--- .../instrumentation/api/instrumenter/rpc/MetricsView.java | 4 ++-- .../api/instrumenter/rpc/RpcClientMetrics.java | 8 ++++---- .../api/instrumenter/rpc/RpcServerMetrics.java | 6 +++--- .../exporter/implementation/MetricDataMapper.java | 4 +++- .../exporter/implementation/SpanDataMapper.java | 3 +-- 8 files changed, 22 insertions(+), 21 deletions(-) rename agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/{Utils.java => UserAgents.java} (97%) diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/Utils.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/UserAgents.java similarity index 97% rename from agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/Utils.java rename to agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/UserAgents.java index afcc5bc8179..5403adcd6f4 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/Utils.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/UserAgents.java @@ -25,7 +25,7 @@ import io.opentelemetry.api.common.Attributes; import javax.annotation.Nullable; -public final class Utils { +public final class UserAgents { public static final String IS_SYNTHETIC = "isSynthetic"; public static final String TARGET = "target"; @@ -54,5 +54,5 @@ private static T getAttribute(AttributeKey key, Attributes... attributesL return null; } - private Utils() {} + private UserAgents() {} } diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java index 219b417febf..baa29cfcf80 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java @@ -21,10 +21,10 @@ package io.opentelemetry.instrumentation.api.instrumenter.http; -import static io.opentelemetry.instrumentation.api.instrumenter.Utils.IS_PRE_AGGREGATED; -import static io.opentelemetry.instrumentation.api.instrumenter.Utils.IS_SYNTHETIC; -import static io.opentelemetry.instrumentation.api.instrumenter.Utils.TARGET; -import static io.opentelemetry.instrumentation.api.instrumenter.Utils.isUserAgentBot; +import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.IS_PRE_AGGREGATED; +import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.IS_SYNTHETIC; +import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.TARGET; +import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.isUserAgentBot; import static io.opentelemetry.instrumentation.api.instrumenter.http.TemporaryMetricsView.applyClientDurationAndSizeView; import static java.util.logging.Level.FINE; diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java index 72b19e7aa1a..11f1d39fd44 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java @@ -21,9 +21,9 @@ package io.opentelemetry.instrumentation.api.instrumenter.http; -import static io.opentelemetry.instrumentation.api.instrumenter.Utils.IS_PRE_AGGREGATED; -import static io.opentelemetry.instrumentation.api.instrumenter.Utils.IS_SYNTHETIC; -import static io.opentelemetry.instrumentation.api.instrumenter.Utils.isUserAgentBot; +import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.IS_PRE_AGGREGATED; +import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.IS_SYNTHETIC; +import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.isUserAgentBot; import static java.util.logging.Level.FINE; import com.google.auto.value.AutoValue; diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java index ec48fa450ee..a06dd8c74b2 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java @@ -21,8 +21,8 @@ package io.opentelemetry.instrumentation.api.instrumenter.rpc; -import static io.opentelemetry.instrumentation.api.instrumenter.Utils.IS_SYNTHETIC; -import static io.opentelemetry.instrumentation.api.instrumenter.Utils.TARGET; +import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.IS_SYNTHETIC; +import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.TARGET; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java index f22b39e3426..4810b9962dd 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java @@ -21,10 +21,10 @@ package io.opentelemetry.instrumentation.api.instrumenter.rpc; -import static io.opentelemetry.instrumentation.api.instrumenter.Utils.IS_PRE_AGGREGATED; -import static io.opentelemetry.instrumentation.api.instrumenter.Utils.IS_SYNTHETIC; -import static io.opentelemetry.instrumentation.api.instrumenter.Utils.TARGET; -import static io.opentelemetry.instrumentation.api.instrumenter.Utils.isUserAgentBot; +import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.IS_PRE_AGGREGATED; +import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.IS_SYNTHETIC; +import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.TARGET; +import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.isUserAgentBot; import static io.opentelemetry.instrumentation.api.instrumenter.rpc.MetricsView.applyClientView; import static java.util.logging.Level.FINE; diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java index 03f7f4db0de..971ad4102e7 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java @@ -21,9 +21,9 @@ package io.opentelemetry.instrumentation.api.instrumenter.rpc; -import static io.opentelemetry.instrumentation.api.instrumenter.Utils.IS_PRE_AGGREGATED; -import static io.opentelemetry.instrumentation.api.instrumenter.Utils.IS_SYNTHETIC; -import static io.opentelemetry.instrumentation.api.instrumenter.Utils.isUserAgentBot; +import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.IS_PRE_AGGREGATED; +import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.IS_SYNTHETIC; +import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.isUserAgentBot; import static io.opentelemetry.instrumentation.api.instrumenter.rpc.MetricsView.applyServerView; import static java.util.logging.Level.FINE; diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index 2da33ce321a..1f75a79d493 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -44,7 +44,9 @@ import io.opentelemetry.sdk.metrics.data.PointData; import io.opentelemetry.sdk.resources.Resource; import java.util.ArrayList; +import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.function.BiConsumer; import java.util.function.Consumer; import org.slf4j.Logger; @@ -52,7 +54,7 @@ public class MetricDataMapper { - private static final List OTEL_PRE_AGGREGATED_METRIC_NAMES = new ArrayList<>(); + private static final Set OTEL_PRE_AGGREGATED_METRIC_NAMES = new HashSet<>(4); private static final List EXCLUDED_METRIC_NAMES = new ArrayList<>(); private static final Logger logger = LoggerFactory.getLogger(MetricDataMapper.class); diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java index dd48b0082a0..04ac5235251 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java @@ -604,8 +604,7 @@ private static int getDefaultPortForDbSystem(String dbSystem) { } } - private TelemetryItem exportRequest( - SpanData span, long itemCount, boolean isPreAggregated) { + private TelemetryItem exportRequest(SpanData span, long itemCount, boolean isPreAggregated) { RequestTelemetryBuilder telemetryBuilder = RequestTelemetryBuilder.create(); telemetryInitializer.accept(telemetryBuilder, span.getResource()); From b84e94b7566f4b8aa96c495bc36861286ec38780 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Mon, 22 Aug 2022 10:54:49 -0700 Subject: [PATCH 58/95] Fix smoke tests --- .../smoketest/AzureSdkControllerSpansEnabledTest.java | 3 ++- .../applicationinsights/smoketest/CoreAndFilterTests.java | 2 +- .../applicationinsights/smoketest/CustomDimensionsTest.java | 2 +- .../smoketest/CustomInstrumentationTest.java | 2 +- .../applicationinsights/smoketest/HttpClientSmokeTest.java | 3 ++- .../applicationinsights/smoketest/HttpHeadersTest.java | 2 +- .../smoketest/HttpServer4xxDefaultTest.java | 3 ++- .../applicationinsights/smoketest/SpringBootAutoTest.java | 2 +- .../com/microsoft/applicationinsights/smoketest/JmsTest.java | 2 +- .../com/microsoft/applicationinsights/smoketest/JdbcTest.java | 3 ++- .../com/microsoft/applicationinsights/smoketest/JedisTest.java | 3 ++- .../applicationinsights/smoketest/JettyNativeHandlerTest.java | 3 ++- .../com/microsoft/applicationinsights/smoketest/KafkaTest.java | 2 +- .../microsoft/applicationinsights/smoketest/LettuceTest.java | 3 ++- .../applicationinsights/smoketest/MicrometerTest.java | 3 ++- .../com/microsoft/applicationinsights/smoketest/MongoTest.java | 3 ++- .../applicationinsights/smoketest/NonDaemonThreadsTest.java | 2 +- .../smoketest/OpenTelemetryApiSupportTest.java | 3 ++- .../smoketest/SpringBootAttachInMainTest.java | 3 ++- .../applicationinsights/smoketest/SpringBootAutoTest.java | 3 ++- .../applicationinsights/smoketest/SpringBootTest.java | 2 +- .../applicationinsights/smoketest/SpringCloudStreamTest.java | 2 +- .../applicationinsights/smoketest/SpringBootAutoTest.java | 2 +- .../microsoft/applicationinsights/smoketest/WebFluxTest.java | 3 ++- 24 files changed, 37 insertions(+), 24 deletions(-) diff --git a/smoke-tests/apps/AzureSdk/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/AzureSdkControllerSpansEnabledTest.java b/smoke-tests/apps/AzureSdk/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/AzureSdkControllerSpansEnabledTest.java index 5524143ef07..84ad4044758 100644 --- a/smoke-tests/apps/AzureSdk/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/AzureSdkControllerSpansEnabledTest.java +++ b/smoke-tests/apps/AzureSdk/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/AzureSdkControllerSpansEnabledTest.java @@ -55,7 +55,8 @@ void test() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getMeasurements()).isEmpty(); assertThat(telemetry.rdd1.getName()).isEqualTo("TestController.test"); diff --git a/smoke-tests/apps/CoreAndFilter3x/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CoreAndFilterTests.java b/smoke-tests/apps/CoreAndFilter3x/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CoreAndFilterTests.java index 891240ee2fc..47156538751 100644 --- a/smoke-tests/apps/CoreAndFilter3x/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CoreAndFilterTests.java +++ b/smoke-tests/apps/CoreAndFilter3x/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CoreAndFilterTests.java @@ -183,7 +183,7 @@ void testHttpRequest() throws Exception { testing.mockedIngestion.waitForItems("RequestData", 5); int totalItems = testing.mockedIngestion.getItemCount(); - assertThat(totalItems).isEqualTo(5); + assertThat(totalItems).isEqualTo(6); // TODO get HttpRequest data envelope and verify value List requests = testing.mockedIngestion.getTelemetryDataByType("RequestData"); diff --git a/smoke-tests/apps/CustomDimensions/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CustomDimensionsTest.java b/smoke-tests/apps/CustomDimensions/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CustomDimensionsTest.java index 86200fcb940..352b72c1827 100644 --- a/smoke-tests/apps/CustomDimensions/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CustomDimensionsTest.java +++ b/smoke-tests/apps/CustomDimensions/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CustomDimensionsTest.java @@ -47,7 +47,7 @@ void doMostBasicTest() throws Exception { assertThat(telemetry.rd.getProperties()).containsEntry("test", "value"); assertThat(telemetry.rd.getProperties()).containsKey("home"); - assertThat(telemetry.rd.getProperties()).hasSize(2); + assertThat(telemetry.rd.getProperties()).hasSize(3); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rdEnvelope.getTags()).containsEntry("ai.application.ver", "123"); diff --git a/smoke-tests/apps/CustomInstrumentation/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CustomInstrumentationTest.java b/smoke-tests/apps/CustomInstrumentation/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CustomInstrumentationTest.java index 8651f21422b..e13e30b03dd 100644 --- a/smoke-tests/apps/CustomInstrumentation/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CustomInstrumentationTest.java +++ b/smoke-tests/apps/CustomInstrumentation/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CustomInstrumentationTest.java @@ -69,7 +69,7 @@ void test() throws Exception { assertThat(rd1.getName()).isEqualTo("GET /test"); assertThat(rd1.getResponseCode()).isEqualTo("200"); - assertThat(rd1.getProperties()).isEmpty(); + assertThat(rd1.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(rd1.getSuccess()).isTrue(); assertThat(rd2.getName()).isEqualTo("TestController.run"); diff --git a/smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpClientSmokeTest.java b/smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpClientSmokeTest.java index 779be3cfb6b..1b5f5a0d183 100644 --- a/smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpClientSmokeTest.java +++ b/smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpClientSmokeTest.java @@ -96,7 +96,8 @@ private static void verify() throws Exception { private static void verify(String successUrlWithQueryString) throws Exception { Telemetry telemetry = testing.getTelemetry(3); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getSuccess()).isTrue(); // TODO (trask) add this check in all smoke tests? assertThat(telemetry.rdEnvelope.getSampleRate()).isNull(); diff --git a/smoke-tests/apps/HttpHeaders/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpHeadersTest.java b/smoke-tests/apps/HttpHeaders/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpHeadersTest.java index e5fa502971a..1b3aca1fb47 100644 --- a/smoke-tests/apps/HttpHeaders/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpHeadersTest.java +++ b/smoke-tests/apps/HttpHeaders/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpHeadersTest.java @@ -48,7 +48,7 @@ void testServerHeaders() throws Exception { assertThat(telemetry.rd.getProperties().get("http.response.header.abc")) .isEqualTo("testing123"); assertThat(telemetry.rd.getProperties()).containsKey("http.request.header.host"); - assertThat(telemetry.rd.getProperties()).hasSize(2); + assertThat(telemetry.rd.getProperties()).hasSize(3); assertThat(telemetry.rd.getSuccess()).isTrue(); } diff --git a/smoke-tests/apps/HttpServer4xx/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpServer4xxDefaultTest.java b/smoke-tests/apps/HttpServer4xx/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpServer4xxDefaultTest.java index dd5fc4049cc..0f84abcaf9c 100644 --- a/smoke-tests/apps/HttpServer4xx/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpServer4xxDefaultTest.java +++ b/smoke-tests/apps/HttpServer4xx/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpServer4xxDefaultTest.java @@ -50,7 +50,8 @@ void doMostBasicTest() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("400"); assertThat(telemetry.rd.getSuccess()).isFalse(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getMeasurements()).isEmpty(); } diff --git a/smoke-tests/apps/InheritedAttributes/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java b/smoke-tests/apps/InheritedAttributes/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java index ca7e5b07a9a..06fe3c325d7 100644 --- a/smoke-tests/apps/InheritedAttributes/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java +++ b/smoke-tests/apps/InheritedAttributes/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java @@ -66,7 +66,7 @@ void test() throws Exception { assertThat(rd.getName()).isEqualTo("GET /test"); assertThat(rd.getResponseCode()).isEqualTo("200"); assertThat(rd.getProperties()).containsEntry("tenant", "z"); - assertThat(rd.getProperties()).hasSize(1); + assertThat(rd.getProperties()).hasSize(2); assertThat(rd.getSuccess()).isTrue(); assertThat(md.getMessage()).isEqualTo("hello"); diff --git a/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsTest.java b/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsTest.java index 017e70b24bc..9c21ab605cd 100644 --- a/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsTest.java +++ b/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsTest.java @@ -74,7 +74,7 @@ void doMostBasicTest() throws Exception { (RemoteDependencyData) ((Data) rddEnvelope2.getData()).getBaseData(); assertThat(rd1.getName()).isEqualTo("GET /sendMessage"); - assertThat(rd1.getProperties()).isEmpty(); + assertThat(rd1.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(rd1.getSuccess()).isTrue(); assertThat(rdd1.getName()).isEqualTo("message send"); diff --git a/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java b/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java index 44863f123a5..8c50ec94e07 100644 --- a/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java +++ b/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java @@ -62,7 +62,8 @@ abstract class JdbcTest { void hsqldbPreparedStatement() throws Exception { Telemetry telemetry = testing.getTelemetry(1); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rdd1.getName()).isEqualTo("SELECT testdb.abc"); diff --git a/smoke-tests/apps/Jedis/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JedisTest.java b/smoke-tests/apps/Jedis/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JedisTest.java index e280e8251f1..532ca2abd79 100644 --- a/smoke-tests/apps/Jedis/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JedisTest.java +++ b/smoke-tests/apps/Jedis/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JedisTest.java @@ -55,7 +55,8 @@ void jedis() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getMeasurements()).isEmpty(); assertThat(telemetry.rdd1.getName()).isEqualTo("GET"); diff --git a/smoke-tests/apps/JettyNativeHandler/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JettyNativeHandlerTest.java b/smoke-tests/apps/JettyNativeHandler/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JettyNativeHandlerTest.java index 678e1416266..d6b0a441f8f 100644 --- a/smoke-tests/apps/JettyNativeHandler/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JettyNativeHandlerTest.java +++ b/smoke-tests/apps/JettyNativeHandler/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JettyNativeHandlerTest.java @@ -50,7 +50,8 @@ void doSimpleTest() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getMeasurements()).isEmpty(); } diff --git a/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaTest.java b/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaTest.java index 809ea469817..555045a2ef2 100644 --- a/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaTest.java +++ b/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaTest.java @@ -90,7 +90,7 @@ void doMostBasicTest() throws Exception { (RemoteDependencyData) ((Data) rddEnvelope2.getData()).getBaseData(); assertThat(rd1.getName()).isEqualTo("GET /sendMessage"); - assertThat(rd1.getProperties()).isEmpty(); + assertThat(rd1.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(rd1.getSuccess()).isTrue(); assertThat(rdd1.getName()).isEqualTo("mytopic send"); diff --git a/smoke-tests/apps/Lettuce/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/LettuceTest.java b/smoke-tests/apps/Lettuce/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/LettuceTest.java index 861ab598083..01a6c045d79 100644 --- a/smoke-tests/apps/Lettuce/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/LettuceTest.java +++ b/smoke-tests/apps/Lettuce/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/LettuceTest.java @@ -55,7 +55,8 @@ void lettuce() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getMeasurements()).isEmpty(); assertThat(telemetry.rdd1.getName()).isEqualTo("GET"); diff --git a/smoke-tests/apps/Micrometer/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/MicrometerTest.java b/smoke-tests/apps/Micrometer/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/MicrometerTest.java index 875329a02fe..757e9cdab9a 100644 --- a/smoke-tests/apps/Micrometer/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/MicrometerTest.java +++ b/smoke-tests/apps/Micrometer/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/MicrometerTest.java @@ -56,7 +56,8 @@ void doMostBasicTest() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getMeasurements()).isEmpty(); List metricItems = diff --git a/smoke-tests/apps/MongoDB/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/MongoTest.java b/smoke-tests/apps/MongoDB/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/MongoTest.java index 747c130747c..cd3ab9db7ba 100644 --- a/smoke-tests/apps/MongoDB/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/MongoTest.java +++ b/smoke-tests/apps/MongoDB/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/MongoTest.java @@ -55,7 +55,8 @@ void mongo() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getMeasurements()).isEmpty(); assertThat(telemetry.rdd1.getName()).isEqualTo("find testdb.test"); diff --git a/smoke-tests/apps/NonDaemonThreads/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/NonDaemonThreadsTest.java b/smoke-tests/apps/NonDaemonThreads/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/NonDaemonThreadsTest.java index 38e0ead7925..ee400405830 100644 --- a/smoke-tests/apps/NonDaemonThreads/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/NonDaemonThreadsTest.java +++ b/smoke-tests/apps/NonDaemonThreads/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/NonDaemonThreadsTest.java @@ -68,7 +68,7 @@ void spawnAnotherJavaProcess() throws Exception { (RemoteDependencyData) ((Data) rddEnvelope.getData()).getBaseData(); MessageData md = (MessageData) ((Data) mdEnvelope.getData()).getBaseData(); - assertThat(rd.getProperties()).isEmpty(); + assertThat(rd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(rd.getSuccess()).isTrue(); assertThat(rdd.getName()).isEqualTo("GET /search"); diff --git a/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java b/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java index 4526ccd5be6..fc8a5a1b5d1 100644 --- a/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java +++ b/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java @@ -54,7 +54,8 @@ void testApi() throws Exception { assertThat(telemetry.rd.getProperties()).hasSize(2); assertThat(telemetry.rd.getProperties()).containsEntry("myattr1", "myvalue1"); assertThat(telemetry.rd.getProperties()).containsEntry("myattr2", "myvalue2"); - assertThat(telemetry.rd.getMeasurements()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); // ideally want the properties below on rd, but can't get SERVER span yet // see diff --git a/smoke-tests/apps/SpringBootAttachInMain/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAttachInMainTest.java b/smoke-tests/apps/SpringBootAttachInMain/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAttachInMainTest.java index c210306a69b..5fe7f23bcf7 100644 --- a/smoke-tests/apps/SpringBootAttachInMain/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAttachInMainTest.java +++ b/smoke-tests/apps/SpringBootAttachInMain/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAttachInMainTest.java @@ -49,7 +49,8 @@ void doMostBasicTest() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getMeasurements()).isEmpty(); assertThat(telemetry.rdEnvelope.getTags()) diff --git a/smoke-tests/apps/SpringBootAuto/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java b/smoke-tests/apps/SpringBootAuto/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java index dedb850e1a0..8fd267949c4 100644 --- a/smoke-tests/apps/SpringBootAuto/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java +++ b/smoke-tests/apps/SpringBootAuto/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java @@ -56,7 +56,8 @@ void doMostBasicTest() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getMeasurements()).isEmpty(); } diff --git a/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootTest.java b/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootTest.java index a9ad539e4a2..01b93482b56 100644 --- a/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootTest.java +++ b/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootTest.java @@ -105,7 +105,7 @@ void testResultCodeWhenRestControllerThrows() throws Exception { assertThat(rd.getName()).isEqualTo("GET /SpringBootTest/throwsException"); assertThat(rd.getResponseCode()).isEqualTo("500"); - assertThat(rd.getProperties()).isEmpty(); + assertThat(rd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(rd.getSuccess()).isFalse(); SmokeTestExtension.assertParentChild( diff --git a/smoke-tests/apps/SpringCloudStream/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringCloudStreamTest.java b/smoke-tests/apps/SpringCloudStream/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringCloudStreamTest.java index 5651acbb917..9952de8902f 100644 --- a/smoke-tests/apps/SpringCloudStream/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringCloudStreamTest.java +++ b/smoke-tests/apps/SpringCloudStream/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringCloudStreamTest.java @@ -85,7 +85,7 @@ void doMostBasicTest() throws Exception { (RemoteDependencyData) ((Data) rddEnvelope1.getData()).getBaseData(); assertThat(rd1.getName()).isEqualTo("GET /sendMessage"); - assertThat(rd1.getProperties()).isEmpty(); + assertThat(rd1.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(rd1.getSuccess()).isTrue(); assertThat(rdd1.getName()).isEqualTo("greetings send"); diff --git a/smoke-tests/apps/TelemetryProcessors/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java b/smoke-tests/apps/TelemetryProcessors/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java index bce21d1f5f0..9d2f1bf5ddf 100644 --- a/smoke-tests/apps/TelemetryProcessors/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java +++ b/smoke-tests/apps/TelemetryProcessors/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java @@ -73,7 +73,7 @@ void doSimpleTestPiiData() throws Exception { assertThat(telemetry.rd.getProperties()).containsEntry("sensitiveAttribute1", "redacted"); assertThat(telemetry.rd.getProperties().get("httpPath")) .isEqualTo("*/TelemetryProcessors/sensitivedata*"); - assertThat(telemetry.rd.getProperties()).hasSize(4); + assertThat(telemetry.rd.getProperties()).hasSize(5); assertThat(telemetry.rd.getSuccess()).isTrue(); } diff --git a/smoke-tests/apps/WebFlux/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/WebFluxTest.java b/smoke-tests/apps/WebFlux/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/WebFluxTest.java index d7b50ec293e..4cb52bd7845 100644 --- a/smoke-tests/apps/WebFlux/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/WebFluxTest.java +++ b/smoke-tests/apps/WebFlux/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/WebFluxTest.java @@ -64,7 +64,8 @@ void testException() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("500"); assertThat(telemetry.rd.getSuccess()).isFalse(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getMeasurements()).isEmpty(); } From f63b8f5e5c9095b962f7584e0d96f423e2007e56 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Mon, 22 Aug 2022 11:30:01 -0700 Subject: [PATCH 59/95] Fix smoke tests --- .../smoketest/ClassicSdkWebInteropTest.java | 2 +- .../smoketest/ClassicSdkWebInteropTest.java | 2 +- .../smoketest/HttpClientSmokeTest.java | 9 ++++++--- .../applicationinsights/smoketest/HttpHeadersTest.java | 5 +++-- .../applicationinsights/smoketest/KafkaTest.java | 2 +- .../applicationinsights/smoketest/WebFluxTest.java | 3 ++- 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/smoke-tests/apps/ClassicSdkWebInterop2x/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/ClassicSdkWebInteropTest.java b/smoke-tests/apps/ClassicSdkWebInterop2x/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/ClassicSdkWebInteropTest.java index eefc126913d..6a6ac9fa5a5 100644 --- a/smoke-tests/apps/ClassicSdkWebInterop2x/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/ClassicSdkWebInteropTest.java +++ b/smoke-tests/apps/ClassicSdkWebInterop2x/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/ClassicSdkWebInteropTest.java @@ -54,7 +54,7 @@ void doMostBasicTest() throws Exception { .isEqualTo("mydeviceosversion"); assertThat(telemetry.rd.getProperties()).containsEntry("myattr1", "myvalue1"); assertThat(telemetry.rd.getProperties()).containsEntry("myattr2", "myvalue2"); - assertThat(telemetry.rd.getProperties()).hasSize(2); + assertThat(telemetry.rd.getProperties()).hasSize(3); assertThat(telemetry.rd.getSuccess()).isFalse(); } diff --git a/smoke-tests/apps/ClassicSdkWebInterop3x/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/ClassicSdkWebInteropTest.java b/smoke-tests/apps/ClassicSdkWebInterop3x/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/ClassicSdkWebInteropTest.java index eefc126913d..6a6ac9fa5a5 100644 --- a/smoke-tests/apps/ClassicSdkWebInterop3x/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/ClassicSdkWebInteropTest.java +++ b/smoke-tests/apps/ClassicSdkWebInterop3x/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/ClassicSdkWebInteropTest.java @@ -54,7 +54,7 @@ void doMostBasicTest() throws Exception { .isEqualTo("mydeviceosversion"); assertThat(telemetry.rd.getProperties()).containsEntry("myattr1", "myvalue1"); assertThat(telemetry.rd.getProperties()).containsEntry("myattr2", "myvalue2"); - assertThat(telemetry.rd.getProperties()).hasSize(2); + assertThat(telemetry.rd.getProperties()).hasSize(3); assertThat(telemetry.rd.getSuccess()).isFalse(); } diff --git a/smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpClientSmokeTest.java b/smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpClientSmokeTest.java index 1b5f5a0d183..e9e5eadea4d 100644 --- a/smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpClientSmokeTest.java +++ b/smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpClientSmokeTest.java @@ -107,7 +107,8 @@ private static void verify(String successUrlWithQueryString) throws Exception { assertThat(telemetry.rdd1.getType()).isEqualTo("Http"); assertThat(telemetry.rdd1.getTarget()).isEqualTo("mock.codes"); assertThat(telemetry.rdd1.getResultCode()).isEqualTo("200"); - assertThat(telemetry.rdd1.getProperties()).isEmpty(); + assertThat(telemetry.rdd1.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rdd1.getSuccess()).isTrue(); assertThat(telemetry.rddEnvelope1.getSampleRate()).isNull(); @@ -116,7 +117,8 @@ private static void verify(String successUrlWithQueryString) throws Exception { assertThat(telemetry.rdd2.getType()).isEqualTo("Http"); assertThat(telemetry.rdd2.getTarget()).isEqualTo("mock.codes"); assertThat(telemetry.rdd2.getResultCode()).isEqualTo("404"); - assertThat(telemetry.rdd2.getProperties()).isEmpty(); + assertThat(telemetry.rdd2.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rdd2.getSuccess()).isFalse(); assertThat(telemetry.rddEnvelope2.getSampleRate()).isNull(); @@ -125,7 +127,8 @@ private static void verify(String successUrlWithQueryString) throws Exception { assertThat(telemetry.rdd3.getType()).isEqualTo("Http"); assertThat(telemetry.rdd3.getTarget()).isEqualTo("mock.codes"); assertThat(telemetry.rdd3.getResultCode()).isEqualTo("500"); - assertThat(telemetry.rdd3.getProperties()).isEmpty(); + assertThat(telemetry.rdd3.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rdd3.getSuccess()).isFalse(); assertThat(telemetry.rddEnvelope3.getSampleRate()).isNull(); diff --git a/smoke-tests/apps/HttpHeaders/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpHeadersTest.java b/smoke-tests/apps/HttpHeaders/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpHeadersTest.java index 1b3aca1fb47..e8440445cde 100644 --- a/smoke-tests/apps/HttpHeaders/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpHeadersTest.java +++ b/smoke-tests/apps/HttpHeaders/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpHeadersTest.java @@ -58,9 +58,10 @@ void testClientHeaders() throws Exception { Telemetry telemetry = testing.getTelemetry(1); assertThat(telemetry.rd.getProperties()).containsKey("http.request.header.host"); - assertThat(telemetry.rd.getProperties()).hasSize(1); + assertThat(telemetry.rd.getProperties()).hasSize(2); assertThat(telemetry.rd.getSuccess()).isTrue(); - + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rdd1.getProperties().get("http.request.header.abc")) .isEqualTo("testing123"); assertThat(telemetry.rdd1.getProperties()).containsKey("http.response.header.date"); diff --git a/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaTest.java b/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaTest.java index 555045a2ef2..45f2ca861a7 100644 --- a/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaTest.java +++ b/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaTest.java @@ -109,7 +109,7 @@ void doMostBasicTest() throws Exception { assertThat(rdd2.getData()).isEqualTo("https://www.bing.com"); assertThat(rdd2.getType()).isEqualTo("Http"); assertThat(rdd2.getTarget()).isEqualTo("www.bing.com"); - assertThat(rdd2.getProperties()).isEmpty(); + assertThat(rdd2.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(rdd2.getSuccess()).isTrue(); SmokeTestExtension.assertParentChild(rd1, rdEnvelope1, rddEnvelope1, "GET /sendMessage"); diff --git a/smoke-tests/apps/WebFlux/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/WebFluxTest.java b/smoke-tests/apps/WebFlux/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/WebFluxTest.java index 4cb52bd7845..4a04a2a70e1 100644 --- a/smoke-tests/apps/WebFlux/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/WebFluxTest.java +++ b/smoke-tests/apps/WebFlux/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/WebFluxTest.java @@ -50,7 +50,8 @@ void doMostBasicTest() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getMeasurements()).isEmpty(); } From 2fef2858926075cab6a6c7d47f598e614a9e0192 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Mon, 22 Aug 2022 11:54:38 -0700 Subject: [PATCH 60/95] Fix tests --- .../applicationinsights/smoketest/HttpHeadersTest.java | 2 +- .../applicationinsights/smoketest/HttpServer4xxTest.java | 3 ++- .../com/microsoft/applicationinsights/smoketest/JmsTest.java | 2 +- .../com/microsoft/applicationinsights/smoketest/JdbcTest.java | 3 ++- .../applicationinsights/smoketest/KafkaDisabledTest.java | 2 +- .../applicationinsights/smoketest/NonDaemonThreadsTest.java | 2 +- .../OpenTelemetryApiSupportControllerSpansEnabledTest.java | 3 ++- .../applicationinsights/smoketest/SpringBootTest.java | 2 +- .../smoketest/SpringCloudStreamControllerSpansEnabledTest.java | 2 +- .../microsoft/applicationinsights/smoketest/WebFluxTest.java | 3 ++- 10 files changed, 14 insertions(+), 10 deletions(-) diff --git a/smoke-tests/apps/HttpHeaders/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpHeadersTest.java b/smoke-tests/apps/HttpHeaders/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpHeadersTest.java index e8440445cde..809b267fd4d 100644 --- a/smoke-tests/apps/HttpHeaders/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpHeadersTest.java +++ b/smoke-tests/apps/HttpHeaders/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpHeadersTest.java @@ -65,7 +65,7 @@ void testClientHeaders() throws Exception { assertThat(telemetry.rdd1.getProperties().get("http.request.header.abc")) .isEqualTo("testing123"); assertThat(telemetry.rdd1.getProperties()).containsKey("http.response.header.date"); - assertThat(telemetry.rdd1.getProperties()).hasSize(2); + assertThat(telemetry.rdd1.getProperties()).hasSize(3); assertThat(telemetry.rdd1.getSuccess()).isTrue(); } diff --git a/smoke-tests/apps/HttpServer4xx/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpServer4xxTest.java b/smoke-tests/apps/HttpServer4xx/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpServer4xxTest.java index c529f649ab6..bba014cdca8 100644 --- a/smoke-tests/apps/HttpServer4xx/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpServer4xxTest.java +++ b/smoke-tests/apps/HttpServer4xx/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpServer4xxTest.java @@ -50,7 +50,8 @@ void doMostBasicTest() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("400"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getMeasurements()).isEmpty(); } diff --git a/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsTest.java b/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsTest.java index 9c21ab605cd..b0482717ce1 100644 --- a/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsTest.java +++ b/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsTest.java @@ -93,7 +93,7 @@ void doMostBasicTest() throws Exception { assertThat(rdd2.getData()).isEqualTo("https://www.bing.com"); assertThat(rdd2.getType()).isEqualTo("Http"); assertThat(rdd2.getTarget()).isEqualTo("www.bing.com"); - assertThat(rdd2.getProperties()).isEmpty(); + assertThat(rdd2.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(rdd2.getSuccess()).isTrue(); SmokeTestExtension.assertParentChild(rd1, rdEnvelope1, rddEnvelope1, "GET /sendMessage"); diff --git a/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java b/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java index 8c50ec94e07..6e644daa904 100644 --- a/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java +++ b/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java @@ -256,7 +256,8 @@ void postgresStatement() throws Exception { void sqlServerPreparedStatement() throws Exception { Telemetry telemetry = testing.getTelemetry(1); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rdd1.getName()).isEqualTo("SELECT abc"); diff --git a/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaDisabledTest.java b/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaDisabledTest.java index 9bc189106cd..a2142d366ce 100644 --- a/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaDisabledTest.java +++ b/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaDisabledTest.java @@ -66,7 +66,7 @@ void doMostBasicTest() throws Exception { assertThat(rd.getName()).isEqualTo("GET /sendMessage"); assertThat(rd.getResponseCode()).isEqualTo("200"); - assertThat(rd.getProperties()).isEmpty(); + assertThat(rd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(rd.getSuccess()).isTrue(); // verify the downstream http dependency that is no longer part of the same trace diff --git a/smoke-tests/apps/NonDaemonThreads/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/NonDaemonThreadsTest.java b/smoke-tests/apps/NonDaemonThreads/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/NonDaemonThreadsTest.java index ee400405830..8d3614f8d27 100644 --- a/smoke-tests/apps/NonDaemonThreads/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/NonDaemonThreadsTest.java +++ b/smoke-tests/apps/NonDaemonThreads/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/NonDaemonThreadsTest.java @@ -75,7 +75,7 @@ void spawnAnotherJavaProcess() throws Exception { assertThat(rdd.getType()).isEqualTo("Http"); assertThat(rdd.getTarget()).isEqualTo("www.bing.com"); assertThat(rdd.getData()).isEqualTo("https://www.bing.com/search?q=test"); - assertThat(rdd.getProperties()).isEmpty(); + assertThat(rdd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(rdd.getSuccess()).isTrue(); assertThat(md.getMessage()).isEqualTo("done"); diff --git a/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportControllerSpansEnabledTest.java b/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportControllerSpansEnabledTest.java index e7e03f714e3..31fd02e0f02 100644 --- a/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportControllerSpansEnabledTest.java +++ b/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportControllerSpansEnabledTest.java @@ -91,7 +91,8 @@ void testOverridingIkeyEtc() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getMeasurements()).isEmpty(); assertThat(telemetry.rdd1.getName()).isEqualTo("TestController.testOverridingIkeyEtc"); diff --git a/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootTest.java b/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootTest.java index 01b93482b56..fdafc54fe37 100644 --- a/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootTest.java +++ b/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootTest.java @@ -134,7 +134,7 @@ void testAsyncDependencyCall() throws Exception { assertThat(rd.getName()).isEqualTo("GET /SpringBootTest/asyncDependencyCall"); assertThat(rd.getResponseCode()).isEqualTo("200"); - assertThat(rd.getProperties()).isEmpty(); + assertThat(rd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(rd.getSuccess()).isTrue(); assertThat(rdd1.getName()).isEqualTo("GET /"); diff --git a/smoke-tests/apps/SpringCloudStream/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringCloudStreamControllerSpansEnabledTest.java b/smoke-tests/apps/SpringCloudStream/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringCloudStreamControllerSpansEnabledTest.java index 2f1536097e2..f81554292f9 100644 --- a/smoke-tests/apps/SpringCloudStream/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringCloudStreamControllerSpansEnabledTest.java +++ b/smoke-tests/apps/SpringCloudStream/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringCloudStreamControllerSpansEnabledTest.java @@ -92,7 +92,7 @@ void doMostBasicTest() throws Exception { } assertThat(rd1.getName()).isEqualTo("GET /sendMessage"); - assertThat(rd1.getProperties()).isEmpty(); + assertThat(rd1.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(rd1.getSuccess()).isTrue(); assertThat(rdd1.getName()).isEqualTo("GreetingsController.sendMessage"); diff --git a/smoke-tests/apps/WebFlux/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/WebFluxTest.java b/smoke-tests/apps/WebFlux/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/WebFluxTest.java index 4a04a2a70e1..82d11eaa420 100644 --- a/smoke-tests/apps/WebFlux/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/WebFluxTest.java +++ b/smoke-tests/apps/WebFlux/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/WebFluxTest.java @@ -80,7 +80,8 @@ void testFutureException() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("500"); assertThat(telemetry.rd.getSuccess()).isFalse(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getMeasurements()).isEmpty(); } From bd12ff8eb89b3e61ec481afde8b9f7a51cbd5f7f Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Mon, 22 Aug 2022 12:44:56 -0700 Subject: [PATCH 61/95] Fix tests --- .../JmsControllerSpansEnabledTest.java | 131 ------------------ .../smoketest/JdbcTest.java | 3 +- .../KafkaControllerSpansEnabledTest.java | 2 +- .../OpenTelemetryApiSupportTest.java | 2 +- 4 files changed, 4 insertions(+), 134 deletions(-) delete mode 100644 smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsControllerSpansEnabledTest.java diff --git a/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsControllerSpansEnabledTest.java b/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsControllerSpansEnabledTest.java deleted file mode 100644 index 844945fbfcb..00000000000 --- a/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsControllerSpansEnabledTest.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * ApplicationInsights-Java - * Copyright (c) Microsoft Corporation - * All rights reserved. - * - * MIT License - * Permission is hereby granted, free of charge, to any person obtaining a copy of this - * software and associated documentation files (the ""Software""), to deal in the Software - * without restriction, including without limitation the rights to use, copy, modify, merge, - * publish, distribute, sublicense, and/or sell copies of the Software, and to permit - * persons to whom the Software is furnished to do so, subject to the following conditions: - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE - * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -package com.microsoft.applicationinsights.smoketest; - -import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.JAVA_8; -import static org.assertj.core.api.Assertions.assertThat; - -import com.microsoft.applicationinsights.smoketest.schemav2.Data; -import com.microsoft.applicationinsights.smoketest.schemav2.Envelope; -import com.microsoft.applicationinsights.smoketest.schemav2.RemoteDependencyData; -import com.microsoft.applicationinsights.smoketest.schemav2.RequestData; -import java.util.List; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -@Environment(JAVA_8) -@UseAgent("controller_spans_enabled_applicationinsights.json") -class JmsControllerSpansEnabledTest { - - @RegisterExtension static final SmokeTestExtension testing = new SmokeTestExtension(); - - @Test - @TargetUri("/sendMessage") - void doMostBasicTest() throws Exception { - List rdList = testing.mockedIngestion.waitForItems("RequestData", 2); - - Envelope rdEnvelope1 = getRequestEnvelope(rdList, "GET /sendMessage"); - String operationId = rdEnvelope1.getTags().get("ai.operation.id"); - List rddList = - testing.mockedIngestion.waitForItemsInOperation("RemoteDependencyData", 3, operationId); - assertThat(testing.mockedIngestion.getCountForType("EventData")).isZero(); - - Envelope rdEnvelope2 = getRequestEnvelope(rdList, "message process"); - Envelope rddEnvelope1 = getDependencyEnvelope(rddList, "HelloController.sendMessage"); - Envelope rddEnvelope2 = getDependencyEnvelope(rddList, "message send"); - Envelope rddEnvelope3 = getDependencyEnvelope(rddList, "GET /"); - - assertThat(rdEnvelope1.getSampleRate()).isNull(); - assertThat(rdEnvelope2.getSampleRate()).isNull(); - assertThat(rddEnvelope1.getSampleRate()).isNull(); - assertThat(rddEnvelope2.getSampleRate()).isNull(); - assertThat(rddEnvelope3.getSampleRate()).isNull(); - - RequestData rd1 = (RequestData) ((Data) rdEnvelope1.getData()).getBaseData(); - RequestData rd2 = (RequestData) ((Data) rdEnvelope2.getData()).getBaseData(); - - RemoteDependencyData rdd1 = - (RemoteDependencyData) ((Data) rddEnvelope1.getData()).getBaseData(); - RemoteDependencyData rdd2 = - (RemoteDependencyData) ((Data) rddEnvelope2.getData()).getBaseData(); - RemoteDependencyData rdd3 = - (RemoteDependencyData) ((Data) rddEnvelope3.getData()).getBaseData(); - - assertThat(rd1.getName()).isEqualTo("GET /sendMessage"); - assertThat(rd1.getProperties()).isEmpty(); - assertThat(rd1.getSuccess()).isTrue(); - - assertThat(rdd1.getName()).isEqualTo("HelloController.sendMessage"); - assertThat(rdd1.getData()).isNull(); - assertThat(rdd1.getType()).isEqualTo("InProc"); - assertThat(rdd1.getTarget()).isNull(); - assertThat(rdd1.getProperties()).isEmpty(); - assertThat(rdd1.getSuccess()).isTrue(); - - assertThat(rdd2.getName()).isEqualTo("message send"); - assertThat(rdd2.getData()).isNull(); - assertThat(rdd2.getType()).isEqualTo("Queue Message | jms"); - assertThat(rdd2.getTarget()).isEqualTo("message"); - assertThat(rdd2.getProperties()).isEmpty(); - assertThat(rdd2.getSuccess()).isTrue(); - - assertThat(rd2.getName()).isEqualTo("message process"); - assertThat(rd2.getSource()).isEqualTo("message"); - assertThat(rd2.getProperties()).isEmpty(); - assertThat(rd2.getSuccess()).isTrue(); - - assertThat(rdd3.getName()).isEqualTo("GET /"); - assertThat(rdd3.getData()).isEqualTo("https://www.bing.com"); - assertThat(rdd3.getType()).isEqualTo("Http"); - assertThat(rdd3.getTarget()).isEqualTo("www.bing.com"); - assertThat(rdd3.getProperties()).isEmpty(); - assertThat(rdd3.getSuccess()).isTrue(); - - SmokeTestExtension.assertParentChild(rd1, rdEnvelope1, rddEnvelope1, "GET /sendMessage"); - SmokeTestExtension.assertParentChild(rdd1, rddEnvelope1, rddEnvelope2, "GET /sendMessage"); - SmokeTestExtension.assertParentChild( - rdd2.getId(), rddEnvelope2, rdEnvelope2, "GET /sendMessage", "message process", false); - SmokeTestExtension.assertParentChild( - rd2.getId(), rdEnvelope2, rddEnvelope3, "message process", "message process", false); - } - - private static Envelope getRequestEnvelope(List envelopes, String name) { - for (Envelope envelope : envelopes) { - RequestData rd = (RequestData) ((Data) envelope.getData()).getBaseData(); - if (rd.getName().equals(name)) { - return envelope; - } - } - throw new IllegalStateException("Could not find request with name: " + name); - } - - private static Envelope getDependencyEnvelope(List envelopes, String name) { - for (Envelope envelope : envelopes) { - RemoteDependencyData rdd = - (RemoteDependencyData) ((Data) envelope.getData()).getBaseData(); - if (rdd.getName().equals(name)) { - return envelope; - } - } - throw new IllegalStateException("Could not find dependency with name: " + name); - } -} diff --git a/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java b/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java index 6e644daa904..b95cdacff86 100644 --- a/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java +++ b/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java @@ -276,7 +276,8 @@ void sqlServerPreparedStatement() throws Exception { void sqlServerStatement() throws Exception { Telemetry telemetry = testing.getTelemetry(1); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rdd1.getName()).isEqualTo("SELECT abc"); diff --git a/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaControllerSpansEnabledTest.java b/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaControllerSpansEnabledTest.java index 31b4b9ece5e..7f883674b98 100644 --- a/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaControllerSpansEnabledTest.java +++ b/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaControllerSpansEnabledTest.java @@ -87,7 +87,7 @@ void doMostBasicTest() throws Exception { (RemoteDependencyData) ((Data) rddEnvelope3.getData()).getBaseData(); assertThat(rd1.getName()).isEqualTo("GET /sendMessage"); - assertThat(rd1.getProperties()).isEmpty(); + assertThat(rdd1.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(rd1.getSuccess()).isTrue(); assertThat(rdd1.getName()).isEqualTo("HelloController.sendMessage"); diff --git a/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java b/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java index fc8a5a1b5d1..69658f6bafe 100644 --- a/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java +++ b/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java @@ -51,7 +51,7 @@ void testApi() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties()).hasSize(2); + assertThat(telemetry.rd.getProperties()).hasSize(3); assertThat(telemetry.rd.getProperties()).containsEntry("myattr1", "myvalue1"); assertThat(telemetry.rd.getProperties()).containsEntry("myattr2", "myvalue2"); assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) From e0a6763621f1855e7905007e7cfd9d2108bcc29d Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Mon, 22 Aug 2022 13:11:20 -0700 Subject: [PATCH 62/95] Fix --- .../applicationinsights/smoketest/JmsDisabledTest.java | 2 +- .../com/microsoft/applicationinsights/smoketest/JdbcTest.java | 3 ++- .../smoketest/KafkaControllerSpansEnabledTest.java | 2 +- .../OpenTelemetryApiSupportControllerSpansEnabledTest.java | 3 ++- .../smoketest/SpringBootControllerSpansEnabledTest.java | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsDisabledTest.java b/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsDisabledTest.java index 6a5c041d934..63b9654d3a3 100644 --- a/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsDisabledTest.java +++ b/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsDisabledTest.java @@ -50,7 +50,7 @@ void doMostBasicTest() throws Exception { assertThat(rd.getName()).isEqualTo("GET /sendMessage"); assertThat(rd.getResponseCode()).isEqualTo("200"); - assertThat(rd.getProperties()).isEmpty(); + assertThat(rd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(rd.getSuccess()).isTrue(); // verify the downstream http dependency that is no longer part of the same trace diff --git a/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java b/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java index b95cdacff86..19a71ef2d79 100644 --- a/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java +++ b/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java @@ -236,7 +236,8 @@ void postgresPreparedStatement() throws Exception { void postgresStatement() throws Exception { Telemetry telemetry = testing.getTelemetry(1); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rdd1.getName()).isEqualTo("SELECT postgres.abc"); diff --git a/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaControllerSpansEnabledTest.java b/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaControllerSpansEnabledTest.java index 7f883674b98..3005ed0a486 100644 --- a/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaControllerSpansEnabledTest.java +++ b/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaControllerSpansEnabledTest.java @@ -87,7 +87,7 @@ void doMostBasicTest() throws Exception { (RemoteDependencyData) ((Data) rddEnvelope3.getData()).getBaseData(); assertThat(rd1.getName()).isEqualTo("GET /sendMessage"); - assertThat(rdd1.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(rd1.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(rd1.getSuccess()).isTrue(); assertThat(rdd1.getName()).isEqualTo("HelloController.sendMessage"); diff --git a/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportControllerSpansEnabledTest.java b/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportControllerSpansEnabledTest.java index 31fd02e0f02..84893a20c0c 100644 --- a/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportControllerSpansEnabledTest.java +++ b/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportControllerSpansEnabledTest.java @@ -144,7 +144,8 @@ void testAnnotations() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getMeasurements()).isEmpty(); assertThat(telemetry.rdd1.getName()).isEqualTo("TestController.testAnnotations"); diff --git a/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootControllerSpansEnabledTest.java b/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootControllerSpansEnabledTest.java index 4aa7daa42eb..56cfdd7ba73 100644 --- a/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootControllerSpansEnabledTest.java +++ b/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootControllerSpansEnabledTest.java @@ -111,7 +111,7 @@ public boolean test(Envelope input) { assertThat(rd.getName()).isEqualTo("GET /SpringBootTest/throwsException"); assertThat(rd.getResponseCode()).isEqualTo("500"); - assertThat(rd.getProperties()).isEmpty(); + assertThat(rd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(rd.getSuccess()).isFalse(); assertThat(rdd1.getName()).isEqualTo("TestController.resultCodeTest"); From f06077e002fd28e91f637c639281ca85f895dfe4 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Mon, 22 Aug 2022 13:43:10 -0700 Subject: [PATCH 63/95] Debug synthetic --- .../instrumentation/api/instrumenter/UserAgents.java | 9 +++------ .../exporter/implementation/MetricDataMapper.java | 2 ++ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/UserAgents.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/UserAgents.java index 5403adcd6f4..e29b8326085 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/UserAgents.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/UserAgents.java @@ -24,6 +24,7 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; import javax.annotation.Nullable; +import org.slf4j.LoggerFactory; public final class UserAgents { @@ -31,16 +32,12 @@ public final class UserAgents { public static final String TARGET = "target"; public static final String IS_PRE_AGGREGATED = "isPreAggregated"; - @SuppressWarnings("SystemOut") public static boolean isUserAgentBot(Attributes endAttributes, Attributes startAttributes) { String aiUserAgent = getAttribute(AttributeKey.stringKey("ai.user.userAgent"), endAttributes, startAttributes); // TODO to be removed debug log - System.out.println("############## HttpServerMetrics::aiUserAgent: " + aiUserAgent); - if (aiUserAgent != null && aiUserAgent.indexOf("AlwaysOn") >= 0) { - return true; - } - return false; + LoggerFactory.getLogger(UserAgents.class).debug("############## aiUserAgent: {}", aiUserAgent); + return aiUserAgent != null && aiUserAgent.indexOf("AlwaysOn") >= 0; } @Nullable diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index 1f75a79d493..a5ff55ee303 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -162,6 +162,8 @@ public static void updateMetricPointBuilder( boolean success = getSuccess(statusCode, captureHttpServer4xxAsError); String isSyntheticString = pointData.getAttributes().get(AttributeKey.stringKey("isSynthetic")); + // TODO to be removed + logger.debug("####### isSyntheticString: {}", isSyntheticString); boolean isSynthetic = false; if (isSyntheticString != null) { isSynthetic = Boolean.valueOf(isSyntheticString); From b9d66692f36783634d84301959968bcf406d8c80 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Mon, 22 Aug 2022 14:20:13 -0700 Subject: [PATCH 64/95] Fix tests --- .../applicationinsights/smoketest/JmsDisabledTest.java | 2 +- .../microsoft/applicationinsights/smoketest/SpringBootTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsDisabledTest.java b/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsDisabledTest.java index 63b9654d3a3..65abffd2791 100644 --- a/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsDisabledTest.java +++ b/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsDisabledTest.java @@ -65,7 +65,7 @@ void doMostBasicTest() throws Exception { assertThat(rdd.getName()).isEqualTo("GET /"); assertThat(rdd.getData()).isEqualTo("https://www.bing.com"); - assertThat(rdd.getProperties()).isEmpty(); + assertThat(rdd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(rdd.getSuccess()).isTrue(); // sleep a bit and make sure no kafka "requests" or dependencies are reported diff --git a/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootTest.java b/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootTest.java index fdafc54fe37..6da942c34ed 100644 --- a/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootTest.java +++ b/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootTest.java @@ -140,7 +140,7 @@ void testAsyncDependencyCall() throws Exception { assertThat(rdd1.getName()).isEqualTo("GET /"); assertThat(rdd1.getData()).isEqualTo("https://www.bing.com"); assertThat(rdd1.getTarget()).isEqualTo("www.bing.com"); - assertThat(rdd1.getProperties()).isEmpty(); + assertThat(rdd1.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(rdd1.getSuccess()).isTrue(); SmokeTestExtension.assertParentChild( From 7802806f0e4fc0c5d67fe1c9da9b7705aa731228 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Mon, 22 Aug 2022 14:52:39 -0700 Subject: [PATCH 65/95] Fix userAgent otel key and more tests --- .../instrumentation/api/instrumenter/UserAgents.java | 3 ++- .../applicationinsights/smoketest/CoreAndFilterTests.java | 2 +- .../applicationinsights/smoketest/JmsDisabledTest.java | 2 +- .../com/microsoft/applicationinsights/smoketest/JdbcTest.java | 3 ++- .../smoketest/KafkaControllerSpansEnabledTest.java | 2 +- .../smoketest/OpenTelemetryApiSupportTest.java | 3 ++- 6 files changed, 9 insertions(+), 6 deletions(-) diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/UserAgents.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/UserAgents.java index e29b8326085..96e0ee4d0d2 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/UserAgents.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/UserAgents.java @@ -23,6 +23,7 @@ import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import javax.annotation.Nullable; import org.slf4j.LoggerFactory; @@ -34,7 +35,7 @@ public final class UserAgents { public static boolean isUserAgentBot(Attributes endAttributes, Attributes startAttributes) { String aiUserAgent = - getAttribute(AttributeKey.stringKey("ai.user.userAgent"), endAttributes, startAttributes); + getAttribute(SemanticAttributes.HTTP_USER_AGENT, endAttributes, startAttributes); // TODO to be removed debug log LoggerFactory.getLogger(UserAgents.class).debug("############## aiUserAgent: {}", aiUserAgent); return aiUserAgent != null && aiUserAgent.indexOf("AlwaysOn") >= 0; diff --git a/smoke-tests/apps/CoreAndFilter3x/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CoreAndFilterTests.java b/smoke-tests/apps/CoreAndFilter3x/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CoreAndFilterTests.java index 47156538751..891240ee2fc 100644 --- a/smoke-tests/apps/CoreAndFilter3x/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CoreAndFilterTests.java +++ b/smoke-tests/apps/CoreAndFilter3x/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CoreAndFilterTests.java @@ -183,7 +183,7 @@ void testHttpRequest() throws Exception { testing.mockedIngestion.waitForItems("RequestData", 5); int totalItems = testing.mockedIngestion.getItemCount(); - assertThat(totalItems).isEqualTo(6); + assertThat(totalItems).isEqualTo(5); // TODO get HttpRequest data envelope and verify value List requests = testing.mockedIngestion.getTelemetryDataByType("RequestData"); diff --git a/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsDisabledTest.java b/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsDisabledTest.java index 65abffd2791..63b9654d3a3 100644 --- a/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsDisabledTest.java +++ b/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsDisabledTest.java @@ -65,7 +65,7 @@ void doMostBasicTest() throws Exception { assertThat(rdd.getName()).isEqualTo("GET /"); assertThat(rdd.getData()).isEqualTo("https://www.bing.com"); - assertThat(rdd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(rdd.getProperties()).isEmpty(); assertThat(rdd.getSuccess()).isTrue(); // sleep a bit and make sure no kafka "requests" or dependencies are reported diff --git a/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java b/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java index 19a71ef2d79..b5bbb36b629 100644 --- a/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java +++ b/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java @@ -82,7 +82,8 @@ void hsqldbPreparedStatement() throws Exception { void hsqldbStatement() throws Exception { Telemetry telemetry = testing.getTelemetry(1); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rdd1.getName()).isEqualTo("SELECT testdb.abc"); diff --git a/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaControllerSpansEnabledTest.java b/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaControllerSpansEnabledTest.java index 3005ed0a486..b6418e5fb36 100644 --- a/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaControllerSpansEnabledTest.java +++ b/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaControllerSpansEnabledTest.java @@ -114,7 +114,7 @@ void doMostBasicTest() throws Exception { assertThat(rdd3.getData()).isEqualTo("https://www.bing.com"); assertThat(rdd3.getType()).isEqualTo("Http"); assertThat(rdd3.getTarget()).isEqualTo("www.bing.com"); - assertThat(rdd3.getProperties()).isEmpty(); + assertThat(rdd3.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(rdd3.getSuccess()).isTrue(); SmokeTestExtension.assertParentChild(rd1, rdEnvelope1, rddEnvelope1, "GET /sendMessage"); diff --git a/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java b/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java index 69658f6bafe..8816e1c9aa6 100644 --- a/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java +++ b/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java @@ -110,7 +110,8 @@ void testAnnotations() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getMeasurements()).isEmpty(); assertThat(telemetry.rdd1.getName()).isEqualTo("TestController.underAnnotation"); From 6075e3f5106c23da5f720a25a859fb00f2994626 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Mon, 22 Aug 2022 15:08:12 -0700 Subject: [PATCH 66/95] Fix more tests --- .../applicationinsights/smoketest/JmsDisabledTest.java | 2 +- .../com/microsoft/applicationinsights/smoketest/JdbcTest.java | 3 ++- .../applicationinsights/smoketest/KafkaDisabledTest.java | 2 +- .../OpenTelemetryApiSupportControllerSpansEnabledTest.java | 3 ++- .../smoketest/SpringBootControllerSpansEnabledTest.java | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsDisabledTest.java b/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsDisabledTest.java index 63b9654d3a3..65abffd2791 100644 --- a/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsDisabledTest.java +++ b/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsDisabledTest.java @@ -65,7 +65,7 @@ void doMostBasicTest() throws Exception { assertThat(rdd.getName()).isEqualTo("GET /"); assertThat(rdd.getData()).isEqualTo("https://www.bing.com"); - assertThat(rdd.getProperties()).isEmpty(); + assertThat(rdd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(rdd.getSuccess()).isTrue(); // sleep a bit and make sure no kafka "requests" or dependencies are reported diff --git a/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java b/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java index b5bbb36b629..f04e4c46cd3 100644 --- a/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java +++ b/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java @@ -175,7 +175,8 @@ void mysqlPreparedStatement() throws Exception { Telemetry telemetry = testing.getTelemetry(1, rdd -> !rdd.getData().startsWith("/* mysql-connector-java? ")); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rdd1.getName()).isEqualTo("SELECT mysql.abc"); diff --git a/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaDisabledTest.java b/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaDisabledTest.java index a2142d366ce..901244f163e 100644 --- a/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaDisabledTest.java +++ b/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaDisabledTest.java @@ -81,7 +81,7 @@ void doMostBasicTest() throws Exception { assertThat(rdd.getName()).isEqualTo("GET /"); assertThat(rdd.getData()).isEqualTo("https://www.bing.com"); - assertThat(rdd.getProperties()).isEmpty(); + assertThat(rdd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(rdd.getSuccess()).isTrue(); // sleep a bit and make sure no kafka "requests" or dependencies are reported diff --git a/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportControllerSpansEnabledTest.java b/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportControllerSpansEnabledTest.java index 84893a20c0c..474d24517e2 100644 --- a/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportControllerSpansEnabledTest.java +++ b/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportControllerSpansEnabledTest.java @@ -46,7 +46,8 @@ void testApi() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getMeasurements()).isEmpty(); assertThat(telemetry.rdd1.getName()).isEqualTo("myspanname"); diff --git a/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootControllerSpansEnabledTest.java b/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootControllerSpansEnabledTest.java index 56cfdd7ba73..6e52385fe5d 100644 --- a/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootControllerSpansEnabledTest.java +++ b/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootControllerSpansEnabledTest.java @@ -157,7 +157,7 @@ void testAsyncDependencyCall() throws Exception { assertThat(rd.getName()).isEqualTo("GET /SpringBootTest/asyncDependencyCall"); assertThat(rd.getResponseCode()).isEqualTo("200"); - assertThat(rd.getProperties()).isEmpty(); + assertThat(rd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(rd.getSuccess()).isTrue(); assertThat(rdd1.getName()).isEqualTo("TestController.asyncDependencyCall"); From 25384f3fbee260008ea1be7bf7bff30d8c5dbcda Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Mon, 22 Aug 2022 17:12:06 -0700 Subject: [PATCH 67/95] Fix more tests --- .../smoketest/JdbcTest.java | 21 ++++++++++++------- .../OpenTelemetryApiSupportTest.java | 2 ++ .../SpringBootControllerSpansEnabledTest.java | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java b/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java index f04e4c46cd3..a8a19bd50ce 100644 --- a/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java +++ b/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java @@ -102,7 +102,8 @@ void hsqldbStatement() throws Exception { void hsqldbLargeStatement() throws Exception { Telemetry telemetry = testing.getTelemetry(1); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getSuccess()).isTrue(); StringBuilder a2000 = new StringBuilder(); @@ -129,7 +130,8 @@ void hsqldbLargeStatement() throws Exception { void hsqldbBatchPreparedStatement() throws Exception { Telemetry telemetry = testing.getTelemetry(1); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rdd1.getName()).isEqualTo("INSERT testdb.abc"); @@ -150,7 +152,8 @@ void hsqldbBatchPreparedStatement() throws Exception { void hsqldbBatchStatement() throws Exception { Telemetry telemetry = testing.getTelemetry(1); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rdd1.getName()).isEqualTo("insert testdb.abc"); @@ -198,7 +201,8 @@ void mysqlStatement() throws Exception { Telemetry telemetry = testing.getTelemetry(1, rdd -> !rdd.getData().startsWith("/* mysql-connector-java? ")); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rdd1.getName()).isEqualTo("SELECT mysql.abc"); @@ -218,7 +222,8 @@ void mysqlStatement() throws Exception { void postgresPreparedStatement() throws Exception { Telemetry telemetry = testing.getTelemetry(1); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rdd1.getName()).isEqualTo("SELECT postgres.abc"); @@ -300,7 +305,8 @@ void sqlServerStatement() throws Exception { void oraclePreparedStatement() throws Exception { Telemetry telemetry = testing.getTelemetry(1); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rdd1.getName()).isEqualTo("SELECT abc"); @@ -320,7 +326,8 @@ void oraclePreparedStatement() throws Exception { void oracleStatement() throws Exception { Telemetry telemetry = testing.getTelemetry(1); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rdd1.getName()).isEqualTo("SELECT abc"); diff --git a/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java b/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java index 8816e1c9aa6..7edf4d8f657 100644 --- a/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java +++ b/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java @@ -84,6 +84,8 @@ void testOverridingIkeyEtc() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getProperties()).isEmpty(); assertThat(telemetry.rd.getMeasurements()).isEmpty(); diff --git a/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootControllerSpansEnabledTest.java b/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootControllerSpansEnabledTest.java index 6e52385fe5d..e017253f34f 100644 --- a/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootControllerSpansEnabledTest.java +++ b/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootControllerSpansEnabledTest.java @@ -170,7 +170,7 @@ void testAsyncDependencyCall() throws Exception { assertThat(rdd2.getName()).isEqualTo("GET /"); assertThat(rdd2.getData()).isEqualTo("https://www.bing.com"); assertThat(rdd2.getTarget()).isEqualTo("www.bing.com"); - assertThat(rdd2.getProperties()).isEmpty(); + assertThat(rdd2.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); assertThat(rdd2.getSuccess()).isTrue(); // TODO (trask): why is spring-webmvc instrumentation capturing this twice? From cd388142335bf41209a1baa4b1610f4ca71bd418 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Mon, 22 Aug 2022 19:04:29 -0700 Subject: [PATCH 68/95] Fix one more test --- .../smoketest/OpenTelemetryApiSupportTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java b/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java index 7edf4d8f657..5dcfba3acc6 100644 --- a/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java +++ b/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java @@ -86,7 +86,8 @@ void testOverridingIkeyEtc() throws Exception { assertThat(telemetry.rd.getSource()).isNull(); assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) .isEqualTo("True"); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) + .isEqualTo("True"); assertThat(telemetry.rd.getMeasurements()).isEmpty(); // checking that instrumentation key, cloud role name, cloud role instance, and sdk version are From 2d45b25c522d7518ac4bff8a490bd89d6b4aa875 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Mon, 22 Aug 2022 19:33:49 -0700 Subject: [PATCH 69/95] Fix pre-agg metrics' custom dimensions --- .../exporter/implementation/MetricDataMapper.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index a5ff55ee303..30ff6900cad 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -105,7 +105,10 @@ private List convertOtelMetricToAzureMonitorMetric( for (PointData pointData : metricData.getData().getPoints()) { MetricTelemetryBuilder builder = MetricTelemetryBuilder.create(); - telemetryInitializer.accept(builder, metricData.getResource()); + // do not populate default tags and properties for pre-aggregated metrics + if (!isPreAggregated) { + telemetryInitializer.accept(builder, metricData.getResource()); + } builder.setTime(FormattedTime.offSetDateTimeFromEpochNanos(pointData.getEpochNanos())); updateMetricPointBuilder( From 9cac0e8c6b1d3d96a017d62c36bd4997a5402fb8 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Mon, 22 Aug 2022 19:52:58 -0700 Subject: [PATCH 70/95] Revert change and add a todo --- .../exporter/implementation/MetricDataMapper.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index 30ff6900cad..121232269a1 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -105,10 +105,8 @@ private List convertOtelMetricToAzureMonitorMetric( for (PointData pointData : metricData.getData().getPoints()) { MetricTelemetryBuilder builder = MetricTelemetryBuilder.create(); - // do not populate default tags and properties for pre-aggregated metrics - if (!isPreAggregated) { - telemetryInitializer.accept(builder, metricData.getResource()); - } + // TODO (heya) do not apply custom dimensions to pre-aggregated metrics + telemetryInitializer.accept(builder, metricData.getResource()); builder.setTime(FormattedTime.offSetDateTimeFromEpochNanos(pointData.getEpochNanos())); updateMetricPointBuilder( From 2f8e95f6c3f55bf4009a28ff2db159e6dfaaf4a4 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Tue, 23 Aug 2022 14:53:29 -0700 Subject: [PATCH 71/95] Fix pre-agg metrics were failing to be ingested into mdm --- .../implementation/preaggregatedmetrics/BaseExtractor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/BaseExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/BaseExtractor.java index f8b22428c56..1874032b6ef 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/BaseExtractor.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/BaseExtractor.java @@ -29,7 +29,7 @@ public abstract class BaseExtractor { // visible for testing - public static final String MS_METRIC_ID = "_MS.metricId"; + public static final String MS_METRIC_ID = "_MS.MetricId"; public static final String MS_IS_AUTOCOLLECTED = "_MS.IsAutocollected"; public static final String TRUE = "True"; public static final String FALSE = "False"; From 29459ea1af7fed2a097f40c5abc911b697b4aceb Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Tue, 23 Aug 2022 15:10:56 -0700 Subject: [PATCH 72/95] Fix tests --- .../exporter/implementation/MetricDataMapper.java | 2 -- .../smoketest/HttpPreaggregatedMetricsSmokeTest.java | 4 ++-- .../com/microsoft/applicationinsights/smoketest/GrpcTest.java | 4 ++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index 121232269a1..c273be2b6ab 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -163,8 +163,6 @@ public static void updateMetricPointBuilder( boolean success = getSuccess(statusCode, captureHttpServer4xxAsError); String isSyntheticString = pointData.getAttributes().get(AttributeKey.stringKey("isSynthetic")); - // TODO to be removed - logger.debug("####### isSyntheticString: {}", isSyntheticString); boolean isSynthetic = false; if (isSyntheticString != null) { isSynthetic = Boolean.valueOf(isSyntheticString); diff --git a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java index d3c91f5586f..cc2cc25293a 100644 --- a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java +++ b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java @@ -191,13 +191,13 @@ private static void validateMetricData(String type, MetricData metricData, Strin Map properties = metricData.getProperties(); String expectedResultCode = "200".equals(resultCode) ? "True" : "False"; if ("client".equals(type)) { - assertThat(properties.get("_MS.metricId")).isEqualTo("dependencies/duration"); + assertThat(properties.get("_MS.MetricId")).isEqualTo("dependencies/duration"); assertThat(properties.get("dependency/resultCode")).isEqualTo(resultCode); assertThat(properties.get("dependency/success")).isEqualTo(expectedResultCode); assertThat(properties.get("dependency/target")).isNotNull(); assertThat(properties.get("dependency/type")).isNotNull(); } else { - assertThat(properties.get("_MS.metricId")).isEqualTo("requests/duration"); + assertThat(properties.get("_MS.MetricId")).isEqualTo("requests/duration"); assertThat(properties.get("request/resultCode")).isEqualTo(resultCode); assertThat(properties.get("request/success")).isEqualTo(expectedResultCode); } diff --git a/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java b/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java index 64494e7b16e..489842dea6a 100644 --- a/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java +++ b/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java @@ -211,11 +211,11 @@ private static void validateMetricData(String type, MetricData metricData) { Map properties = metricData.getProperties(); if ("client".equals(type)) { assertThat(properties.get("dependency/resultCode")).isNull(); - assertThat(properties.get("_MS.metricId")).isEqualTo("dependencies/duration"); + assertThat(properties.get("_MS.MetricId")).isEqualTo("dependencies/duration"); assertThat(properties.get("dependency/target")).isNotNull(); assertThat(properties.get("dependency/type")).isEqualTo("grpc"); } else { - assertThat(properties.get("_MS.metricId")).isEqualTo("requests/duration"); + assertThat(properties.get("_MS.MetricId")).isEqualTo("requests/duration"); assertThat(properties.get("request/resultCode")).isNull(); assertThat(properties.get("request/success")).isEqualTo("True"); } From 120fa3ad5867e00816d8a10185db185b1edcda9c Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Tue, 23 Aug 2022 15:11:36 -0700 Subject: [PATCH 73/95] Remove a todo --- .../opentelemetry/exporter/implementation/MetricDataMapper.java | 1 - 1 file changed, 1 deletion(-) diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index c273be2b6ab..1f75a79d493 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -105,7 +105,6 @@ private List convertOtelMetricToAzureMonitorMetric( for (PointData pointData : metricData.getData().getPoints()) { MetricTelemetryBuilder builder = MetricTelemetryBuilder.create(); - // TODO (heya) do not apply custom dimensions to pre-aggregated metrics telemetryInitializer.accept(builder, metricData.getResource()); builder.setTime(FormattedTime.offSetDateTimeFromEpochNanos(pointData.getEpochNanos())); From 8978dec1bafa86f5b9fd7ad1ff318e12131a7970 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Tue, 23 Aug 2022 15:12:09 -0700 Subject: [PATCH 74/95] Remove debug logs --- .../instrumentation/api/instrumenter/UserAgents.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/UserAgents.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/UserAgents.java index 96e0ee4d0d2..ac864c467a6 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/UserAgents.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/UserAgents.java @@ -25,7 +25,6 @@ import io.opentelemetry.api.common.Attributes; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import javax.annotation.Nullable; -import org.slf4j.LoggerFactory; public final class UserAgents { @@ -36,8 +35,6 @@ public final class UserAgents { public static boolean isUserAgentBot(Attributes endAttributes, Attributes startAttributes) { String aiUserAgent = getAttribute(SemanticAttributes.HTTP_USER_AGENT, endAttributes, startAttributes); - // TODO to be removed debug log - LoggerFactory.getLogger(UserAgents.class).debug("############## aiUserAgent: {}", aiUserAgent); return aiUserAgent != null && aiUserAgent.indexOf("AlwaysOn") >= 0; } From 79b0a088ec08d94cf6ec5681cb96231e6f36f0d4 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Tue, 23 Aug 2022 16:23:06 -0700 Subject: [PATCH 75/95] Address comments --- .../BootstrapSemanticAttributes.java | 37 +++++++++++++++++++ .../api/instrumenter/UserAgents.java | 6 +-- .../instrumenter/http/HttpClientMetrics.java | 12 +++--- .../instrumenter/http/HttpServerMetrics.java | 10 ++--- .../api/instrumenter/rpc/MetricsView.java | 8 ++-- .../instrumenter/rpc/RpcClientMetrics.java | 8 ++-- .../instrumenter/rpc/RpcServerMetrics.java | 6 +-- .../implementation/AiSemanticAttributes.java | 7 +++- .../implementation/MetricDataMapper.java | 10 ++--- .../implementation/SpanDataMapper.java | 26 +++++-------- .../preaggregatedmetrics/BaseExtractor.java | 7 ++-- .../DependencyExtractor.java | 2 +- .../RequestExtractor.java | 2 +- .../exporter/PreAggregatedMetricsTest.java | 2 - .../AzureSdkControllerSpansEnabledTest.java | 1 + .../smoketest/AzureSdkTest.java | 5 ++- .../smoketest/ClassicSdkWebInteropTest.java | 2 + .../smoketest/ClassicSdkWebInteropTest.java | 2 + 18 files changed, 90 insertions(+), 63 deletions(-) create mode 100644 agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/BootstrapSemanticAttributes.java diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/BootstrapSemanticAttributes.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/BootstrapSemanticAttributes.java new file mode 100644 index 00000000000..e7ed457ce1c --- /dev/null +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/BootstrapSemanticAttributes.java @@ -0,0 +1,37 @@ +/* + * ApplicationInsights-Java + * Copyright (c) Microsoft Corporation + * All rights reserved. + * + * MIT License + * Permission is hereby granted, free of charge, to any person obtaining a copy of this + * software and associated documentation files (the ""Software""), to deal in the Software + * without restriction, including without limitation the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, and to permit + * persons to whom the Software is furnished to do so, subject to the following conditions: + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR + * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE + * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + +package io.opentelemetry.instrumentation.api.instrumenter; + +import static io.opentelemetry.api.common.AttributeKey.booleanKey; +import static io.opentelemetry.api.common.AttributeKey.stringKey; + +import io.opentelemetry.api.common.AttributeKey; + +public final class BootstrapSemanticAttributes { + + public static final AttributeKey IS_SYNTHETIC = booleanKey("isSynthetic"); + public static final AttributeKey TARGET = stringKey("target"); + public static final AttributeKey IS_PRE_AGGREGATED = + booleanKey("applicationinsights.internal.is_pre_aggregated"); + + private BootstrapSemanticAttributes() {} +} diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/UserAgents.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/UserAgents.java index ac864c467a6..fd942f7358c 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/UserAgents.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/UserAgents.java @@ -28,14 +28,10 @@ public final class UserAgents { - public static final String IS_SYNTHETIC = "isSynthetic"; - public static final String TARGET = "target"; - public static final String IS_PRE_AGGREGATED = "isPreAggregated"; - public static boolean isUserAgentBot(Attributes endAttributes, Attributes startAttributes) { String aiUserAgent = getAttribute(SemanticAttributes.HTTP_USER_AGENT, endAttributes, startAttributes); - return aiUserAgent != null && aiUserAgent.indexOf("AlwaysOn") >= 0; + return aiUserAgent != null && aiUserAgent.contains("AlwaysOn"); } @Nullable diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java index baa29cfcf80..bc9b0ff0979 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java @@ -21,9 +21,9 @@ package io.opentelemetry.instrumentation.api.instrumenter.http; -import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.IS_PRE_AGGREGATED; -import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.IS_SYNTHETIC; -import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.TARGET; +import static io.opentelemetry.instrumentation.api.instrumenter.BootstrapSemanticAttributes.IS_PRE_AGGREGATED; +import static io.opentelemetry.instrumentation.api.instrumenter.BootstrapSemanticAttributes.IS_SYNTHETIC; +import static io.opentelemetry.instrumentation.api.instrumenter.BootstrapSemanticAttributes.TARGET; import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.isUserAgentBot; import static io.opentelemetry.instrumentation.api.instrumenter.http.TemporaryMetricsView.applyClientDurationAndSizeView; import static java.util.logging.Level.FINE; @@ -118,13 +118,11 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { // this is needed for detecting telemetry signals that will trigger pre-aggregated metrics via // auto instrumentations - Span.fromContext(context).setAttribute(IS_PRE_AGGREGATED, "True"); + Span.fromContext(context).setAttribute(IS_PRE_AGGREGATED, true); Attributes durationAttributes = durationAndSizeAttributes.toBuilder() - .put( - IS_SYNTHETIC, - String.valueOf(isUserAgentBot(endAttributes, state.startAttributes()))) + .put(IS_SYNTHETIC, isUserAgentBot(endAttributes, state.startAttributes())) .put(TARGET, getTargetForHttpClientSpan(durationAndSizeAttributes)) .build(); // END APPLICATION INSIGHTS CODE diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java index 11f1d39fd44..f2a8f2aab29 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java @@ -21,8 +21,8 @@ package io.opentelemetry.instrumentation.api.instrumenter.http; -import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.IS_PRE_AGGREGATED; -import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.IS_SYNTHETIC; +import static io.opentelemetry.instrumentation.api.instrumenter.BootstrapSemanticAttributes.IS_PRE_AGGREGATED; +import static io.opentelemetry.instrumentation.api.instrumenter.BootstrapSemanticAttributes.IS_SYNTHETIC; import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.isUserAgentBot; import static java.util.logging.Level.FINE; @@ -129,13 +129,11 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { // this is needed for detecting telemetry signals that will trigger pre-aggregated metrics via // auto instrumentations - Span.fromContext(context).setAttribute(IS_PRE_AGGREGATED, "True"); + Span.fromContext(context).setAttribute(IS_PRE_AGGREGATED, true); Attributes durationAttributes = durationAndSizeAttributes.toBuilder() - .put( - IS_SYNTHETIC, - String.valueOf(isUserAgentBot(endAttributes, state.startAttributes()))) + .put(IS_SYNTHETIC, isUserAgentBot(endAttributes, state.startAttributes())) .build(); // END APPLICATION INSIGHTS CODE diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java index a06dd8c74b2..7a2e800168f 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java @@ -21,8 +21,8 @@ package io.opentelemetry.instrumentation.api.instrumenter.rpc; -import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.IS_SYNTHETIC; -import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.TARGET; +import static io.opentelemetry.instrumentation.api.instrumenter.BootstrapSemanticAttributes.IS_SYNTHETIC; +import static io.opentelemetry.instrumentation.api.instrumenter.BootstrapSemanticAttributes.TARGET; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; @@ -50,8 +50,8 @@ private static Set buildAlwaysInclude() { view.add(SemanticAttributes.RPC_SYSTEM); view.add(SemanticAttributes.RPC_SERVICE); view.add(SemanticAttributes.RPC_METHOD); - view.add(AttributeKey.stringKey(TARGET)); - view.add(AttributeKey.stringKey(IS_SYNTHETIC)); + view.add(TARGET); + view.add(IS_SYNTHETIC); return view; } diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java index 4810b9962dd..690ebac010e 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java @@ -21,9 +21,9 @@ package io.opentelemetry.instrumentation.api.instrumenter.rpc; -import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.IS_PRE_AGGREGATED; -import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.IS_SYNTHETIC; -import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.TARGET; +import static io.opentelemetry.instrumentation.api.instrumenter.BootstrapSemanticAttributes.IS_PRE_AGGREGATED; +import static io.opentelemetry.instrumentation.api.instrumenter.BootstrapSemanticAttributes.IS_SYNTHETIC; +import static io.opentelemetry.instrumentation.api.instrumenter.BootstrapSemanticAttributes.TARGET; import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.isUserAgentBot; import static io.opentelemetry.instrumentation.api.instrumenter.rpc.MetricsView.applyClientView; import static java.util.logging.Level.FINE; @@ -98,7 +98,7 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { // this is needed for detecting telemetry signals that will trigger pre-aggregated metrics via // auto instrumentations - Span.fromContext(context).setAttribute(IS_PRE_AGGREGATED, "True"); + Span.fromContext(context).setAttribute(IS_PRE_AGGREGATED, true); String target = getTargetFromPeerAttributes(endAttributes, 0); if (target == null) { diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java index 971ad4102e7..543339aa6e3 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java @@ -21,8 +21,8 @@ package io.opentelemetry.instrumentation.api.instrumenter.rpc; -import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.IS_PRE_AGGREGATED; -import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.IS_SYNTHETIC; +import static io.opentelemetry.instrumentation.api.instrumenter.BootstrapSemanticAttributes.IS_PRE_AGGREGATED; +import static io.opentelemetry.instrumentation.api.instrumenter.BootstrapSemanticAttributes.IS_SYNTHETIC; import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.isUserAgentBot; import static io.opentelemetry.instrumentation.api.instrumenter.rpc.MetricsView.applyServerView; import static java.util.logging.Level.FINE; @@ -95,7 +95,7 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { // this is needed for detecting telemetry signals that will trigger pre-aggregated metrics via // auto instrumentations - Span.fromContext(context).setAttribute(IS_PRE_AGGREGATED, "True"); + Span.fromContext(context).setAttribute(IS_PRE_AGGREGATED, true); endAttributes = endAttributes.toBuilder() diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/AiSemanticAttributes.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/AiSemanticAttributes.java index 2d31f84dfd8..2a3bf1dbeb8 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/AiSemanticAttributes.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/AiSemanticAttributes.java @@ -21,15 +21,18 @@ package com.azure.monitor.opentelemetry.exporter.implementation; +import static io.opentelemetry.api.common.AttributeKey.longKey; +import static io.opentelemetry.api.common.AttributeKey.stringKey; + import io.opentelemetry.api.common.AttributeKey; public final class AiSemanticAttributes { public static final AttributeKey OPERATION_NAME = - AttributeKey.stringKey("applicationinsights.internal.operation_name"); + stringKey("applicationinsights.internal.operation_name"); public static final AttributeKey ITEM_COUNT = - AttributeKey.longKey("applicationinsights.internal.item_count"); + longKey("applicationinsights.internal.item_count"); private AiSemanticAttributes() {} } diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index 1f75a79d493..f37cb95d6fb 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -49,6 +49,7 @@ import java.util.Set; import java.util.function.BiConsumer; import java.util.function.Consumer; +import jdk.internal.jline.internal.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -100,7 +101,7 @@ public void map(MetricData metricData, Consumer consumer) { } private List convertOtelMetricToAzureMonitorMetric( - MetricData metricData, boolean isPreAggregated) { + MetricData metricData, @Nullable Boolean isPreAggregated) { List telemetryItems = new ArrayList<>(); for (PointData pointData : metricData.getData().getPoints()) { @@ -160,12 +161,7 @@ public static void updateMetricPointBuilder( if (isPreAggregated) { Long statusCode = pointData.getAttributes().get(SemanticAttributes.HTTP_STATUS_CODE); boolean success = getSuccess(statusCode, captureHttpServer4xxAsError); - String isSyntheticString = - pointData.getAttributes().get(AttributeKey.stringKey("isSynthetic")); - boolean isSynthetic = false; - if (isSyntheticString != null) { - isSynthetic = Boolean.valueOf(isSyntheticString); - } + Boolean isSynthetic = pointData.getAttributes().get(AttributeKey.booleanKey("isSynthetic")); if (metricData.getName().contains(".server.")) { RequestExtractor requestExtractor = new RequestExtractor(metricTelemetryBuilder, statusCode, success, isSynthetic); diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java index 5cc754af2af..7a65308c13b 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java @@ -180,12 +180,10 @@ public void map(SpanData span, Consumer consumer) { } public TelemetryItem map(SpanData span, long itemCount) { - boolean isPreAggregated = checkIsPreAggregated(span); if (isRequest(span)) { - return exportRequest(span, itemCount, isPreAggregated); + return exportRequest(span, itemCount); } else { - return exportRemoteDependency( - span, span.getKind() == SpanKind.INTERNAL, itemCount, isPreAggregated); + return exportRemoteDependency(span, span.getKind() == SpanKind.INTERNAL, itemCount); } } @@ -230,12 +228,13 @@ private static boolean isRequest( } private static boolean checkIsPreAggregated(SpanData span) { - String isPreAggregated = span.getAttributes().get(AttributeKey.stringKey("isPreAggregated")); - return isPreAggregated != null && Boolean.valueOf(isPreAggregated); + Boolean isPreAggregated = + span.getAttributes() + .get(AttributeKey.booleanKey("applicationinsights.internal.is_pre_aggregated")); + return isPreAggregated != null && isPreAggregated; } - private TelemetryItem exportRemoteDependency( - SpanData span, boolean inProc, long itemCount, boolean isPreAggregated) { + private TelemetryItem exportRemoteDependency(SpanData span, boolean inProc, long itemCount) { RemoteDependencyTelemetryBuilder telemetryBuilder = RemoteDependencyTelemetryBuilder.create(); telemetryInitializer.accept(telemetryBuilder, span.getResource()); @@ -262,7 +261,7 @@ private TelemetryItem exportRemoteDependency( applySemanticConventions(telemetryBuilder, span); } - if (isPreAggregated) { + if (checkIsPreAggregated(span)) { telemetryBuilder.addProperty(MS_PROCESSED_BY_METRIC_EXTRACTORS, "True"); } @@ -527,8 +526,6 @@ private static void applyRpcClientSpan( target = rpcSystem; } telemetryBuilder.setTarget(target); - // RPC client/server metrics only has duration - telemetryBuilder.addProperty(MS_PROCESSED_BY_METRIC_EXTRACTORS, "True"); } private static void applyDatabaseClientSpan( @@ -608,7 +605,7 @@ private static int getDefaultPortForDbSystem(String dbSystem) { } } - private TelemetryItem exportRequest(SpanData span, long itemCount, boolean isPreAggregated) { + private TelemetryItem exportRequest(SpanData span, long itemCount) { RequestTelemetryBuilder telemetryBuilder = RequestTelemetryBuilder.create(); telemetryInitializer.accept(telemetryBuilder, span.getResource()); @@ -695,7 +692,7 @@ private TelemetryItem exportRequest(SpanData span, long itemCount, boolean isPre telemetryBuilder.addTag(ContextTagKeys.AI_DEVICE_OS_VERSION.toString(), deviceOsVersion); } - if (isPreAggregated) { + if (checkIsPreAggregated(span)) { telemetryBuilder.addProperty(MS_PROCESSED_BY_METRIC_EXTRACTORS, "True"); } @@ -973,9 +970,6 @@ private static void setExtraAttributes( && !stringKey.startsWith("http.response.header.")) { return; } - if (stringKey.equals("isPreAggregated")) { - return; - } String val = convertToString(value, key.getType()); if (value != null) { telemetryBuilder.addProperty(key.getKey(), val); diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/BaseExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/BaseExtractor.java index 1874032b6ef..1b2707d55ee 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/BaseExtractor.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/BaseExtractor.java @@ -39,12 +39,12 @@ public abstract class BaseExtractor { protected final AbstractTelemetryBuilder telemetryBuilder; - public BaseExtractor(MetricTelemetryBuilder telemetryBuilder, boolean isSynthetic) { + public BaseExtractor(MetricTelemetryBuilder telemetryBuilder, Boolean isSynthetic) { this.telemetryBuilder = telemetryBuilder; extractCommon(isSynthetic); } - private void extractCommon(boolean isSynthetic) { + private void extractCommon(Boolean isSynthetic) { telemetryBuilder.addProperty(MS_IS_AUTOCOLLECTED, TRUE); Map tags = telemetryBuilder.build().getTags(); if (tags != null) { @@ -59,7 +59,8 @@ private void extractCommon(boolean isSynthetic) { } } - telemetryBuilder.addProperty(OPERATION_SYNTHETIC, isSynthetic ? TRUE : FALSE); + telemetryBuilder.addProperty( + OPERATION_SYNTHETIC, isSynthetic != null && isSynthetic ? TRUE : FALSE); } public abstract void extract(); diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java index d2f3b8f6619..dc6ed06636a 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java @@ -43,7 +43,7 @@ public DependencyExtractor( boolean success, String type, String target, - boolean isSynthetic) { + Boolean isSynthetic) { super(telemetryBuilder, isSynthetic); this.statusCode = statusCode; this.success = success; diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java index 6457d90fcc3..a145d2bedcb 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java @@ -36,7 +36,7 @@ public RequestExtractor( MetricTelemetryBuilder telemetryBuilder, Long statusCode, boolean success, - boolean isSynthetic) { + Boolean isSynthetic) { super(telemetryBuilder, isSynthetic); this.statusCode = statusCode; this.success = success; diff --git a/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java index 1d899f4d737..f1356724491 100644 --- a/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java +++ b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java @@ -322,8 +322,6 @@ private static Map generateExpectedDependencyCustomDimensions(St Map expectedMap = new HashMap<>(); expectedMap.put(MS_METRIC_ID, DEPENDENCIES_DURATION); expectedMap.put(MS_IS_AUTOCOLLECTED, TRUE); - // TODO performance market is updated in HttpClientMetrics - // expectedMap.put(PERFORMANCE_BUCKET, "<250ms"); expectedMap.put(OPERATION_SYNTHETIC, FALSE); expectedMap.put(DEPENDENCY_SUCCESS, TRUE); if ("http".equals(type)) { diff --git a/smoke-tests/apps/AzureSdk/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/AzureSdkControllerSpansEnabledTest.java b/smoke-tests/apps/AzureSdk/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/AzureSdkControllerSpansEnabledTest.java index 84ad4044758..a99c40e8416 100644 --- a/smoke-tests/apps/AzureSdk/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/AzureSdkControllerSpansEnabledTest.java +++ b/smoke-tests/apps/AzureSdk/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/AzureSdkControllerSpansEnabledTest.java @@ -55,6 +55,7 @@ void test() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); + assertThat(telemetry.rd.getProperties()).hasSize(1); assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) .isEqualTo("True"); assertThat(telemetry.rd.getMeasurements()).isEmpty(); diff --git a/smoke-tests/apps/AzureSdk/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/AzureSdkTest.java b/smoke-tests/apps/AzureSdk/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/AzureSdkTest.java index e090d25359a..75f453d72a8 100644 --- a/smoke-tests/apps/AzureSdk/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/AzureSdkTest.java +++ b/smoke-tests/apps/AzureSdk/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/AzureSdkTest.java @@ -31,6 +31,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8; import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -50,8 +51,8 @@ void test() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getMeasurements()).isEmpty(); assertThat(telemetry.rdd1.getName()).isEqualTo("hello"); diff --git a/smoke-tests/apps/ClassicSdkWebInterop2x/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/ClassicSdkWebInteropTest.java b/smoke-tests/apps/ClassicSdkWebInterop2x/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/ClassicSdkWebInteropTest.java index 6a6ac9fa5a5..9a5a15041c8 100644 --- a/smoke-tests/apps/ClassicSdkWebInterop2x/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/ClassicSdkWebInteropTest.java +++ b/smoke-tests/apps/ClassicSdkWebInterop2x/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/ClassicSdkWebInteropTest.java @@ -55,6 +55,8 @@ void doMostBasicTest() throws Exception { assertThat(telemetry.rd.getProperties()).containsEntry("myattr1", "myvalue1"); assertThat(telemetry.rd.getProperties()).containsEntry("myattr2", "myvalue2"); assertThat(telemetry.rd.getProperties()).hasSize(3); + assertThat(telemetry.rd.getProperties()) + .containsEntry("_MS.ProcessedByMetricExtractors", "True"); assertThat(telemetry.rd.getSuccess()).isFalse(); } diff --git a/smoke-tests/apps/ClassicSdkWebInterop3x/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/ClassicSdkWebInteropTest.java b/smoke-tests/apps/ClassicSdkWebInterop3x/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/ClassicSdkWebInteropTest.java index 6a6ac9fa5a5..9a5a15041c8 100644 --- a/smoke-tests/apps/ClassicSdkWebInterop3x/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/ClassicSdkWebInteropTest.java +++ b/smoke-tests/apps/ClassicSdkWebInterop3x/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/ClassicSdkWebInteropTest.java @@ -55,6 +55,8 @@ void doMostBasicTest() throws Exception { assertThat(telemetry.rd.getProperties()).containsEntry("myattr1", "myvalue1"); assertThat(telemetry.rd.getProperties()).containsEntry("myattr2", "myvalue2"); assertThat(telemetry.rd.getProperties()).hasSize(3); + assertThat(telemetry.rd.getProperties()) + .containsEntry("_MS.ProcessedByMetricExtractors", "True"); assertThat(telemetry.rd.getSuccess()).isFalse(); } From ab331d7261f05d801832b34d4b10dd5840b317da Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Tue, 23 Aug 2022 16:28:14 -0700 Subject: [PATCH 76/95] Add appinsights code comment --- .../instrumentation/api/instrumenter/rpc/MetricsView.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java index 7a2e800168f..5c44822d67f 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java @@ -50,9 +50,12 @@ private static Set buildAlwaysInclude() { view.add(SemanticAttributes.RPC_SYSTEM); view.add(SemanticAttributes.RPC_SERVICE); view.add(SemanticAttributes.RPC_METHOD); + + // START APPLICATION INSIGHTS CODE view.add(TARGET); view.add(IS_SYNTHETIC); return view; + // END APPLICATION INSIGHTS CODE } private static Set buildClientView() { From 8ab315437d2728b2def83c7bfffc55a9c1b4fd9d Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Tue, 23 Aug 2022 16:31:17 -0700 Subject: [PATCH 77/95] Exclude return statement --- .../instrumentation/api/instrumenter/rpc/MetricsView.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java index 5c44822d67f..8b49d66b9e8 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java @@ -54,8 +54,9 @@ private static Set buildAlwaysInclude() { // START APPLICATION INSIGHTS CODE view.add(TARGET); view.add(IS_SYNTHETIC); - return view; // END APPLICATION INSIGHTS CODE + + return view; } private static Set buildClientView() { From e216ed428fd6bc659ac9a839215ec0757e569bf5 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Tue, 23 Aug 2022 16:53:30 -0700 Subject: [PATCH 78/95] Use containsExactly --- .../AzureSdkControllerSpansEnabledTest.java | 6 +-- .../smoketest/CassandraTest.java | 5 +- .../smoketest/CustomInstrumentationTest.java | 4 +- .../smoketest/HttpClientSmokeTest.java | 17 +++--- .../smoketest/HttpHeadersTest.java | 5 +- .../HttpPreaggregatedMetricsSmokeTest.java | 17 +++--- .../smoketest/HttpServer4xxDefaultTest.java | 5 +- .../smoketest/HttpServer4xxTest.java | 5 +- .../smoketest/JmsDisabledTest.java | 7 ++- .../smoketest/JmsTest.java | 7 ++- .../smoketest/JdbcTest.java | 53 ++++++++++--------- .../smoketest/JedisTest.java | 5 +- .../smoketest/JettyNativeHandlerTest.java | 5 +- .../KafkaControllerSpansEnabledTest.java | 7 ++- .../smoketest/KafkaDisabledTest.java | 7 ++- .../smoketest/KafkaTest.java | 7 ++- .../smoketest/LettuceTest.java | 5 +- .../smoketest/MicrometerTest.java | 4 +- .../smoketest/MongoTest.java | 5 +- .../smoketest/NonDaemonThreadsTest.java | 7 ++- ...yApiSupportControllerSpansEnabledTest.java | 13 ++--- .../OpenTelemetryApiSupportTest.java | 17 +++--- .../smoketest/SpringBootAttachInMainTest.java | 5 +- .../smoketest/SpringBootAutoTest.java | 5 +- .../SpringBootControllerSpansEnabledTest.java | 10 ++-- .../smoketest/SpringBootTest.java | 10 ++-- ...CloudStreamControllerSpansEnabledTest.java | 4 +- .../smoketest/SpringCloudStreamTest.java | 4 +- .../smoketest/SpringBootAutoTest.java | 5 +- .../smoketest/WebFluxTest.java | 13 ++--- .../smoketest/GrpcTest.java | 13 +++-- 31 files changed, 168 insertions(+), 114 deletions(-) diff --git a/smoke-tests/apps/AzureSdk/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/AzureSdkControllerSpansEnabledTest.java b/smoke-tests/apps/AzureSdk/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/AzureSdkControllerSpansEnabledTest.java index a99c40e8416..557cf654fbd 100644 --- a/smoke-tests/apps/AzureSdk/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/AzureSdkControllerSpansEnabledTest.java +++ b/smoke-tests/apps/AzureSdk/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/AzureSdkControllerSpansEnabledTest.java @@ -23,6 +23,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.TOMCAT_8_JAVA_8; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import com.microsoft.applicationinsights.smoketest.schemav2.Envelope; import com.microsoft.applicationinsights.smoketest.schemav2.RemoteDependencyData; @@ -55,9 +56,8 @@ void test() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties()).hasSize(1); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getMeasurements()).isEmpty(); assertThat(telemetry.rdd1.getName()).isEqualTo("TestController.test"); diff --git a/smoke-tests/apps/Cassandra/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CassandraTest.java b/smoke-tests/apps/Cassandra/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CassandraTest.java index 9c42bd83a20..8e47ca740a5 100644 --- a/smoke-tests/apps/Cassandra/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CassandraTest.java +++ b/smoke-tests/apps/Cassandra/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CassandraTest.java @@ -31,6 +31,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8; import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -55,8 +56,8 @@ void cassandra() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getMeasurements()).isEmpty(); assertThat(telemetry.rdd1.getName()).isEqualTo("SELECT test.test"); diff --git a/smoke-tests/apps/CustomInstrumentation/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CustomInstrumentationTest.java b/smoke-tests/apps/CustomInstrumentation/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CustomInstrumentationTest.java index e13e30b03dd..a3aa81eee06 100644 --- a/smoke-tests/apps/CustomInstrumentation/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CustomInstrumentationTest.java +++ b/smoke-tests/apps/CustomInstrumentation/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CustomInstrumentationTest.java @@ -31,6 +31,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.JAVA_8; import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.JAVA_8_OPENJ9; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import com.microsoft.applicationinsights.smoketest.schemav2.Data; import com.microsoft.applicationinsights.smoketest.schemav2.Envelope; @@ -69,7 +70,8 @@ void test() throws Exception { assertThat(rd1.getName()).isEqualTo("GET /test"); assertThat(rd1.getResponseCode()).isEqualTo("200"); - assertThat(rd1.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(rd1.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(rd1.getSuccess()).isTrue(); assertThat(rd2.getName()).isEqualTo("TestController.run"); diff --git a/smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpClientSmokeTest.java b/smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpClientSmokeTest.java index e9e5eadea4d..4c7c2d0bbb4 100644 --- a/smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpClientSmokeTest.java +++ b/smoke-tests/apps/HttpClients/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpClientSmokeTest.java @@ -31,6 +31,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8; import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -96,8 +97,8 @@ private static void verify() throws Exception { private static void verify(String successUrlWithQueryString) throws Exception { Telemetry telemetry = testing.getTelemetry(3); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getSuccess()).isTrue(); // TODO (trask) add this check in all smoke tests? assertThat(telemetry.rdEnvelope.getSampleRate()).isNull(); @@ -107,8 +108,8 @@ private static void verify(String successUrlWithQueryString) throws Exception { assertThat(telemetry.rdd1.getType()).isEqualTo("Http"); assertThat(telemetry.rdd1.getTarget()).isEqualTo("mock.codes"); assertThat(telemetry.rdd1.getResultCode()).isEqualTo("200"); - assertThat(telemetry.rdd1.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rdd1.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rdd1.getSuccess()).isTrue(); assertThat(telemetry.rddEnvelope1.getSampleRate()).isNull(); @@ -117,8 +118,8 @@ private static void verify(String successUrlWithQueryString) throws Exception { assertThat(telemetry.rdd2.getType()).isEqualTo("Http"); assertThat(telemetry.rdd2.getTarget()).isEqualTo("mock.codes"); assertThat(telemetry.rdd2.getResultCode()).isEqualTo("404"); - assertThat(telemetry.rdd2.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rdd2.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rdd2.getSuccess()).isFalse(); assertThat(telemetry.rddEnvelope2.getSampleRate()).isNull(); @@ -127,8 +128,8 @@ private static void verify(String successUrlWithQueryString) throws Exception { assertThat(telemetry.rdd3.getType()).isEqualTo("Http"); assertThat(telemetry.rdd3.getTarget()).isEqualTo("mock.codes"); assertThat(telemetry.rdd3.getResultCode()).isEqualTo("500"); - assertThat(telemetry.rdd3.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rdd3.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rdd3.getSuccess()).isFalse(); assertThat(telemetry.rddEnvelope3.getSampleRate()).isNull(); diff --git a/smoke-tests/apps/HttpHeaders/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpHeadersTest.java b/smoke-tests/apps/HttpHeaders/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpHeadersTest.java index 809b267fd4d..5611784c796 100644 --- a/smoke-tests/apps/HttpHeaders/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpHeadersTest.java +++ b/smoke-tests/apps/HttpHeaders/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpHeadersTest.java @@ -31,6 +31,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8; import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -60,8 +61,8 @@ void testClientHeaders() throws Exception { assertThat(telemetry.rd.getProperties()).containsKey("http.request.header.host"); assertThat(telemetry.rd.getProperties()).hasSize(2); assertThat(telemetry.rd.getSuccess()).isTrue(); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rdd1.getProperties().get("http.request.header.abc")) .isEqualTo("testing123"); assertThat(telemetry.rdd1.getProperties()).containsKey("http.response.header.date"); diff --git a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java index cc2cc25293a..06910259ab3 100644 --- a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java +++ b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java @@ -31,6 +31,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8; import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import com.microsoft.applicationinsights.smoketest.schemav2.Data; import com.microsoft.applicationinsights.smoketest.schemav2.DataPoint; @@ -76,8 +77,8 @@ private static void verifyHttpclientRequestsAndDependencies(String successUrlWit throws Exception { Telemetry telemetry = testing.getTelemetry(3); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rdd1.getData()).isEqualTo(successUrlWithQueryString); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rdEnvelope.getSampleRate()).isNull(); @@ -85,8 +86,8 @@ private static void verifyHttpclientRequestsAndDependencies(String successUrlWit assertThat(telemetry.rdd1.getType()).isEqualTo("Http"); assertThat(telemetry.rdd1.getTarget()).isEqualTo("mock.codes"); assertThat(telemetry.rdd1.getResultCode()).isEqualTo("200"); - assertThat(telemetry.rdd1.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rdd1.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rdd1.getSuccess()).isTrue(); assertThat(telemetry.rddEnvelope1.getSampleRate()).isNull(); @@ -95,8 +96,8 @@ private static void verifyHttpclientRequestsAndDependencies(String successUrlWit assertThat(telemetry.rdd2.getType()).isEqualTo("Http"); assertThat(telemetry.rdd2.getTarget()).isEqualTo("mock.codes"); assertThat(telemetry.rdd2.getResultCode()).isEqualTo("404"); - assertThat(telemetry.rdd1.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rdd2.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rdd2.getSuccess()).isFalse(); assertThat(telemetry.rddEnvelope2.getSampleRate()).isNull(); @@ -105,8 +106,8 @@ private static void verifyHttpclientRequestsAndDependencies(String successUrlWit assertThat(telemetry.rdd3.getType()).isEqualTo("Http"); assertThat(telemetry.rdd3.getTarget()).isEqualTo("mock.codes"); assertThat(telemetry.rdd3.getResultCode()).isEqualTo("500"); - assertThat(telemetry.rdd1.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rdd3.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rdd3.getSuccess()).isFalse(); assertThat(telemetry.rddEnvelope3.getSampleRate()).isNull(); diff --git a/smoke-tests/apps/HttpServer4xx/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpServer4xxDefaultTest.java b/smoke-tests/apps/HttpServer4xx/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpServer4xxDefaultTest.java index 0f84abcaf9c..ba650cd5abd 100644 --- a/smoke-tests/apps/HttpServer4xx/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpServer4xxDefaultTest.java +++ b/smoke-tests/apps/HttpServer4xx/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpServer4xxDefaultTest.java @@ -31,6 +31,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8; import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -50,8 +51,8 @@ void doMostBasicTest() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("400"); assertThat(telemetry.rd.getSuccess()).isFalse(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getMeasurements()).isEmpty(); } diff --git a/smoke-tests/apps/HttpServer4xx/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpServer4xxTest.java b/smoke-tests/apps/HttpServer4xx/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpServer4xxTest.java index bba014cdca8..5626416e700 100644 --- a/smoke-tests/apps/HttpServer4xx/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpServer4xxTest.java +++ b/smoke-tests/apps/HttpServer4xx/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpServer4xxTest.java @@ -31,6 +31,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8; import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -50,8 +51,8 @@ void doMostBasicTest() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("400"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getMeasurements()).isEmpty(); } diff --git a/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsDisabledTest.java b/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsDisabledTest.java index 65abffd2791..3533bec1152 100644 --- a/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsDisabledTest.java +++ b/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsDisabledTest.java @@ -23,6 +23,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.JAVA_8; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import com.microsoft.applicationinsights.smoketest.schemav2.Data; import com.microsoft.applicationinsights.smoketest.schemav2.Envelope; @@ -50,7 +51,8 @@ void doMostBasicTest() throws Exception { assertThat(rd.getName()).isEqualTo("GET /sendMessage"); assertThat(rd.getResponseCode()).isEqualTo("200"); - assertThat(rd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(rd.getSuccess()).isTrue(); // verify the downstream http dependency that is no longer part of the same trace @@ -65,7 +67,8 @@ void doMostBasicTest() throws Exception { assertThat(rdd.getName()).isEqualTo("GET /"); assertThat(rdd.getData()).isEqualTo("https://www.bing.com"); - assertThat(rdd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(rdd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(rdd.getSuccess()).isTrue(); // sleep a bit and make sure no kafka "requests" or dependencies are reported diff --git a/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsTest.java b/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsTest.java index b0482717ce1..103e4989574 100644 --- a/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsTest.java +++ b/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsTest.java @@ -31,6 +31,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.JAVA_8; import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.JAVA_8_OPENJ9; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import com.microsoft.applicationinsights.smoketest.schemav2.Data; import com.microsoft.applicationinsights.smoketest.schemav2.Envelope; @@ -74,7 +75,8 @@ void doMostBasicTest() throws Exception { (RemoteDependencyData) ((Data) rddEnvelope2.getData()).getBaseData(); assertThat(rd1.getName()).isEqualTo("GET /sendMessage"); - assertThat(rd1.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(rd1.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(rd1.getSuccess()).isTrue(); assertThat(rdd1.getName()).isEqualTo("message send"); @@ -93,7 +95,8 @@ void doMostBasicTest() throws Exception { assertThat(rdd2.getData()).isEqualTo("https://www.bing.com"); assertThat(rdd2.getType()).isEqualTo("Http"); assertThat(rdd2.getTarget()).isEqualTo("www.bing.com"); - assertThat(rdd2.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(rdd2.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(rdd2.getSuccess()).isTrue(); SmokeTestExtension.assertParentChild(rd1, rdEnvelope1, rddEnvelope1, "GET /sendMessage"); diff --git a/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java b/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java index f8c7d54f85f..a092f79fd68 100644 --- a/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java +++ b/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcTest.java @@ -31,6 +31,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8; import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -62,8 +63,8 @@ abstract class JdbcTest { void hsqldbPreparedStatement() throws Exception { Telemetry telemetry = testing.getTelemetry(1); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rdd1.getName()).isEqualTo("SELECT testdb.abc"); @@ -82,8 +83,8 @@ void hsqldbPreparedStatement() throws Exception { void hsqldbStatement() throws Exception { Telemetry telemetry = testing.getTelemetry(1); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rdd1.getName()).isEqualTo("SELECT testdb.abc"); @@ -102,8 +103,8 @@ void hsqldbStatement() throws Exception { void hsqldbLargeStatement() throws Exception { Telemetry telemetry = testing.getTelemetry(1); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getSuccess()).isTrue(); StringBuilder a2000 = new StringBuilder(); @@ -130,8 +131,8 @@ void hsqldbLargeStatement() throws Exception { void hsqldbBatchPreparedStatement() throws Exception { Telemetry telemetry = testing.getTelemetry(1); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rdd1.getName()).isEqualTo("INSERT testdb.abc"); @@ -152,8 +153,8 @@ void hsqldbBatchPreparedStatement() throws Exception { void hsqldbBatchStatement() throws Exception { Telemetry telemetry = testing.getTelemetry(1); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rdd1.getName()).isEqualTo("insert testdb.abc"); @@ -178,8 +179,8 @@ void mysqlPreparedStatement() throws Exception { Telemetry telemetry = testing.getTelemetry(1, rdd -> !rdd.getData().startsWith("/* mysql-connector-java? ")); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rdd1.getName()).isEqualTo("SELECT mysql.abc"); @@ -201,8 +202,8 @@ void mysqlStatement() throws Exception { Telemetry telemetry = testing.getTelemetry(1, rdd -> !rdd.getData().startsWith("/* mysql-connector-java? ")); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rdd1.getName()).isEqualTo("SELECT mysql.abc"); @@ -222,8 +223,8 @@ void mysqlStatement() throws Exception { void postgresPreparedStatement() throws Exception { Telemetry telemetry = testing.getTelemetry(1); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rdd1.getName()).isEqualTo("SELECT postgres.abc"); @@ -243,8 +244,8 @@ void postgresPreparedStatement() throws Exception { void postgresStatement() throws Exception { Telemetry telemetry = testing.getTelemetry(1); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rdd1.getName()).isEqualTo("SELECT postgres.abc"); @@ -264,8 +265,8 @@ void postgresStatement() throws Exception { void sqlServerPreparedStatement() throws Exception { Telemetry telemetry = testing.getTelemetry(1); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rdd1.getName()).isEqualTo("SELECT abc"); @@ -284,8 +285,8 @@ void sqlServerPreparedStatement() throws Exception { void sqlServerStatement() throws Exception { Telemetry telemetry = testing.getTelemetry(1); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rdd1.getName()).isEqualTo("SELECT abc"); @@ -305,8 +306,8 @@ void sqlServerStatement() throws Exception { void oraclePreparedStatement() throws Exception { Telemetry telemetry = testing.getTelemetry(1); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rdd1.getName()).isEqualTo("SELECT abc"); @@ -326,8 +327,8 @@ void oraclePreparedStatement() throws Exception { void oracleStatement() throws Exception { Telemetry telemetry = testing.getTelemetry(1); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rdd1.getName()).isEqualTo("SELECT abc"); diff --git a/smoke-tests/apps/Jedis/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JedisTest.java b/smoke-tests/apps/Jedis/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JedisTest.java index 532ca2abd79..e4c5842aa28 100644 --- a/smoke-tests/apps/Jedis/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JedisTest.java +++ b/smoke-tests/apps/Jedis/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JedisTest.java @@ -31,6 +31,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8; import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -55,8 +56,8 @@ void jedis() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getMeasurements()).isEmpty(); assertThat(telemetry.rdd1.getName()).isEqualTo("GET"); diff --git a/smoke-tests/apps/JettyNativeHandler/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JettyNativeHandlerTest.java b/smoke-tests/apps/JettyNativeHandler/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JettyNativeHandlerTest.java index d6b0a441f8f..38efee740c1 100644 --- a/smoke-tests/apps/JettyNativeHandler/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JettyNativeHandlerTest.java +++ b/smoke-tests/apps/JettyNativeHandler/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JettyNativeHandlerTest.java @@ -31,6 +31,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.JAVA_8; import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.JAVA_8_OPENJ9; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -50,8 +51,8 @@ void doSimpleTest() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getMeasurements()).isEmpty(); } diff --git a/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaControllerSpansEnabledTest.java b/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaControllerSpansEnabledTest.java index b6418e5fb36..2176f2f77bc 100644 --- a/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaControllerSpansEnabledTest.java +++ b/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaControllerSpansEnabledTest.java @@ -23,6 +23,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.JAVA_8; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import com.microsoft.applicationinsights.smoketest.schemav2.Data; import com.microsoft.applicationinsights.smoketest.schemav2.Envelope; @@ -87,7 +88,8 @@ void doMostBasicTest() throws Exception { (RemoteDependencyData) ((Data) rddEnvelope3.getData()).getBaseData(); assertThat(rd1.getName()).isEqualTo("GET /sendMessage"); - assertThat(rd1.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(rd1.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(rd1.getSuccess()).isTrue(); assertThat(rdd1.getName()).isEqualTo("HelloController.sendMessage"); @@ -114,7 +116,8 @@ void doMostBasicTest() throws Exception { assertThat(rdd3.getData()).isEqualTo("https://www.bing.com"); assertThat(rdd3.getType()).isEqualTo("Http"); assertThat(rdd3.getTarget()).isEqualTo("www.bing.com"); - assertThat(rdd3.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(rdd3.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(rdd3.getSuccess()).isTrue(); SmokeTestExtension.assertParentChild(rd1, rdEnvelope1, rddEnvelope1, "GET /sendMessage"); diff --git a/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaDisabledTest.java b/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaDisabledTest.java index 901244f163e..e2479b8a004 100644 --- a/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaDisabledTest.java +++ b/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaDisabledTest.java @@ -23,6 +23,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.JAVA_8; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import com.microsoft.applicationinsights.smoketest.schemav2.Data; import com.microsoft.applicationinsights.smoketest.schemav2.Envelope; @@ -66,7 +67,8 @@ void doMostBasicTest() throws Exception { assertThat(rd.getName()).isEqualTo("GET /sendMessage"); assertThat(rd.getResponseCode()).isEqualTo("200"); - assertThat(rd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(rd.getSuccess()).isTrue(); // verify the downstream http dependency that is no longer part of the same trace @@ -81,7 +83,8 @@ void doMostBasicTest() throws Exception { assertThat(rdd.getName()).isEqualTo("GET /"); assertThat(rdd.getData()).isEqualTo("https://www.bing.com"); - assertThat(rdd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(rdd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(rdd.getSuccess()).isTrue(); // sleep a bit and make sure no kafka "requests" or dependencies are reported diff --git a/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaTest.java b/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaTest.java index 45f2ca861a7..d9deb104ccf 100644 --- a/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaTest.java +++ b/smoke-tests/apps/Kafka/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/KafkaTest.java @@ -31,6 +31,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.JAVA_8; import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.JAVA_8_OPENJ9; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import com.microsoft.applicationinsights.smoketest.schemav2.Data; import com.microsoft.applicationinsights.smoketest.schemav2.Envelope; @@ -90,7 +91,8 @@ void doMostBasicTest() throws Exception { (RemoteDependencyData) ((Data) rddEnvelope2.getData()).getBaseData(); assertThat(rd1.getName()).isEqualTo("GET /sendMessage"); - assertThat(rd1.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(rd1.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(rd1.getSuccess()).isTrue(); assertThat(rdd1.getName()).isEqualTo("mytopic send"); @@ -109,7 +111,8 @@ void doMostBasicTest() throws Exception { assertThat(rdd2.getData()).isEqualTo("https://www.bing.com"); assertThat(rdd2.getType()).isEqualTo("Http"); assertThat(rdd2.getTarget()).isEqualTo("www.bing.com"); - assertThat(rdd2.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(rdd2.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(rdd2.getSuccess()).isTrue(); SmokeTestExtension.assertParentChild(rd1, rdEnvelope1, rddEnvelope1, "GET /sendMessage"); diff --git a/smoke-tests/apps/Lettuce/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/LettuceTest.java b/smoke-tests/apps/Lettuce/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/LettuceTest.java index 01a6c045d79..4f15df4aa01 100644 --- a/smoke-tests/apps/Lettuce/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/LettuceTest.java +++ b/smoke-tests/apps/Lettuce/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/LettuceTest.java @@ -31,6 +31,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8; import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -55,8 +56,8 @@ void lettuce() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getMeasurements()).isEmpty(); assertThat(telemetry.rdd1.getName()).isEqualTo("GET"); diff --git a/smoke-tests/apps/Micrometer/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/MicrometerTest.java b/smoke-tests/apps/Micrometer/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/MicrometerTest.java index 757e9cdab9a..6fb24ec4a7d 100644 --- a/smoke-tests/apps/Micrometer/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/MicrometerTest.java +++ b/smoke-tests/apps/Micrometer/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/MicrometerTest.java @@ -56,8 +56,8 @@ void doMostBasicTest() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getMeasurements()).isEmpty(); List metricItems = diff --git a/smoke-tests/apps/MongoDB/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/MongoTest.java b/smoke-tests/apps/MongoDB/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/MongoTest.java index cd3ab9db7ba..791e7fe63a6 100644 --- a/smoke-tests/apps/MongoDB/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/MongoTest.java +++ b/smoke-tests/apps/MongoDB/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/MongoTest.java @@ -31,6 +31,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8; import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -55,8 +56,8 @@ void mongo() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getMeasurements()).isEmpty(); assertThat(telemetry.rdd1.getName()).isEqualTo("find testdb.test"); diff --git a/smoke-tests/apps/NonDaemonThreads/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/NonDaemonThreadsTest.java b/smoke-tests/apps/NonDaemonThreads/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/NonDaemonThreadsTest.java index 8d3614f8d27..20c4cc5db81 100644 --- a/smoke-tests/apps/NonDaemonThreads/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/NonDaemonThreadsTest.java +++ b/smoke-tests/apps/NonDaemonThreads/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/NonDaemonThreadsTest.java @@ -31,6 +31,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.JAVA_8; import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.JAVA_8_OPENJ9; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import com.microsoft.applicationinsights.smoketest.schemav2.Data; import com.microsoft.applicationinsights.smoketest.schemav2.Envelope; @@ -68,14 +69,16 @@ void spawnAnotherJavaProcess() throws Exception { (RemoteDependencyData) ((Data) rddEnvelope.getData()).getBaseData(); MessageData md = (MessageData) ((Data) mdEnvelope.getData()).getBaseData(); - assertThat(rd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(rd.getSuccess()).isTrue(); assertThat(rdd.getName()).isEqualTo("GET /search"); assertThat(rdd.getType()).isEqualTo("Http"); assertThat(rdd.getTarget()).isEqualTo("www.bing.com"); assertThat(rdd.getData()).isEqualTo("https://www.bing.com/search?q=test"); - assertThat(rdd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(rdd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(rdd.getSuccess()).isTrue(); assertThat(md.getMessage()).isEqualTo("done"); diff --git a/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportControllerSpansEnabledTest.java b/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportControllerSpansEnabledTest.java index fbadd8eaac6..7a1370b2de8 100644 --- a/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportControllerSpansEnabledTest.java +++ b/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportControllerSpansEnabledTest.java @@ -23,6 +23,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.TOMCAT_8_JAVA_8; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import com.microsoft.applicationinsights.smoketest.schemav2.Envelope; import com.microsoft.applicationinsights.smoketest.schemav2.RemoteDependencyData; @@ -46,8 +47,8 @@ void testApi() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getMeasurements()).isEmpty(); assertThat(telemetry.rdd1.getName()).isEqualTo("myspanname"); @@ -92,8 +93,8 @@ void testOverridingIkeyEtc() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getMeasurements()).isEmpty(); assertThat(telemetry.rdd1.getName()).isEqualTo("TestController.testOverridingIkeyEtc"); @@ -160,8 +161,8 @@ private static void testAnnotations( assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getMeasurements()).isEmpty(); assertThat(telemetry.rdd1.getName()).isEqualTo("TestController." + controllerMethodName); diff --git a/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java b/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java index 8f5690299cd..4e0c2c4c086 100644 --- a/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java +++ b/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java @@ -31,6 +31,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8; import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -54,8 +55,8 @@ void testApi() throws Exception { assertThat(telemetry.rd.getProperties()).hasSize(3); assertThat(telemetry.rd.getProperties()).containsEntry("myattr1", "myvalue1"); assertThat(telemetry.rd.getProperties()).containsEntry("myattr2", "myvalue2"); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); // ideally want the properties below on rd, but can't get SERVER span yet // see @@ -84,10 +85,10 @@ void testOverridingIkeyEtc() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getMeasurements()).isEmpty(); // checking that instrumentation key, cloud role name, cloud role instance, and sdk version are @@ -123,8 +124,8 @@ private static void testAnnotations(String path, String methodName) throws Excep assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getMeasurements()).isEmpty(); assertThat(telemetry.rdd1.getName()).isEqualTo("TestController." + methodName); diff --git a/smoke-tests/apps/SpringBootAttachInMain/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAttachInMainTest.java b/smoke-tests/apps/SpringBootAttachInMain/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAttachInMainTest.java index 5fe7f23bcf7..65449d7ba10 100644 --- a/smoke-tests/apps/SpringBootAttachInMain/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAttachInMainTest.java +++ b/smoke-tests/apps/SpringBootAttachInMain/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAttachInMainTest.java @@ -31,6 +31,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.JAVA_8; import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.JAVA_8_OPENJ9; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -49,8 +50,8 @@ void doMostBasicTest() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getMeasurements()).isEmpty(); assertThat(telemetry.rdEnvelope.getTags()) diff --git a/smoke-tests/apps/SpringBootAuto/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java b/smoke-tests/apps/SpringBootAuto/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java index 8fd267949c4..28c6a02fd95 100644 --- a/smoke-tests/apps/SpringBootAuto/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java +++ b/smoke-tests/apps/SpringBootAuto/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java @@ -31,6 +31,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8; import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -56,8 +57,8 @@ void doMostBasicTest() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getMeasurements()).isEmpty(); } diff --git a/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootControllerSpansEnabledTest.java b/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootControllerSpansEnabledTest.java index e017253f34f..74c3aef5db4 100644 --- a/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootControllerSpansEnabledTest.java +++ b/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootControllerSpansEnabledTest.java @@ -23,6 +23,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.TOMCAT_8_JAVA_8; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import com.microsoft.applicationinsights.smoketest.schemav2.Data; import com.microsoft.applicationinsights.smoketest.schemav2.Envelope; @@ -111,7 +112,8 @@ public boolean test(Envelope input) { assertThat(rd.getName()).isEqualTo("GET /SpringBootTest/throwsException"); assertThat(rd.getResponseCode()).isEqualTo("500"); - assertThat(rd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(rd.getSuccess()).isFalse(); assertThat(rdd1.getName()).isEqualTo("TestController.resultCodeTest"); @@ -157,7 +159,8 @@ void testAsyncDependencyCall() throws Exception { assertThat(rd.getName()).isEqualTo("GET /SpringBootTest/asyncDependencyCall"); assertThat(rd.getResponseCode()).isEqualTo("200"); - assertThat(rd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(rd.getSuccess()).isTrue(); assertThat(rdd1.getName()).isEqualTo("TestController.asyncDependencyCall"); @@ -170,7 +173,8 @@ void testAsyncDependencyCall() throws Exception { assertThat(rdd2.getName()).isEqualTo("GET /"); assertThat(rdd2.getData()).isEqualTo("https://www.bing.com"); assertThat(rdd2.getTarget()).isEqualTo("www.bing.com"); - assertThat(rdd2.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(rdd2.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(rdd2.getSuccess()).isTrue(); // TODO (trask): why is spring-webmvc instrumentation capturing this twice? diff --git a/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootTest.java b/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootTest.java index 6da942c34ed..9a21f8ad4ea 100644 --- a/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootTest.java +++ b/smoke-tests/apps/SpringBootTest/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootTest.java @@ -31,6 +31,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8; import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import com.microsoft.applicationinsights.smoketest.schemav2.Data; import com.microsoft.applicationinsights.smoketest.schemav2.Envelope; @@ -105,7 +106,8 @@ void testResultCodeWhenRestControllerThrows() throws Exception { assertThat(rd.getName()).isEqualTo("GET /SpringBootTest/throwsException"); assertThat(rd.getResponseCode()).isEqualTo("500"); - assertThat(rd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(rd.getSuccess()).isFalse(); SmokeTestExtension.assertParentChild( @@ -134,13 +136,15 @@ void testAsyncDependencyCall() throws Exception { assertThat(rd.getName()).isEqualTo("GET /SpringBootTest/asyncDependencyCall"); assertThat(rd.getResponseCode()).isEqualTo("200"); - assertThat(rd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(rd.getSuccess()).isTrue(); assertThat(rdd1.getName()).isEqualTo("GET /"); assertThat(rdd1.getData()).isEqualTo("https://www.bing.com"); assertThat(rdd1.getTarget()).isEqualTo("www.bing.com"); - assertThat(rdd1.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(rdd1.getSuccess()).isTrue(); SmokeTestExtension.assertParentChild( diff --git a/smoke-tests/apps/SpringCloudStream/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringCloudStreamControllerSpansEnabledTest.java b/smoke-tests/apps/SpringCloudStream/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringCloudStreamControllerSpansEnabledTest.java index f81554292f9..1337a1e9cff 100644 --- a/smoke-tests/apps/SpringCloudStream/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringCloudStreamControllerSpansEnabledTest.java +++ b/smoke-tests/apps/SpringCloudStream/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringCloudStreamControllerSpansEnabledTest.java @@ -23,6 +23,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.JAVA_8; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import com.microsoft.applicationinsights.smoketest.schemav2.Data; import com.microsoft.applicationinsights.smoketest.schemav2.Envelope; @@ -92,7 +93,8 @@ void doMostBasicTest() throws Exception { } assertThat(rd1.getName()).isEqualTo("GET /sendMessage"); - assertThat(rd1.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(rd1.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(rd1.getSuccess()).isTrue(); assertThat(rdd1.getName()).isEqualTo("GreetingsController.sendMessage"); diff --git a/smoke-tests/apps/SpringCloudStream/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringCloudStreamTest.java b/smoke-tests/apps/SpringCloudStream/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringCloudStreamTest.java index 9952de8902f..5eb79368e70 100644 --- a/smoke-tests/apps/SpringCloudStream/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringCloudStreamTest.java +++ b/smoke-tests/apps/SpringCloudStream/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringCloudStreamTest.java @@ -31,6 +31,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.JAVA_8; import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.JAVA_8_OPENJ9; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import com.microsoft.applicationinsights.smoketest.schemav2.Data; import com.microsoft.applicationinsights.smoketest.schemav2.Envelope; @@ -85,7 +86,8 @@ void doMostBasicTest() throws Exception { (RemoteDependencyData) ((Data) rddEnvelope1.getData()).getBaseData(); assertThat(rd1.getName()).isEqualTo("GET /sendMessage"); - assertThat(rd1.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(rd1.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(rd1.getSuccess()).isTrue(); assertThat(rdd1.getName()).isEqualTo("greetings send"); diff --git a/smoke-tests/apps/TelemetryProcessors/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java b/smoke-tests/apps/TelemetryProcessors/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java index 9d2f1bf5ddf..ecc92b978a5 100644 --- a/smoke-tests/apps/TelemetryProcessors/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java +++ b/smoke-tests/apps/TelemetryProcessors/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java @@ -31,6 +31,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8; import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import com.microsoft.applicationinsights.smoketest.schemav2.MessageData; import java.util.List; @@ -53,8 +54,8 @@ void doMostBasicTest() throws Exception { assertThat(telemetry.rd.getProperties().get("httpPath")) .isEqualTo("*/TelemetryProcessors/test*"); assertThat(telemetry.rd.getProperties()).hasSize(5); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getSuccess()).isTrue(); // Log processor test List logs = testing.mockedIngestion.getMessageDataInRequest(); diff --git a/smoke-tests/apps/WebFlux/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/WebFluxTest.java b/smoke-tests/apps/WebFlux/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/WebFluxTest.java index 82d11eaa420..33e5b509baa 100644 --- a/smoke-tests/apps/WebFlux/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/WebFluxTest.java +++ b/smoke-tests/apps/WebFlux/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/WebFluxTest.java @@ -31,6 +31,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.JAVA_8; import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.JAVA_8_OPENJ9; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -50,8 +51,8 @@ void doMostBasicTest() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getMeasurements()).isEmpty(); } @@ -65,8 +66,8 @@ void testException() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("500"); assertThat(telemetry.rd.getSuccess()).isFalse(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getMeasurements()).isEmpty(); } @@ -80,8 +81,8 @@ void testFutureException() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("500"); assertThat(telemetry.rd.getSuccess()).isFalse(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties().get("_MS.ProcessedByMetricExtractors")) - .isEqualTo("True"); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getMeasurements()).isEmpty(); } diff --git a/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java b/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java index 489842dea6a..31151f7c7db 100644 --- a/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java +++ b/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java @@ -31,6 +31,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.JAVA_8; import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.JAVA_8_OPENJ9; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import com.microsoft.applicationinsights.smoketest.schemav2.Data; import com.microsoft.applicationinsights.smoketest.schemav2.DataPoint; @@ -81,10 +82,12 @@ void doSimpleTest() throws Exception { assertThat(rdd.getTarget()).isEqualTo("localhost:10203"); - assertThat(rd1.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(rd1.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(rd1.getSuccess()).isTrue(); - assertThat(rdd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(rdd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(rdd.getSuccess()).isTrue(); // TODO (trask): verify rd2 @@ -123,10 +126,12 @@ void doConversationTest() throws Exception { assertThat(rdd.getTarget()).isEqualTo("localhost:10203"); - assertThat(rd1.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(rd1.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(rd1.getSuccess()).isTrue(); - assertThat(rdd.getProperties().get("_MS.ProcessedByMetricExtractors")).isEqualTo("True"); + assertThat(rdd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(rdd.getSuccess()).isTrue(); // TODO (trask): verify rd2 From 68bf94551c22138f7e1b19595b3b8d76a199ebb7 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Tue, 23 Aug 2022 17:06:17 -0700 Subject: [PATCH 79/95] Verify _MS.ProcessedByMetricExtractors --- .../smoketest/CustomDimensionsTest.java | 2 ++ .../applicationinsights/smoketest/HttpHeadersTest.java | 9 ++++++--- .../smoketest/SpringBootAutoTest.java | 1 + .../smoketest/OpenTelemetryApiSupportTest.java | 4 +--- .../smoketest/SpringBootAutoTest.java | 5 +++-- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/smoke-tests/apps/CustomDimensions/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CustomDimensionsTest.java b/smoke-tests/apps/CustomDimensions/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CustomDimensionsTest.java index 352b72c1827..0915a3ff891 100644 --- a/smoke-tests/apps/CustomDimensions/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CustomDimensionsTest.java +++ b/smoke-tests/apps/CustomDimensions/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/CustomDimensionsTest.java @@ -48,6 +48,8 @@ void doMostBasicTest() throws Exception { assertThat(telemetry.rd.getProperties()).containsEntry("test", "value"); assertThat(telemetry.rd.getProperties()).containsKey("home"); assertThat(telemetry.rd.getProperties()).hasSize(3); + assertThat(telemetry.rd.getProperties()) + .containsEntry("_MS.ProcessedByMetricExtractors", "True"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rdEnvelope.getTags()).containsEntry("ai.application.ver", "123"); diff --git a/smoke-tests/apps/HttpHeaders/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpHeadersTest.java b/smoke-tests/apps/HttpHeaders/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpHeadersTest.java index 5611784c796..09fb49d3280 100644 --- a/smoke-tests/apps/HttpHeaders/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpHeadersTest.java +++ b/smoke-tests/apps/HttpHeaders/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpHeadersTest.java @@ -31,7 +31,6 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8; import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.data.MapEntry.entry; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -50,6 +49,8 @@ void testServerHeaders() throws Exception { .isEqualTo("testing123"); assertThat(telemetry.rd.getProperties()).containsKey("http.request.header.host"); assertThat(telemetry.rd.getProperties()).hasSize(3); + assertThat(telemetry.rd.getProperties()) + .containsEntry("_MS.ProcessedByMetricExtractors", "True"); assertThat(telemetry.rd.getSuccess()).isTrue(); } @@ -60,13 +61,15 @@ void testClientHeaders() throws Exception { assertThat(telemetry.rd.getProperties()).containsKey("http.request.header.host"); assertThat(telemetry.rd.getProperties()).hasSize(2); - assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getProperties()) - .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); + .containsEntry("_MS.ProcessedByMetricExtractors", "True"); + assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rdd1.getProperties().get("http.request.header.abc")) .isEqualTo("testing123"); assertThat(telemetry.rdd1.getProperties()).containsKey("http.response.header.date"); assertThat(telemetry.rdd1.getProperties()).hasSize(3); + assertThat(telemetry.rdd1.getProperties()) + .containsEntry("_MS.ProcessedByMetricExtractors", "True"); assertThat(telemetry.rdd1.getSuccess()).isTrue(); } diff --git a/smoke-tests/apps/InheritedAttributes/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java b/smoke-tests/apps/InheritedAttributes/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java index 06fe3c325d7..4be20056ed8 100644 --- a/smoke-tests/apps/InheritedAttributes/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java +++ b/smoke-tests/apps/InheritedAttributes/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java @@ -67,6 +67,7 @@ void test() throws Exception { assertThat(rd.getResponseCode()).isEqualTo("200"); assertThat(rd.getProperties()).containsEntry("tenant", "z"); assertThat(rd.getProperties()).hasSize(2); + assertThat(rd.getProperties()).containsEntry("_MS.ProcessedByMetricExtractors", "True"); assertThat(rd.getSuccess()).isTrue(); assertThat(md.getMessage()).isEqualTo("hello"); diff --git a/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java b/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java index 4e0c2c4c086..d9c9d3306a5 100644 --- a/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java +++ b/smoke-tests/apps/OpenTelemetryApiSupport/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/OpenTelemetryApiSupportTest.java @@ -56,7 +56,7 @@ void testApi() throws Exception { assertThat(telemetry.rd.getProperties()).containsEntry("myattr1", "myvalue1"); assertThat(telemetry.rd.getProperties()).containsEntry("myattr2", "myvalue2"); assertThat(telemetry.rd.getProperties()) - .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); + .containsEntry("_MS.ProcessedByMetricExtractors", "True"); // ideally want the properties below on rd, but can't get SERVER span yet // see @@ -85,8 +85,6 @@ void testOverridingIkeyEtc() throws Exception { assertThat(telemetry.rd.getResponseCode()).isEqualTo("200"); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rd.getSource()).isNull(); - assertThat(telemetry.rd.getProperties()) - .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getProperties()) .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getMeasurements()).isEmpty(); diff --git a/smoke-tests/apps/TelemetryProcessors/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java b/smoke-tests/apps/TelemetryProcessors/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java index ecc92b978a5..0ce2f9459b2 100644 --- a/smoke-tests/apps/TelemetryProcessors/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java +++ b/smoke-tests/apps/TelemetryProcessors/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/SpringBootAutoTest.java @@ -31,7 +31,6 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8; import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.data.MapEntry.entry; import com.microsoft.applicationinsights.smoketest.schemav2.MessageData; import java.util.List; @@ -55,7 +54,7 @@ void doMostBasicTest() throws Exception { .isEqualTo("*/TelemetryProcessors/test*"); assertThat(telemetry.rd.getProperties()).hasSize(5); assertThat(telemetry.rd.getProperties()) - .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); + .containsEntry("_MS.ProcessedByMetricExtractors", "True"); assertThat(telemetry.rd.getSuccess()).isTrue(); // Log processor test List logs = testing.mockedIngestion.getMessageDataInRequest(); @@ -75,6 +74,8 @@ void doSimpleTestPiiData() throws Exception { assertThat(telemetry.rd.getProperties().get("httpPath")) .isEqualTo("*/TelemetryProcessors/sensitivedata*"); assertThat(telemetry.rd.getProperties()).hasSize(5); + assertThat(telemetry.rd.getProperties()) + .containsEntry("_MS.ProcessedByMetricExtractors", "True"); assertThat(telemetry.rd.getSuccess()).isTrue(); } From 111c773ea5acd510708f34aef6c28d6d8b65a2f2 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Tue, 23 Aug 2022 17:10:53 -0700 Subject: [PATCH 80/95] Fix wrong import --- .../opentelemetry/exporter/implementation/MetricDataMapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index f37cb95d6fb..078cd555668 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -49,7 +49,7 @@ import java.util.Set; import java.util.function.BiConsumer; import java.util.function.Consumer; -import jdk.internal.jline.internal.Nullable; +import javax.annotation.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; From 998e042769522ef5698af4cece20ba7b6b432ffd Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Tue, 23 Aug 2022 18:22:20 -0700 Subject: [PATCH 81/95] Fix a compilation error --- .../exporter/implementation/MetricDataMapper.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index 078cd555668..96fb8ba5682 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -49,7 +49,6 @@ import java.util.Set; import java.util.function.BiConsumer; import java.util.function.Consumer; -import javax.annotation.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -101,7 +100,7 @@ public void map(MetricData metricData, Consumer consumer) { } private List convertOtelMetricToAzureMonitorMetric( - MetricData metricData, @Nullable Boolean isPreAggregated) { + MetricData metricData, boolean isPreAggregated) { List telemetryItems = new ArrayList<>(); for (PointData pointData : metricData.getData().getPoints()) { From 24ad4c77b98293db20ef0ac5494c9facc8fd35fb Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Wed, 24 Aug 2022 10:06:54 -0700 Subject: [PATCH 82/95] Turn baseextractor into a util class --- agent/agent-bootstrap/build.gradle.kts | 1 + .../instrumenter/http/HttpClientMetrics.java | 3 +- .../http/TemporaryMetricsView.java | 122 ------------------ agent/agent/build.gradle.kts | 1 - .../DependencyExtractor.java | 27 ++-- ...aseExtractor.java => ExtractorHelper.java} | 24 ++-- .../RequestExtractor.java | 27 ++-- .../exporter/PreAggregatedMetricsTest.java | 10 +- .../smoketest/MicrometerTest.java | 1 + 9 files changed, 51 insertions(+), 165 deletions(-) delete mode 100644 agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java rename agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/{BaseExtractor.java => ExtractorHelper.java} (75%) diff --git a/agent/agent-bootstrap/build.gradle.kts b/agent/agent-bootstrap/build.gradle.kts index c018fef5266..11bedaa5416 100644 --- a/agent/agent-bootstrap/build.gradle.kts +++ b/agent/agent-bootstrap/build.gradle.kts @@ -8,6 +8,7 @@ dependencies { // TODO (heya) remove this when updating to upstream micrometer instrumentation compileOnly("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api") compileOnly("io.opentelemetry:opentelemetry-semconv") + compileOnly("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-semconv") compileOnly("com.google.auto.value:auto-value-annotations") annotationProcessor("com.google.auto.value:auto-value") diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java index bc9b0ff0979..32d893851e2 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java @@ -25,7 +25,6 @@ import static io.opentelemetry.instrumentation.api.instrumenter.BootstrapSemanticAttributes.IS_SYNTHETIC; import static io.opentelemetry.instrumentation.api.instrumenter.BootstrapSemanticAttributes.TARGET; import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.isUserAgentBot; -import static io.opentelemetry.instrumentation.api.instrumenter.http.TemporaryMetricsView.applyClientDurationAndSizeView; import static java.util.logging.Level.FINE; import com.google.auto.value.AutoValue; @@ -112,7 +111,7 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { return; } Attributes durationAndSizeAttributes = - applyClientDurationAndSizeView(state.startAttributes(), endAttributes); + TemporaryMetricsView.applyClientDurationAndSizeView(state.startAttributes(), endAttributes); // START APPLICATION INSIGHTS CODE diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java deleted file mode 100644 index 01f5f8e4a52..00000000000 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/TemporaryMetricsView.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * ApplicationInsights-Java - * Copyright (c) Microsoft Corporation - * All rights reserved. - * - * MIT License - * Permission is hereby granted, free of charge, to any person obtaining a copy of this - * software and associated documentation files (the ""Software""), to deal in the Software - * without restriction, including without limitation the rights to use, copy, modify, merge, - * publish, distribute, sublicense, and/or sell copies of the Software, and to permit - * persons to whom the Software is furnished to do so, subject to the following conditions: - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE - * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -package io.opentelemetry.instrumentation.api.instrumenter.http; - -import io.opentelemetry.api.common.AttributeKey; -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.common.AttributesBuilder; -import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; -import java.util.HashSet; -import java.util.Set; -import java.util.function.BiConsumer; - -// this is temporary, see -// https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/3962#issuecomment-906606325 -@SuppressWarnings("rawtypes") -final class TemporaryMetricsView { - - private static final Set durationAlwaysInclude = buildDurationAlwaysInclude(); - private static final Set durationClientView = buildDurationClientView(); - private static final Set durationServerView = buildDurationServerView(); - private static final Set activeRequestsView = buildActiveRequestsView(); - - private static Set buildDurationAlwaysInclude() { - // the list of included metrics is from - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/http-metrics.md#attributes - Set view = new HashSet<>(); - view.add(SemanticAttributes.HTTP_METHOD); - view.add(SemanticAttributes.HTTP_STATUS_CODE); // Optional - view.add(SemanticAttributes.HTTP_FLAVOR); // Optional - return view; - } - - private static Set buildDurationClientView() { - // We pull identifying attributes according to: - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/http-metrics.md#attribute-alternatives - // We only pull net.peer.name and net.peer.port because http.url has too high cardinality - Set view = new HashSet<>(durationAlwaysInclude); - view.add(SemanticAttributes.NET_PEER_NAME); - view.add(SemanticAttributes.NET_PEER_PORT); - return view; - } - - private static Set buildDurationServerView() { - // We pull identifying attributes according to: - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/http-metrics.md#attribute-alternatives - // With the following caveat: - // - we always rely on http.route + http.host in this repository. - // - we prefer http.route (which is scrubbed) over http.target (which is not scrubbed). - Set view = new HashSet<>(durationAlwaysInclude); - view.add(SemanticAttributes.HTTP_SCHEME); - view.add(SemanticAttributes.HTTP_HOST); - view.add(SemanticAttributes.HTTP_ROUTE); - return view; - } - - private static Set buildActiveRequestsView() { - // the list of included metrics is from - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/http-metrics.md#attributes - Set view = new HashSet<>(); - view.add(SemanticAttributes.HTTP_METHOD); - view.add(SemanticAttributes.HTTP_HOST); - view.add(SemanticAttributes.HTTP_SCHEME); - view.add(SemanticAttributes.HTTP_FLAVOR); - view.add(SemanticAttributes.HTTP_SERVER_NAME); - return view; - } - - static Attributes applyClientDurationAndSizeView( - Attributes startAttributes, Attributes endAttributes) { - AttributesBuilder filtered = Attributes.builder(); - applyView(filtered, startAttributes, durationClientView); - applyView(filtered, endAttributes, durationClientView); - return filtered.build(); - } - - static Attributes applyServerDurationAndSizeView( - Attributes startAttributes, Attributes endAttributes) { - AttributesBuilder filtered = Attributes.builder(); - applyView(filtered, startAttributes, durationServerView); - applyView(filtered, endAttributes, durationServerView); - return filtered.build(); - } - - static Attributes applyActiveRequestsView(Attributes attributes) { - AttributesBuilder filtered = Attributes.builder(); - applyView(filtered, attributes, activeRequestsView); - return filtered.build(); - } - - @SuppressWarnings("unchecked") - private static void applyView( - AttributesBuilder filtered, Attributes attributes, Set view) { - attributes.forEach( - (BiConsumer) - (key, value) -> { - if (view.contains(key)) { - filtered.put(key, value); - } - }); - } - - private TemporaryMetricsView() {} -} diff --git a/agent/agent/build.gradle.kts b/agent/agent/build.gradle.kts index c0999f0ce79..85d60e74673 100644 --- a/agent/agent/build.gradle.kts +++ b/agent/agent/build.gradle.kts @@ -115,7 +115,6 @@ tasks { exclude("io/opentelemetry/javaagent/shaded/instrumentation/api/instrumenter/http/HttpClientMetrics.class") exclude("io/opentelemetry/javaagent/shaded/instrumentation/api/instrumenter/http/HttpServerMetrics.class") - exclude("io/opentelemetry/javaagent/shaded/instrumentation/api/instrumenter/http/TemporaryMetricsView.class") exclude("io/opentelemetry/javaagent/shaded/instrumentation/api/instrumenter/rpc/RpcClientMetrics.class") exclude("io/opentelemetry/javaagent/shaded/instrumentation/api/instrumenter/rpc/RpcServerMetrics.class") diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java index dc6ed06636a..7513856b74e 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java @@ -21,9 +21,14 @@ package com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.ExtractorHelper.FALSE; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.ExtractorHelper.MS_METRIC_ID; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.ExtractorHelper.TRUE; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.ExtractorHelper.extractCommon; + import com.azure.monitor.opentelemetry.exporter.implementation.builders.MetricTelemetryBuilder; -public class DependencyExtractor extends BaseExtractor { +public class DependencyExtractor { // visible for testing public static final String DEPENDENCIES_DURATION = "dependencies/duration"; @@ -32,34 +37,38 @@ public class DependencyExtractor extends BaseExtractor { public static final String DEPENDENCY_TARGET = "dependency/target"; public static final String DEPENDENCY_RESULT_CODE = "dependency/resultCode"; + private final MetricTelemetryBuilder metricBuilder; private final Long statusCode; private final boolean success; private final String type; private final String target; + private final Boolean isSynthetic; public DependencyExtractor( - MetricTelemetryBuilder telemetryBuilder, + MetricTelemetryBuilder metricBuilder, Long statusCode, boolean success, String type, String target, Boolean isSynthetic) { - super(telemetryBuilder, isSynthetic); + this.metricBuilder = metricBuilder; this.statusCode = statusCode; this.success = success; this.type = type; this.target = target; + this.isSynthetic = isSynthetic; } - @Override public void extract() { - telemetryBuilder.addProperty(MS_METRIC_ID, DEPENDENCIES_DURATION); + extractCommon(metricBuilder, isSynthetic); + + metricBuilder.addProperty(MS_METRIC_ID, DEPENDENCIES_DURATION); // TODO OTEL will provide rpc.grpc.status_code & rpc.success, http.success if (statusCode != null) { - telemetryBuilder.addProperty(DEPENDENCY_RESULT_CODE, String.valueOf(statusCode)); + metricBuilder.addProperty(DEPENDENCY_RESULT_CODE, String.valueOf(statusCode)); } - telemetryBuilder.addProperty(DEPENDENCY_SUCCESS, success ? TRUE : FALSE); - telemetryBuilder.addProperty(DEPENDENCY_TYPE, type); - telemetryBuilder.addProperty(DEPENDENCY_TARGET, target); + metricBuilder.addProperty(DEPENDENCY_SUCCESS, success ? TRUE : FALSE); + metricBuilder.addProperty(DEPENDENCY_TYPE, type); + metricBuilder.addProperty(DEPENDENCY_TARGET, target); } } diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/BaseExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/ExtractorHelper.java similarity index 75% rename from agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/BaseExtractor.java rename to agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/ExtractorHelper.java index 1b2707d55ee..796527deb6d 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/BaseExtractor.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/ExtractorHelper.java @@ -21,12 +21,11 @@ package com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics; -import com.azure.monitor.opentelemetry.exporter.implementation.builders.AbstractTelemetryBuilder; import com.azure.monitor.opentelemetry.exporter.implementation.builders.MetricTelemetryBuilder; import com.azure.monitor.opentelemetry.exporter.implementation.models.ContextTagKeys; import java.util.Map; -public abstract class BaseExtractor { +public final class ExtractorHelper { // visible for testing public static final String MS_METRIC_ID = "_MS.MetricId"; @@ -37,31 +36,24 @@ public abstract class BaseExtractor { public static final String CLOUD_ROLE_NAME = "cloud/roleName"; public static final String CLOUD_ROLE_INSTANCE = "cloud/roleInstance"; - protected final AbstractTelemetryBuilder telemetryBuilder; - - public BaseExtractor(MetricTelemetryBuilder telemetryBuilder, Boolean isSynthetic) { - this.telemetryBuilder = telemetryBuilder; - extractCommon(isSynthetic); - } - - private void extractCommon(Boolean isSynthetic) { - telemetryBuilder.addProperty(MS_IS_AUTOCOLLECTED, TRUE); - Map tags = telemetryBuilder.build().getTags(); + static void extractCommon(MetricTelemetryBuilder metricBuilder, Boolean isSynthetic) { + metricBuilder.addProperty(MS_IS_AUTOCOLLECTED, TRUE); + Map tags = metricBuilder.build().getTags(); if (tags != null) { String cloudName = tags.get(ContextTagKeys.AI_CLOUD_ROLE.toString()); if (cloudName != null && !cloudName.isEmpty()) { - telemetryBuilder.addProperty(CLOUD_ROLE_NAME, cloudName); + metricBuilder.addProperty(CLOUD_ROLE_NAME, cloudName); } String cloudRoleInstance = tags.get(ContextTagKeys.AI_CLOUD_ROLE_INSTANCE.toString()); if (cloudRoleInstance != null && !cloudRoleInstance.isEmpty()) { - telemetryBuilder.addProperty(CLOUD_ROLE_INSTANCE, cloudRoleInstance); + metricBuilder.addProperty(CLOUD_ROLE_INSTANCE, cloudRoleInstance); } } - telemetryBuilder.addProperty( + metricBuilder.addProperty( OPERATION_SYNTHETIC, isSynthetic != null && isSynthetic ? TRUE : FALSE); } - public abstract void extract(); + private ExtractorHelper() {} } diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java index a145d2bedcb..6b44b9e5b2c 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java @@ -21,33 +21,40 @@ package com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.ExtractorHelper.FALSE; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.ExtractorHelper.MS_METRIC_ID; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.ExtractorHelper.TRUE; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.ExtractorHelper.extractCommon; + import com.azure.monitor.opentelemetry.exporter.implementation.builders.MetricTelemetryBuilder; -public final class RequestExtractor extends BaseExtractor { +public final class RequestExtractor { + // visible for testing public static final String REQUESTS_DURATION = "requests/duration"; public static final String REQUEST_RESULT_CODE = "request/resultCode"; public static final String REQUEST_SUCCESS = "request/success"; + private final MetricTelemetryBuilder metricBuilder; + private final Boolean isSynthetic; private final Long statusCode; private final boolean success; public RequestExtractor( - MetricTelemetryBuilder telemetryBuilder, - Long statusCode, - boolean success, - Boolean isSynthetic) { - super(telemetryBuilder, isSynthetic); + MetricTelemetryBuilder metricBuilder, Long statusCode, boolean success, Boolean isSynthetic) { + this.metricBuilder = metricBuilder; + this.isSynthetic = isSynthetic; this.statusCode = statusCode; this.success = success; } - @Override public void extract() { - telemetryBuilder.addProperty(MS_METRIC_ID, REQUESTS_DURATION); + extractCommon(metricBuilder, isSynthetic); + + metricBuilder.addProperty(MS_METRIC_ID, REQUESTS_DURATION); if (statusCode != null) { - telemetryBuilder.addProperty(REQUEST_RESULT_CODE, String.valueOf(statusCode)); + metricBuilder.addProperty(REQUEST_RESULT_CODE, String.valueOf(statusCode)); } - telemetryBuilder.addProperty(REQUEST_SUCCESS, success ? TRUE : FALSE); + metricBuilder.addProperty(REQUEST_SUCCESS, success ? TRUE : FALSE); } } diff --git a/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java index f1356724491..bfbc4b90f5f 100644 --- a/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java +++ b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java @@ -21,15 +21,15 @@ package com.azure.monitor.opentelemetry.exporter; -import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.BaseExtractor.FALSE; -import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.BaseExtractor.MS_IS_AUTOCOLLECTED; -import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.BaseExtractor.MS_METRIC_ID; -import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.BaseExtractor.OPERATION_SYNTHETIC; -import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.BaseExtractor.TRUE; import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.DependencyExtractor.DEPENDENCIES_DURATION; import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.DependencyExtractor.DEPENDENCY_RESULT_CODE; import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.DependencyExtractor.DEPENDENCY_SUCCESS; import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.DependencyExtractor.DEPENDENCY_TYPE; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.ExtractorHelper.FALSE; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.ExtractorHelper.MS_IS_AUTOCOLLECTED; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.ExtractorHelper.MS_METRIC_ID; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.ExtractorHelper.OPERATION_SYNTHETIC; +import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.ExtractorHelper.TRUE; import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestExtractor.REQUESTS_DURATION; import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestExtractor.REQUEST_RESULT_CODE; import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestExtractor.REQUEST_SUCCESS; diff --git a/smoke-tests/apps/Micrometer/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/MicrometerTest.java b/smoke-tests/apps/Micrometer/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/MicrometerTest.java index 6fb24ec4a7d..a93692af598 100644 --- a/smoke-tests/apps/Micrometer/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/MicrometerTest.java +++ b/smoke-tests/apps/Micrometer/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/MicrometerTest.java @@ -31,6 +31,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.JAVA_8; import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.JAVA_8_OPENJ9; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import com.microsoft.applicationinsights.smoketest.schemav2.Data; import com.microsoft.applicationinsights.smoketest.schemav2.DataPoint; From 6d46468c6d361ab22136b71f231fc7f64840dbe5 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Wed, 24 Aug 2022 10:16:51 -0700 Subject: [PATCH 83/95] Address comments --- .../BootstrapSemanticAttributes.java | 6 +++-- .../api/instrumenter/UserAgents.java | 4 ++-- .../instrumenter/http/HttpClientMetrics.java | 1 + .../instrumenter/http/HttpServerMetrics.java | 1 + .../instrumenter/rpc/RpcClientMetrics.java | 1 + .../instrumenter/rpc/RpcServerMetrics.java | 1 + .../implementation/MetricDataMapper.java | 23 +++++++++++-------- 7 files changed, 24 insertions(+), 13 deletions(-) diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/BootstrapSemanticAttributes.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/BootstrapSemanticAttributes.java index e7ed457ce1c..b143f10b584 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/BootstrapSemanticAttributes.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/BootstrapSemanticAttributes.java @@ -28,8 +28,10 @@ public final class BootstrapSemanticAttributes { - public static final AttributeKey IS_SYNTHETIC = booleanKey("isSynthetic"); - public static final AttributeKey TARGET = stringKey("target"); + public static final AttributeKey IS_SYNTHETIC = + booleanKey("applicationinsights.internal.is_synthetic"); + public static final AttributeKey TARGET = + stringKey("applicationinsights.internal.target"); public static final AttributeKey IS_PRE_AGGREGATED = booleanKey("applicationinsights.internal.is_pre_aggregated"); diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/UserAgents.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/UserAgents.java index fd942f7358c..071ae31a262 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/UserAgents.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/UserAgents.java @@ -29,9 +29,9 @@ public final class UserAgents { public static boolean isUserAgentBot(Attributes endAttributes, Attributes startAttributes) { - String aiUserAgent = + String userAgent = getAttribute(SemanticAttributes.HTTP_USER_AGENT, endAttributes, startAttributes); - return aiUserAgent != null && aiUserAgent.contains("AlwaysOn"); + return userAgent != null && userAgent.contains("AlwaysOn"); } @Nullable diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java index 32d893851e2..2cd031f4617 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java @@ -124,6 +124,7 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { .put(IS_SYNTHETIC, isUserAgentBot(endAttributes, state.startAttributes())) .put(TARGET, getTargetForHttpClientSpan(durationAndSizeAttributes)) .build(); + // END APPLICATION INSIGHTS CODE this.duration.record( diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java index f2a8f2aab29..b0fbfa754e6 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java @@ -135,6 +135,7 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { durationAndSizeAttributes.toBuilder() .put(IS_SYNTHETIC, isUserAgentBot(endAttributes, state.startAttributes())) .build(); + // END APPLICATION INSIGHTS CODE this.duration.record( diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java index 690ebac010e..2c739d6a31a 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java @@ -109,6 +109,7 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { .put(IS_SYNTHETIC, isUserAgentBot(endAttributes, state.startAttributes())) .put(TARGET, target) .build(); + // END APPLICATION INSIGHTS CODE clientDurationHistogram.record( diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java index 543339aa6e3..126292433d1 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java @@ -101,6 +101,7 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { endAttributes.toBuilder() .put(IS_SYNTHETIC, isUserAgentBot(endAttributes, state.startAttributes())) .build(); + // END APPLICATION INSIGHTS CODE serverDurationHistogram.record( diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index 96fb8ba5682..5b6ae0f170f 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -54,7 +54,7 @@ public class MetricDataMapper { - private static final Set OTEL_PRE_AGGREGATED_METRIC_NAMES = new HashSet<>(4); + private static final Set OTEL_STANDARD_METRIC_NAMES = new HashSet<>(4); private static final List EXCLUDED_METRIC_NAMES = new ArrayList<>(); private static final Logger logger = LoggerFactory.getLogger(MetricDataMapper.class); @@ -64,10 +64,10 @@ public class MetricDataMapper { static { EXCLUDED_METRIC_NAMES.add("http.server.active_requests"); // Servlet - OTEL_PRE_AGGREGATED_METRIC_NAMES.add("http.server.duration"); // Servlet - OTEL_PRE_AGGREGATED_METRIC_NAMES.add("http.client.duration"); // HttpClient - OTEL_PRE_AGGREGATED_METRIC_NAMES.add("rpc.client.duration"); // gRPC - OTEL_PRE_AGGREGATED_METRIC_NAMES.add("rpc.server.duration"); // gRPC + OTEL_STANDARD_METRIC_NAMES.add("http.server.duration"); // Servlet + OTEL_STANDARD_METRIC_NAMES.add("http.client.duration"); // HttpClient + OTEL_STANDARD_METRIC_NAMES.add("rpc.client.duration"); // gRPC + OTEL_STANDARD_METRIC_NAMES.add("rpc.server.duration"); // gRPC } public MetricDataMapper( @@ -88,7 +88,7 @@ public void map(MetricData metricData, Consumer consumer) { || type == LONG_SUM || type == LONG_GAUGE || type == HISTOGRAM) { - boolean isPreAggregated = OTEL_PRE_AGGREGATED_METRIC_NAMES.contains(metricData.getName()); + boolean isPreAggregated = OTEL_STANDARD_METRIC_NAMES.contains(metricData.getName()); List telemetryItemList = convertOtelMetricToAzureMonitorMetric(metricData, isPreAggregated); for (TelemetryItem telemetryItem : telemetryItemList) { @@ -160,7 +160,10 @@ public static void updateMetricPointBuilder( if (isPreAggregated) { Long statusCode = pointData.getAttributes().get(SemanticAttributes.HTTP_STATUS_CODE); boolean success = getSuccess(statusCode, captureHttpServer4xxAsError); - Boolean isSynthetic = pointData.getAttributes().get(AttributeKey.booleanKey("isSynthetic")); + Boolean isSynthetic = + pointData + .getAttributes() + .get(AttributeKey.booleanKey("applicationinsights.internal.is_synthetic")); if (metricData.getName().contains(".server.")) { RequestExtractor requestExtractor = new RequestExtractor(metricTelemetryBuilder, statusCode, success, isSynthetic); @@ -170,8 +173,10 @@ public static void updateMetricPointBuilder( metricData.getName().startsWith("http") ? "http" : pointData.getAttributes().get(SemanticAttributes.RPC_SYSTEM); - String target = pointData.getAttributes().get(AttributeKey.stringKey("target")); - + String target = + pointData + .getAttributes() + .get(AttributeKey.stringKey("applicationinsights.internal.target")); DependencyExtractor dependencyExtractor = new DependencyExtractor( metricTelemetryBuilder, statusCode, success, dependencyType, target, isSynthetic); From ad88fc4e88d05e82331d87f3b7a5c574d5ff67b4 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Wed, 24 Aug 2022 10:37:55 -0700 Subject: [PATCH 84/95] Fix tests --- .../exporter/PreAggregatedMetricsTest.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java index bfbc4b90f5f..dbdca09afef 100644 --- a/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java +++ b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java @@ -55,9 +55,11 @@ import io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.Collection; +import java.util.Comparator; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -112,11 +114,15 @@ void generateHttpClientMetrics() { listener.onEnd(context1, responseAttributes, nanos(250)); Collection metricDataCollection = metricReader.collectAllMetrics(); + metricDataCollection = + metricDataCollection.stream() + .sorted(Comparator.comparing(o -> o.getName())) + .collect(Collectors.toList()); for (MetricData metricData : metricDataCollection) { System.out.println("metric: " + metricData); } - assertThat(metricDataCollection.size()).isEqualTo(1); + assertThat(metricDataCollection.size()).isEqualTo(3); assertThat(metricDataCollection) .satisfiesExactly( @@ -140,7 +146,9 @@ void generateHttpClientMetrics() { exemplar -> exemplar .hasTraceId("ff01020304050600ff0a0b0c0d0e0f00") - .hasSpanId("090a0b0c0d0e0f00"))))); + .hasSpanId("090a0b0c0d0e0f00")))), + metric -> assertThat(metric).hasName("http.client.request.size"), + metric -> assertThat(metric).hasName("http.client.response.size")); MetricTelemetryBuilder builder = MetricTelemetryBuilder.create(); MetricData metricData = metricDataCollection.iterator().next(); From 22cdd01f19846f14fc618b547f9f0fae564d3936 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Wed, 24 Aug 2022 14:49:05 -0700 Subject: [PATCH 85/95] Address more comments --- .../api/instrumenter/UserAgents.java | 21 +++++-------------- .../instrumenter/http/HttpClientMetrics.java | 9 ++++++-- .../instrumenter/http/HttpServerMetrics.java | 4 ++-- .../instrumenter/rpc/RpcClientMetrics.java | 8 +++++-- .../instrumenter/rpc/RpcServerMetrics.java | 4 ++-- .../implementation/MetricDataMapper.java | 21 ++++++++++++------- .../implementation/SpanDataMapper.java | 10 ++++----- 7 files changed, 40 insertions(+), 37 deletions(-) diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/UserAgents.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/UserAgents.java index 071ae31a262..c511f9a9e79 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/UserAgents.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/UserAgents.java @@ -21,28 +21,17 @@ package io.opentelemetry.instrumentation.api.instrumenter; -import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; -import javax.annotation.Nullable; public final class UserAgents { - public static boolean isUserAgentBot(Attributes endAttributes, Attributes startAttributes) { - String userAgent = - getAttribute(SemanticAttributes.HTTP_USER_AGENT, endAttributes, startAttributes); - return userAgent != null && userAgent.contains("AlwaysOn"); - } - - @Nullable - private static T getAttribute(AttributeKey key, Attributes... attributesList) { - for (Attributes attributes : attributesList) { - T value = attributes.get(key); - if (value != null) { - return value; - } + public static boolean isBot(Attributes endAttributes, Attributes startAttributes) { + String userAgent = endAttributes.get(SemanticAttributes.HTTP_USER_AGENT); + if (userAgent == null) { + userAgent = startAttributes.get(SemanticAttributes.HTTP_USER_AGENT); } - return null; + return userAgent != null && userAgent.contains("AlwaysOn"); } private UserAgents() {} diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java index 2cd031f4617..c181b2071b5 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java @@ -24,7 +24,6 @@ import static io.opentelemetry.instrumentation.api.instrumenter.BootstrapSemanticAttributes.IS_PRE_AGGREGATED; import static io.opentelemetry.instrumentation.api.instrumenter.BootstrapSemanticAttributes.IS_SYNTHETIC; import static io.opentelemetry.instrumentation.api.instrumenter.BootstrapSemanticAttributes.TARGET; -import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.isUserAgentBot; import static java.util.logging.Level.FINE; import com.google.auto.value.AutoValue; @@ -38,6 +37,7 @@ import io.opentelemetry.context.ContextKey; import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; import io.opentelemetry.instrumentation.api.instrumenter.OperationMetrics; +import io.opentelemetry.instrumentation.api.instrumenter.UserAgents; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; @@ -121,7 +121,7 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { Attributes durationAttributes = durationAndSizeAttributes.toBuilder() - .put(IS_SYNTHETIC, isUserAgentBot(endAttributes, state.startAttributes())) + .put(IS_SYNTHETIC, UserAgents.isBot(endAttributes, state.startAttributes())) .put(TARGET, getTargetForHttpClientSpan(durationAndSizeAttributes)) .build(); @@ -146,6 +146,7 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { } } + // this is copied from SpanDataMapper private static String getTargetForHttpClientSpan(Attributes attributes) { // from the spec, at least one of the following sets of attributes is required: // * http.url @@ -195,12 +196,14 @@ private static String getTargetForHttpClientSpan(Attributes attributes) { return "Http"; } + // this is copied from SpanDataMapper @Nullable private static String getTargetFromPeerService(Attributes attributes) { // do not append port to peer.service return attributes.get(SemanticAttributes.PEER_SERVICE); } + // this is copied from SpanDataMapper @Nullable private static String getTargetFromNetAttributes(Attributes attributes, int defaultPort) { String target = getHostFromNetAttributes(attributes); @@ -215,6 +218,7 @@ private static String getTargetFromNetAttributes(Attributes attributes, int defa return target; } + // this is copied from SpanDataMapper @Nullable private static String getHostFromNetAttributes(Attributes attributes) { String host = attributes.get(SemanticAttributes.NET_PEER_NAME); @@ -224,6 +228,7 @@ private static String getHostFromNetAttributes(Attributes attributes) { return attributes.get(SemanticAttributes.NET_PEER_IP); } + // this is copied from SpanDataMapper @Nullable private static String getTargetFromUrl(String url) { int schemeEndIndex = url.indexOf(':'); diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java index b0fbfa754e6..74441bba767 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java @@ -23,7 +23,6 @@ import static io.opentelemetry.instrumentation.api.instrumenter.BootstrapSemanticAttributes.IS_PRE_AGGREGATED; import static io.opentelemetry.instrumentation.api.instrumenter.BootstrapSemanticAttributes.IS_SYNTHETIC; -import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.isUserAgentBot; import static java.util.logging.Level.FINE; import com.google.auto.value.AutoValue; @@ -38,6 +37,7 @@ import io.opentelemetry.context.ContextKey; import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; import io.opentelemetry.instrumentation.api.instrumenter.OperationMetrics; +import io.opentelemetry.instrumentation.api.instrumenter.UserAgents; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; @@ -133,7 +133,7 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { Attributes durationAttributes = durationAndSizeAttributes.toBuilder() - .put(IS_SYNTHETIC, isUserAgentBot(endAttributes, state.startAttributes())) + .put(IS_SYNTHETIC, UserAgents.isBot(endAttributes, state.startAttributes())) .build(); // END APPLICATION INSIGHTS CODE diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java index 2c739d6a31a..32770f01c18 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java @@ -24,7 +24,6 @@ import static io.opentelemetry.instrumentation.api.instrumenter.BootstrapSemanticAttributes.IS_PRE_AGGREGATED; import static io.opentelemetry.instrumentation.api.instrumenter.BootstrapSemanticAttributes.IS_SYNTHETIC; import static io.opentelemetry.instrumentation.api.instrumenter.BootstrapSemanticAttributes.TARGET; -import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.isUserAgentBot; import static io.opentelemetry.instrumentation.api.instrumenter.rpc.MetricsView.applyClientView; import static java.util.logging.Level.FINE; @@ -37,6 +36,7 @@ import io.opentelemetry.context.ContextKey; import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; import io.opentelemetry.instrumentation.api.instrumenter.OperationMetrics; +import io.opentelemetry.instrumentation.api.instrumenter.UserAgents; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; @@ -106,7 +106,7 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { } endAttributes = endAttributes.toBuilder() - .put(IS_SYNTHETIC, isUserAgentBot(endAttributes, state.startAttributes())) + .put(IS_SYNTHETIC, UserAgents.isBot(endAttributes, state.startAttributes())) .put(TARGET, target) .build(); @@ -118,6 +118,7 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { context); } + // this is copied from SpanDataMapper @Nullable private static String getTargetFromPeerAttributes(Attributes attributes, int defaultPort) { String target = getTargetFromPeerService(attributes); @@ -127,12 +128,14 @@ private static String getTargetFromPeerAttributes(Attributes attributes, int def return getTargetFromNetAttributes(attributes, defaultPort); } + // this is copied from SpanDataMapper @Nullable private static String getTargetFromPeerService(Attributes attributes) { // do not append port to peer.service return attributes.get(SemanticAttributes.PEER_SERVICE); } + // this is copied from SpanDataMapper @Nullable private static String getTargetFromNetAttributes(Attributes attributes, int defaultPort) { String target = getHostFromNetAttributes(attributes); @@ -147,6 +150,7 @@ private static String getTargetFromNetAttributes(Attributes attributes, int defa return target; } + // this is copied from SpanDataMapper @Nullable private static String getHostFromNetAttributes(Attributes attributes) { String host = attributes.get(SemanticAttributes.NET_PEER_NAME); diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java index 126292433d1..e06eae71a90 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java @@ -23,7 +23,6 @@ import static io.opentelemetry.instrumentation.api.instrumenter.BootstrapSemanticAttributes.IS_PRE_AGGREGATED; import static io.opentelemetry.instrumentation.api.instrumenter.BootstrapSemanticAttributes.IS_SYNTHETIC; -import static io.opentelemetry.instrumentation.api.instrumenter.UserAgents.isUserAgentBot; import static io.opentelemetry.instrumentation.api.instrumenter.rpc.MetricsView.applyServerView; import static java.util.logging.Level.FINE; @@ -36,6 +35,7 @@ import io.opentelemetry.context.ContextKey; import io.opentelemetry.instrumentation.api.instrumenter.OperationListener; import io.opentelemetry.instrumentation.api.instrumenter.OperationMetrics; +import io.opentelemetry.instrumentation.api.instrumenter.UserAgents; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; @@ -99,7 +99,7 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { endAttributes = endAttributes.toBuilder() - .put(IS_SYNTHETIC, isUserAgentBot(endAttributes, state.startAttributes())) + .put(IS_SYNTHETIC, UserAgents.isBot(endAttributes, state.startAttributes())) .build(); // END APPLICATION INSIGHTS CODE diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index 5b6ae0f170f..e52e40e9e2a 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -88,9 +88,10 @@ public void map(MetricData metricData, Consumer consumer) { || type == LONG_SUM || type == LONG_GAUGE || type == HISTOGRAM) { - boolean isPreAggregated = OTEL_STANDARD_METRIC_NAMES.contains(metricData.getName()); + boolean isPreAggregatedStandardMetric = + OTEL_STANDARD_METRIC_NAMES.contains(metricData.getName()); List telemetryItemList = - convertOtelMetricToAzureMonitorMetric(metricData, isPreAggregated); + convertOtelMetricToAzureMonitorMetric(metricData, isPreAggregatedStandardMetric); for (TelemetryItem telemetryItem : telemetryItemList) { consumer.accept(telemetryItem); } @@ -100,7 +101,7 @@ public void map(MetricData metricData, Consumer consumer) { } private List convertOtelMetricToAzureMonitorMetric( - MetricData metricData, boolean isPreAggregated) { + MetricData metricData, boolean isPreAggregatedStandardMetric) { List telemetryItems = new ArrayList<>(); for (PointData pointData : metricData.getData().getPoints()) { @@ -109,7 +110,11 @@ private List convertOtelMetricToAzureMonitorMetric( builder.setTime(FormattedTime.offSetDateTimeFromEpochNanos(pointData.getEpochNanos())); updateMetricPointBuilder( - builder, metricData, pointData, captureHttpServer4xxAsError, isPreAggregated); + builder, + metricData, + pointData, + captureHttpServer4xxAsError, + isPreAggregatedStandardMetric); telemetryItems.add(builder.build()); } @@ -122,7 +127,7 @@ public static void updateMetricPointBuilder( MetricData metricData, PointData pointData, boolean captureHttpServer4xxAsError, - boolean isPreAggregated) { + boolean isPreAggregatedStandardMetric) { checkArgument(metricData != null, "MetricData cannot be null."); MetricPointBuilder pointBuilder = new MetricPointBuilder(); @@ -157,9 +162,9 @@ public static void updateMetricPointBuilder( pointBuilder.setName(metricData.getName()); metricTelemetryBuilder.setMetricPoint(pointBuilder); - if (isPreAggregated) { + if (isPreAggregatedStandardMetric) { Long statusCode = pointData.getAttributes().get(SemanticAttributes.HTTP_STATUS_CODE); - boolean success = getSuccess(statusCode, captureHttpServer4xxAsError); + boolean success = isSuccess(statusCode, captureHttpServer4xxAsError); Boolean isSynthetic = pointData .getAttributes() @@ -190,7 +195,7 @@ public static void updateMetricPointBuilder( } } - private static boolean getSuccess(Long statusCode, boolean captureHttpServer4xxAsError) { + private static boolean isSuccess(Long statusCode, boolean captureHttpServer4xxAsError) { if (captureHttpServer4xxAsError) { return statusCode == null || statusCode < 400; } diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java index 7a65308c13b..998063d059f 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/SpanDataMapper.java @@ -227,11 +227,11 @@ private static boolean isRequest( } } - private static boolean checkIsPreAggregated(SpanData span) { - Boolean isPreAggregated = + private static boolean checkIsPreAggregatedStandardMetric(SpanData span) { + Boolean isPreAggregatedStandardMetric = span.getAttributes() .get(AttributeKey.booleanKey("applicationinsights.internal.is_pre_aggregated")); - return isPreAggregated != null && isPreAggregated; + return isPreAggregatedStandardMetric != null && isPreAggregatedStandardMetric; } private TelemetryItem exportRemoteDependency(SpanData span, boolean inProc, long itemCount) { @@ -261,7 +261,7 @@ private TelemetryItem exportRemoteDependency(SpanData span, boolean inProc, long applySemanticConventions(telemetryBuilder, span); } - if (checkIsPreAggregated(span)) { + if (checkIsPreAggregatedStandardMetric(span)) { telemetryBuilder.addProperty(MS_PROCESSED_BY_METRIC_EXTRACTORS, "True"); } @@ -692,7 +692,7 @@ private TelemetryItem exportRequest(SpanData span, long itemCount) { telemetryBuilder.addTag(ContextTagKeys.AI_DEVICE_OS_VERSION.toString(), deviceOsVersion); } - if (checkIsPreAggregated(span)) { + if (checkIsPreAggregatedStandardMetric(span)) { telemetryBuilder.addProperty(MS_PROCESSED_BY_METRIC_EXTRACTORS, "True"); } From b916cbf9651596938a36eb18ad3d8533b0c016e6 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Wed, 24 Aug 2022 15:39:16 -0700 Subject: [PATCH 86/95] Fix tests --- .../smoketest/HttpPreaggregatedMetricsSmokeTest.java | 2 +- .../smoketest/JmsControllerSpansEnabledTest.java | 4 +++- .../applicationinsights/smoketest/JdbcUnmaskedTest.java | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java index 06910259ab3..ac49981894f 100644 --- a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java +++ b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java @@ -47,7 +47,7 @@ @UseAgent abstract class HttpPreaggregatedMetricsSmokeTest { - @RegisterExtension static final SmokeTestExtension testing = new SmokeTestExtension(); + @RegisterExtension static final SmokeTestExtension testing = SmokeTestExtension.create(); @Test @TargetUri("/httpUrlConnection") diff --git a/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsControllerSpansEnabledTest.java b/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsControllerSpansEnabledTest.java index 49c34d7a7ca..df17085ddd1 100644 --- a/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsControllerSpansEnabledTest.java +++ b/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsControllerSpansEnabledTest.java @@ -23,6 +23,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.JAVA_8; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import com.microsoft.applicationinsights.smoketest.schemav2.Data; import com.microsoft.applicationinsights.smoketest.schemav2.Envelope; @@ -71,7 +72,8 @@ void doMostBasicTest() throws Exception { (RemoteDependencyData) ((Data) rddEnvelope3.getData()).getBaseData(); assertThat(rd1.getName()).isEqualTo("GET /sendMessage"); - assertThat(rd1.getProperties()).isEmpty(); + assertThat(rd1.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(rd1.getSuccess()).isTrue(); assertThat(rdd1.getName()).isEqualTo("HelloController.sendMessage"); diff --git a/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcUnmaskedTest.java b/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcUnmaskedTest.java index 98b5669bb69..9760fe00f73 100644 --- a/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcUnmaskedTest.java +++ b/smoke-tests/apps/Jdbc/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JdbcUnmaskedTest.java @@ -23,6 +23,7 @@ import static com.microsoft.applicationinsights.smoketest.WarEnvironmentValue.TOMCAT_8_JAVA_8; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.data.MapEntry.entry; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -38,7 +39,8 @@ class JdbcUnmaskedTest { void hsqldbStatement() throws Exception { Telemetry telemetry = testing.getTelemetry(1); - assertThat(telemetry.rd.getProperties()).isEmpty(); + assertThat(telemetry.rd.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(telemetry.rd.getSuccess()).isTrue(); assertThat(telemetry.rdd1.getName()).isEqualTo("SELECT testdb.abc"); From a1ee8e37fd1be3b066c831091ef3abcb06574d2d Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Wed, 24 Aug 2022 15:43:21 -0700 Subject: [PATCH 87/95] Use attrbuteKey constants --- .../implementation/AiSemanticAttributes.java | 7 +++++++ .../exporter/implementation/MetricDataMapper.java | 13 ++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/AiSemanticAttributes.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/AiSemanticAttributes.java index 2a3bf1dbeb8..9d058709330 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/AiSemanticAttributes.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/AiSemanticAttributes.java @@ -21,6 +21,7 @@ package com.azure.monitor.opentelemetry.exporter.implementation; +import static io.opentelemetry.api.common.AttributeKey.booleanKey; import static io.opentelemetry.api.common.AttributeKey.longKey; import static io.opentelemetry.api.common.AttributeKey.stringKey; @@ -34,5 +35,11 @@ public final class AiSemanticAttributes { public static final AttributeKey ITEM_COUNT = longKey("applicationinsights.internal.item_count"); + public static final AttributeKey IS_SYNTHETIC = + booleanKey("applicationinsights.internal.is_synthetic"); + + public static final AttributeKey TARGET = + stringKey("applicationinsights.internal.target"); + private AiSemanticAttributes() {} } diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index e52e40e9e2a..1785c80df2a 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -21,6 +21,8 @@ package com.azure.monitor.opentelemetry.exporter.implementation; +import static com.azure.monitor.opentelemetry.exporter.implementation.AiSemanticAttributes.IS_SYNTHETIC; +import static com.azure.monitor.opentelemetry.exporter.implementation.AiSemanticAttributes.TARGET; import static io.opentelemetry.api.internal.Utils.checkArgument; import static io.opentelemetry.sdk.metrics.data.MetricDataType.DOUBLE_GAUGE; import static io.opentelemetry.sdk.metrics.data.MetricDataType.DOUBLE_SUM; @@ -35,7 +37,6 @@ import com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.DependencyExtractor; import com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.RequestExtractor; import com.azure.monitor.opentelemetry.exporter.implementation.utils.FormattedTime; -import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.sdk.metrics.data.DoublePointData; import io.opentelemetry.sdk.metrics.data.HistogramPointData; import io.opentelemetry.sdk.metrics.data.LongPointData; @@ -165,10 +166,7 @@ public static void updateMetricPointBuilder( if (isPreAggregatedStandardMetric) { Long statusCode = pointData.getAttributes().get(SemanticAttributes.HTTP_STATUS_CODE); boolean success = isSuccess(statusCode, captureHttpServer4xxAsError); - Boolean isSynthetic = - pointData - .getAttributes() - .get(AttributeKey.booleanKey("applicationinsights.internal.is_synthetic")); + Boolean isSynthetic = pointData.getAttributes().get(IS_SYNTHETIC); if (metricData.getName().contains(".server.")) { RequestExtractor requestExtractor = new RequestExtractor(metricTelemetryBuilder, statusCode, success, isSynthetic); @@ -178,10 +176,7 @@ public static void updateMetricPointBuilder( metricData.getName().startsWith("http") ? "http" : pointData.getAttributes().get(SemanticAttributes.RPC_SYSTEM); - String target = - pointData - .getAttributes() - .get(AttributeKey.stringKey("applicationinsights.internal.target")); + String target = pointData.getAttributes().get(TARGET); DependencyExtractor dependencyExtractor = new DependencyExtractor( metricTelemetryBuilder, statusCode, success, dependencyType, target, isSynthetic); From 8b9601f455bde4e3f455334cebcb4f74a0268fbc Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 25 Aug 2022 11:53:45 -0700 Subject: [PATCH 88/95] Address comments --- .../internal/configuration/ConfigurationBuilder.java | 7 +++---- .../apps/HttpPreaggregatedMetrics/build.gradle.kts | 4 ---- .../smoketest/HttpPreaggregatedMetricsSmokeTest.java | 10 +++++----- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationBuilder.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationBuilder.java index 605e6817b2c..0e795ad5ce1 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationBuilder.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationBuilder.java @@ -466,10 +466,9 @@ static void overlayFromEnv(Configuration config, Path baseDir) throws IOExceptio APPLICATIONINSIGHTS_SELF_DIAGNOSTICS_FILE_PATH, config.selfDiagnostics.file.path); config.preview.metricIntervalSeconds = - (int) - overlayWithEnvVar( - APPLICATIONINSIGHTS_PREVIEW_METRIC_INTERVAL_SECONDS, - config.preview.metricIntervalSeconds); + overlayWithEnvVar( + APPLICATIONINSIGHTS_PREVIEW_METRIC_INTERVAL_SECONDS, + config.preview.metricIntervalSeconds); config.preview.instrumentation.springIntegration.enabled = overlayWithEnvVar( diff --git a/smoke-tests/apps/HttpPreaggregatedMetrics/build.gradle.kts b/smoke-tests/apps/HttpPreaggregatedMetrics/build.gradle.kts index 8d13585aaf1..eb5b96e032d 100644 --- a/smoke-tests/apps/HttpPreaggregatedMetrics/build.gradle.kts +++ b/smoke-tests/apps/HttpPreaggregatedMetrics/build.gradle.kts @@ -1,7 +1,3 @@ plugins { id("ai.smoke-test-war") } - -dependencies { - implementation("org.apache.httpcomponents:httpasyncclient:4.1.4") -} diff --git a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java index ac49981894f..9c9ce94a756 100644 --- a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java +++ b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java @@ -188,19 +188,19 @@ private static void validateMetricData(String type, MetricData metricData, Strin assertThat(dataPoint.getCount()).isEqualTo(1); assertThat(dataPoint.getValue()).isGreaterThan(0d).isLessThan(5 * 60 * 1000d); // (0 - 5) min assertThat(dataPoint.getMin()).isGreaterThan(0d).isLessThan(5 * 60 * 1000d); // (0 - 5) min - assertThat(dataPoint.getMin()).isGreaterThan(0d).isLessThan(5 * 60 * 1000d); // (0 - 5) min + assertThat(dataPoint.getMax()).isGreaterThan(0d).isLessThan(5 * 60 * 1000d); // (0 - 5) min Map properties = metricData.getProperties(); - String expectedResultCode = "200".equals(resultCode) ? "True" : "False"; + String expectedSuccess = "200".equals(resultCode) ? "True" : "False"; if ("client".equals(type)) { assertThat(properties.get("_MS.MetricId")).isEqualTo("dependencies/duration"); assertThat(properties.get("dependency/resultCode")).isEqualTo(resultCode); - assertThat(properties.get("dependency/success")).isEqualTo(expectedResultCode); + assertThat(properties.get("dependency/success")).isEqualTo(expectedSuccess); assertThat(properties.get("dependency/target")).isNotNull(); - assertThat(properties.get("dependency/type")).isNotNull(); + assertThat(properties.get("dependency/type")).isEqualTo("http"); } else { assertThat(properties.get("_MS.MetricId")).isEqualTo("requests/duration"); assertThat(properties.get("request/resultCode")).isEqualTo(resultCode); - assertThat(properties.get("request/success")).isEqualTo(expectedResultCode); + assertThat(properties.get("request/success")).isEqualTo(expectedSuccess); } assertThat(properties.get("operation/synthetic")).isEqualTo("False"); assertThat(properties.get("cloud/roleInstance")).isEqualTo("testroleinstance"); From 81efed100a500ab7707d5ba8a508ba07d32333ed Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 25 Aug 2022 11:59:30 -0700 Subject: [PATCH 89/95] Fix a typo --- .../agent/internal/configuration/ConfigurationBuilder.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationBuilder.java b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationBuilder.java index 998146e8096..b8906c4a351 100644 --- a/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationBuilder.java +++ b/agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/configuration/ConfigurationBuilder.java @@ -469,9 +469,10 @@ static void overlayFromEnv(Configuration config, Path baseDir) throws IOExceptio APPLICATIONINSIGHTS_SELF_DIAGNOSTICS_FILE_PATH, config.selfDiagnostics.file.path); config.preview.metricIntervalSeconds = - overlayWithEnvVar( - APPLICATIONINSIGHTS_PREVIEW_METRIC_INTERVAL_SECONDS, - config.preview.metricIntervalSeconds); + (int) + overlayWithEnvVar( + APPLICATIONINSIGHTS_PREVIEW_METRIC_INTERVAL_SECONDS, + config.preview.metricIntervalSeconds); config.preview.instrumentation.springIntegration.enabled = overlayWithEnvVar( From d61b7d9336d198d75d5ca992ee57899d48500774 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 25 Aug 2022 13:41:56 -0700 Subject: [PATCH 90/95] Fix one more test --- .../smoketest/JmsControllerSpansEnabledTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsControllerSpansEnabledTest.java b/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsControllerSpansEnabledTest.java index df17085ddd1..7eee7fc3a97 100644 --- a/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsControllerSpansEnabledTest.java +++ b/smoke-tests/apps/JMS/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/JmsControllerSpansEnabledTest.java @@ -99,7 +99,8 @@ void doMostBasicTest() throws Exception { assertThat(rdd3.getData()).isEqualTo("https://www.bing.com"); assertThat(rdd3.getType()).isEqualTo("Http"); assertThat(rdd3.getTarget()).isEqualTo("www.bing.com"); - assertThat(rdd3.getProperties()).isEmpty(); + assertThat(rdd3.getProperties()) + .containsExactly(entry("_MS.ProcessedByMetricExtractors", "True")); assertThat(rdd3.getSuccess()).isTrue(); SmokeTestExtension.assertParentChild(rd1, rdEnvelope1, rddEnvelope1, "GET /sendMessage"); From 1855abd8c76e89913523bb570c64869056da718d Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 25 Aug 2022 14:18:01 -0700 Subject: [PATCH 91/95] Remove MetricView and turn extractors into util class --- .../api/instrumenter/rpc/MetricsView.java | 142 ------------------ .../instrumenter/rpc/RpcClientMetrics.java | 11 +- agent/agent/build.gradle.kts | 1 - .../implementation/MetricDataMapper.java | 10 +- .../DependencyExtractor.java | 22 +-- .../RequestExtractor.java | 16 +- 6 files changed, 15 insertions(+), 187 deletions(-) delete mode 100644 agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java deleted file mode 100644 index 8b49d66b9e8..00000000000 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * ApplicationInsights-Java - * Copyright (c) Microsoft Corporation - * All rights reserved. - * - * MIT License - * Permission is hereby granted, free of charge, to any person obtaining a copy of this - * software and associated documentation files (the ""Software""), to deal in the Software - * without restriction, including without limitation the rights to use, copy, modify, merge, - * publish, distribute, sublicense, and/or sell copies of the Software, and to permit - * persons to whom the Software is furnished to do so, subject to the following conditions: - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE - * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - -package io.opentelemetry.instrumentation.api.instrumenter.rpc; - -import static io.opentelemetry.instrumentation.api.instrumenter.BootstrapSemanticAttributes.IS_SYNTHETIC; -import static io.opentelemetry.instrumentation.api.instrumenter.BootstrapSemanticAttributes.TARGET; - -import io.opentelemetry.api.common.AttributeKey; -import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.api.common.AttributesBuilder; -import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; -import java.util.HashSet; -import java.util.Set; -import java.util.function.BiConsumer; - -// this is temporary, see -// https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/3962#issuecomment-906606325 -@SuppressWarnings("rawtypes") -final class MetricsView { - - private static final Set alwaysInclude = buildAlwaysInclude(); - private static final Set clientView = buildClientView(); - private static final Set clientFallbackView = buildClientFallbackView(); - private static final Set serverView = buildServerView(); - private static final Set serverFallbackView = buildServerFallbackView(); - - private static Set buildAlwaysInclude() { - // the list of recommended metrics attributes is from - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/rpc.md#attributes - Set view = new HashSet<>(); - view.add(SemanticAttributes.RPC_SYSTEM); - view.add(SemanticAttributes.RPC_SERVICE); - view.add(SemanticAttributes.RPC_METHOD); - - // START APPLICATION INSIGHTS CODE - view.add(TARGET); - view.add(IS_SYNTHETIC); - // END APPLICATION INSIGHTS CODE - - return view; - } - - private static Set buildClientView() { - // the list of rpc client metrics attributes is from - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/rpc.md#attributes - Set view = new HashSet<>(alwaysInclude); - view.add(SemanticAttributes.NET_PEER_NAME); - view.add(SemanticAttributes.NET_PEER_PORT); - view.add(SemanticAttributes.NET_TRANSPORT); - return view; - } - - private static Set buildClientFallbackView() { - // the list of rpc client metrics attributes is from - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/rpc.md#attributes - Set view = new HashSet<>(alwaysInclude); - view.add(SemanticAttributes.NET_PEER_IP); - view.add(SemanticAttributes.NET_PEER_PORT); - view.add(SemanticAttributes.NET_TRANSPORT); - return view; - } - - private static Set buildServerView() { - // the list of rpc server metrics attributes is from - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/rpc.md#attributes - Set view = new HashSet<>(alwaysInclude); - view.add(SemanticAttributes.NET_HOST_NAME); - view.add(SemanticAttributes.NET_TRANSPORT); - return view; - } - - private static Set buildServerFallbackView() { - // the list of rpc server metrics attributes is from - // https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/metrics/semantic_conventions/rpc.md#attributes - Set view = new HashSet<>(alwaysInclude); - view.add(SemanticAttributes.NET_HOST_IP); - view.add(SemanticAttributes.NET_TRANSPORT); - return view; - } - - private static boolean containsAttribute( - AttributeKey key, Attributes startAttributes, Attributes endAttributes) { - return startAttributes.get(key) != null || endAttributes.get(key) != null; - } - - static Attributes applyClientView(Attributes startAttributes, Attributes endAttributes) { - Set fullSet = clientView; - if (!containsAttribute(SemanticAttributes.NET_PEER_NAME, startAttributes, endAttributes)) { - fullSet = clientFallbackView; - } - return applyView(fullSet, startAttributes, endAttributes); - } - - static Attributes applyServerView(Attributes startAttributes, Attributes endAttributes) { - Set fullSet = serverView; - if (!containsAttribute(SemanticAttributes.NET_HOST_NAME, startAttributes, endAttributes)) { - fullSet = serverFallbackView; - } - return applyView(fullSet, startAttributes, endAttributes); - } - - static Attributes applyView( - Set view, Attributes startAttributes, Attributes endAttributes) { - AttributesBuilder filtered = Attributes.builder(); - applyView(filtered, startAttributes, view); - applyView(filtered, endAttributes, view); - return filtered.build(); - } - - @SuppressWarnings("unchecked") - private static void applyView( - AttributesBuilder filtered, Attributes attributes, Set view) { - attributes.forEach( - (BiConsumer) - (key, value) -> { - if (view.contains(key)) { - filtered.put(key, value); - } - }); - } - - private MetricsView() {} -} diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java index 32770f01c18..cd99e44fc7b 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcClientMetrics.java @@ -24,7 +24,6 @@ import static io.opentelemetry.instrumentation.api.instrumenter.BootstrapSemanticAttributes.IS_PRE_AGGREGATED; import static io.opentelemetry.instrumentation.api.instrumenter.BootstrapSemanticAttributes.IS_SYNTHETIC; import static io.opentelemetry.instrumentation.api.instrumenter.BootstrapSemanticAttributes.TARGET; -import static io.opentelemetry.instrumentation.api.instrumenter.rpc.MetricsView.applyClientView; import static java.util.logging.Level.FINE; import com.google.auto.value.AutoValue; @@ -96,6 +95,8 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { // START APPLICATION INSIGHTS CODE + Attributes attributes = MetricsView.applyClientView(state.startAttributes(), endAttributes); + // this is needed for detecting telemetry signals that will trigger pre-aggregated metrics via // auto instrumentations Span.fromContext(context).setAttribute(IS_PRE_AGGREGATED, true); @@ -104,8 +105,8 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { if (target == null) { target = endAttributes.get(SemanticAttributes.RPC_SYSTEM); } - endAttributes = - endAttributes.toBuilder() + attributes = + attributes.toBuilder() .put(IS_SYNTHETIC, UserAgents.isBot(endAttributes, state.startAttributes())) .put(TARGET, target) .build(); @@ -113,9 +114,7 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { // END APPLICATION INSIGHTS CODE clientDurationHistogram.record( - (endNanos - state.startTimeNanos()) / NANOS_PER_MS, - applyClientView(state.startAttributes(), endAttributes), - context); + (endNanos - state.startTimeNanos()) / NANOS_PER_MS, attributes, context); } // this is copied from SpanDataMapper diff --git a/agent/agent/build.gradle.kts b/agent/agent/build.gradle.kts index 85d60e74673..158a3b5f0c9 100644 --- a/agent/agent/build.gradle.kts +++ b/agent/agent/build.gradle.kts @@ -118,7 +118,6 @@ tasks { exclude("io/opentelemetry/javaagent/shaded/instrumentation/api/instrumenter/rpc/RpcClientMetrics.class") exclude("io/opentelemetry/javaagent/shaded/instrumentation/api/instrumenter/rpc/RpcServerMetrics.class") - exclude("io/opentelemetry/javaagent/shaded/instrumentation/api/instrumenter/rpc/MetricsView.class") dependsOn(isolateJavaagentLibs) from(isolateJavaagentLibs.get().outputs) diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index 1785c80df2a..b4b98a4425e 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -168,19 +168,15 @@ public static void updateMetricPointBuilder( boolean success = isSuccess(statusCode, captureHttpServer4xxAsError); Boolean isSynthetic = pointData.getAttributes().get(IS_SYNTHETIC); if (metricData.getName().contains(".server.")) { - RequestExtractor requestExtractor = - new RequestExtractor(metricTelemetryBuilder, statusCode, success, isSynthetic); - requestExtractor.extract(); + RequestExtractor.extract(metricTelemetryBuilder, statusCode, success, isSynthetic); } else if (metricData.getName().contains(".client.")) { String dependencyType = metricData.getName().startsWith("http") ? "http" : pointData.getAttributes().get(SemanticAttributes.RPC_SYSTEM); String target = pointData.getAttributes().get(TARGET); - DependencyExtractor dependencyExtractor = - new DependencyExtractor( - metricTelemetryBuilder, statusCode, success, dependencyType, target, isSynthetic); - dependencyExtractor.extract(); + DependencyExtractor.extract( + metricTelemetryBuilder, statusCode, success, dependencyType, target, isSynthetic); } } else { pointData diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java index 7513856b74e..09ef005d711 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java @@ -28,7 +28,7 @@ import com.azure.monitor.opentelemetry.exporter.implementation.builders.MetricTelemetryBuilder; -public class DependencyExtractor { +public final class DependencyExtractor { // visible for testing public static final String DEPENDENCIES_DURATION = "dependencies/duration"; @@ -37,29 +37,13 @@ public class DependencyExtractor { public static final String DEPENDENCY_TARGET = "dependency/target"; public static final String DEPENDENCY_RESULT_CODE = "dependency/resultCode"; - private final MetricTelemetryBuilder metricBuilder; - private final Long statusCode; - private final boolean success; - private final String type; - private final String target; - private final Boolean isSynthetic; - - public DependencyExtractor( + public static void extract( MetricTelemetryBuilder metricBuilder, Long statusCode, boolean success, String type, String target, Boolean isSynthetic) { - this.metricBuilder = metricBuilder; - this.statusCode = statusCode; - this.success = success; - this.type = type; - this.target = target; - this.isSynthetic = isSynthetic; - } - - public void extract() { extractCommon(metricBuilder, isSynthetic); metricBuilder.addProperty(MS_METRIC_ID, DEPENDENCIES_DURATION); @@ -71,4 +55,6 @@ public void extract() { metricBuilder.addProperty(DEPENDENCY_TYPE, type); metricBuilder.addProperty(DEPENDENCY_TARGET, target); } + + private DependencyExtractor() {} } diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java index 6b44b9e5b2c..f269b7a55e2 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java @@ -35,20 +35,8 @@ public final class RequestExtractor { public static final String REQUEST_RESULT_CODE = "request/resultCode"; public static final String REQUEST_SUCCESS = "request/success"; - private final MetricTelemetryBuilder metricBuilder; - private final Boolean isSynthetic; - private final Long statusCode; - private final boolean success; - - public RequestExtractor( + public static void extract( MetricTelemetryBuilder metricBuilder, Long statusCode, boolean success, Boolean isSynthetic) { - this.metricBuilder = metricBuilder; - this.isSynthetic = isSynthetic; - this.statusCode = statusCode; - this.success = success; - } - - public void extract() { extractCommon(metricBuilder, isSynthetic); metricBuilder.addProperty(MS_METRIC_ID, REQUESTS_DURATION); @@ -57,4 +45,6 @@ public void extract() { } metricBuilder.addProperty(REQUEST_SUCCESS, success ? TRUE : FALSE); } + + private RequestExtractor() {} } From 53f145a68171ab34e8ff51783a809a52a3965cbe Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 25 Aug 2022 14:53:08 -0700 Subject: [PATCH 92/95] Apply the same to rpcservermetrics --- .../api/instrumenter/rpc/RpcServerMetrics.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java index e06eae71a90..f1943f75e18 100644 --- a/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java +++ b/agent/agent-bootstrap/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/RpcServerMetrics.java @@ -23,7 +23,6 @@ import static io.opentelemetry.instrumentation.api.instrumenter.BootstrapSemanticAttributes.IS_PRE_AGGREGATED; import static io.opentelemetry.instrumentation.api.instrumenter.BootstrapSemanticAttributes.IS_SYNTHETIC; -import static io.opentelemetry.instrumentation.api.instrumenter.rpc.MetricsView.applyServerView; import static java.util.logging.Level.FINE; import com.google.auto.value.AutoValue; @@ -93,21 +92,21 @@ public void onEnd(Context context, Attributes endAttributes, long endNanos) { // START APPLICATION INSIGHTS CODE + Attributes attributes = MetricsView.applyServerView(state.startAttributes(), endAttributes); + // this is needed for detecting telemetry signals that will trigger pre-aggregated metrics via // auto instrumentations Span.fromContext(context).setAttribute(IS_PRE_AGGREGATED, true); - endAttributes = - endAttributes.toBuilder() + attributes = + attributes.toBuilder() .put(IS_SYNTHETIC, UserAgents.isBot(endAttributes, state.startAttributes())) .build(); // END APPLICATION INSIGHTS CODE serverDurationHistogram.record( - (endNanos - state.startTimeNanos()) / NANOS_PER_MS, - applyServerView(state.startAttributes(), endAttributes), - context); + (endNanos - state.startTimeNanos()) / NANOS_PER_MS, attributes, context); } @AutoValue From 0db361d1d5589367ce1732f1c6e19e816782c61e Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 25 Aug 2022 14:55:45 -0700 Subject: [PATCH 93/95] Rename --- .../exporter/implementation/MetricDataMapper.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index b4b98a4425e..3b06554e3d2 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -55,7 +55,7 @@ public class MetricDataMapper { - private static final Set OTEL_STANDARD_METRIC_NAMES = new HashSet<>(4); + private static final Set OTEL_PRE_AGGREGATED_STANDARD_METRIC_NAMES = new HashSet<>(4); private static final List EXCLUDED_METRIC_NAMES = new ArrayList<>(); private static final Logger logger = LoggerFactory.getLogger(MetricDataMapper.class); @@ -65,10 +65,10 @@ public class MetricDataMapper { static { EXCLUDED_METRIC_NAMES.add("http.server.active_requests"); // Servlet - OTEL_STANDARD_METRIC_NAMES.add("http.server.duration"); // Servlet - OTEL_STANDARD_METRIC_NAMES.add("http.client.duration"); // HttpClient - OTEL_STANDARD_METRIC_NAMES.add("rpc.client.duration"); // gRPC - OTEL_STANDARD_METRIC_NAMES.add("rpc.server.duration"); // gRPC + OTEL_PRE_AGGREGATED_STANDARD_METRIC_NAMES.add("http.server.duration"); // Servlet + OTEL_PRE_AGGREGATED_STANDARD_METRIC_NAMES.add("http.client.duration"); // HttpClient + OTEL_PRE_AGGREGATED_STANDARD_METRIC_NAMES.add("rpc.client.duration"); // gRPC + OTEL_PRE_AGGREGATED_STANDARD_METRIC_NAMES.add("rpc.server.duration"); // gRPC } public MetricDataMapper( @@ -90,7 +90,7 @@ public void map(MetricData metricData, Consumer consumer) { || type == LONG_GAUGE || type == HISTOGRAM) { boolean isPreAggregatedStandardMetric = - OTEL_STANDARD_METRIC_NAMES.contains(metricData.getName()); + OTEL_PRE_AGGREGATED_STANDARD_METRIC_NAMES.contains(metricData.getName()); List telemetryItemList = convertOtelMetricToAzureMonitorMetric(metricData, isPreAggregatedStandardMetric); for (TelemetryItem telemetryItem : telemetryItemList) { From 1e7fb051823bd34994ff56688b70d20f0c97dafc Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 25 Aug 2022 16:31:41 -0700 Subject: [PATCH 94/95] Comments --- .../preaggregatedmetrics/DependencyExtractor.java | 5 +++-- .../preaggregatedmetrics/ExtractorHelper.java | 3 ++- .../preaggregatedmetrics/RequestExtractor.java | 6 +++++- .../smoketest/HttpPreaggregatedMetricsSmokeTest.java | 4 +++- .../microsoft/applicationinsights/smoketest/GrpcTest.java | 6 +++--- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java index 09ef005d711..d7ed8a9596b 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/DependencyExtractor.java @@ -27,6 +27,7 @@ import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.ExtractorHelper.extractCommon; import com.azure.monitor.opentelemetry.exporter.implementation.builders.MetricTelemetryBuilder; +import javax.annotation.Nullable; public final class DependencyExtractor { @@ -39,11 +40,11 @@ public final class DependencyExtractor { public static void extract( MetricTelemetryBuilder metricBuilder, - Long statusCode, + @Nullable Long statusCode, boolean success, String type, String target, - Boolean isSynthetic) { + @Nullable Boolean isSynthetic) { extractCommon(metricBuilder, isSynthetic); metricBuilder.addProperty(MS_METRIC_ID, DEPENDENCIES_DURATION); diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/ExtractorHelper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/ExtractorHelper.java index 796527deb6d..ad2dc6a7869 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/ExtractorHelper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/ExtractorHelper.java @@ -24,6 +24,7 @@ import com.azure.monitor.opentelemetry.exporter.implementation.builders.MetricTelemetryBuilder; import com.azure.monitor.opentelemetry.exporter.implementation.models.ContextTagKeys; import java.util.Map; +import javax.annotation.Nullable; public final class ExtractorHelper { @@ -36,7 +37,7 @@ public final class ExtractorHelper { public static final String CLOUD_ROLE_NAME = "cloud/roleName"; public static final String CLOUD_ROLE_INSTANCE = "cloud/roleInstance"; - static void extractCommon(MetricTelemetryBuilder metricBuilder, Boolean isSynthetic) { + static void extractCommon(MetricTelemetryBuilder metricBuilder, @Nullable Boolean isSynthetic) { metricBuilder.addProperty(MS_IS_AUTOCOLLECTED, TRUE); Map tags = metricBuilder.build().getTags(); if (tags != null) { diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java index f269b7a55e2..41d9121a350 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/preaggregatedmetrics/RequestExtractor.java @@ -27,6 +27,7 @@ import static com.azure.monitor.opentelemetry.exporter.implementation.preaggregatedmetrics.ExtractorHelper.extractCommon; import com.azure.monitor.opentelemetry.exporter.implementation.builders.MetricTelemetryBuilder; +import javax.annotation.Nullable; public final class RequestExtractor { @@ -36,7 +37,10 @@ public final class RequestExtractor { public static final String REQUEST_SUCCESS = "request/success"; public static void extract( - MetricTelemetryBuilder metricBuilder, Long statusCode, boolean success, Boolean isSynthetic) { + MetricTelemetryBuilder metricBuilder, + @Nullable Long statusCode, + boolean success, + @Nullable Boolean isSynthetic) { extractCommon(metricBuilder, isSynthetic); metricBuilder.addProperty(MS_METRIC_ID, REQUESTS_DURATION); diff --git a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java index 9c9ce94a756..f1a1bcf5287 100644 --- a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java +++ b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java @@ -192,12 +192,14 @@ private static void validateMetricData(String type, MetricData metricData, Strin Map properties = metricData.getProperties(); String expectedSuccess = "200".equals(resultCode) ? "True" : "False"; if ("client".equals(type)) { + assertThat(properties).hasSize(9); assertThat(properties.get("_MS.MetricId")).isEqualTo("dependencies/duration"); assertThat(properties.get("dependency/resultCode")).isEqualTo(resultCode); assertThat(properties.get("dependency/success")).isEqualTo(expectedSuccess); - assertThat(properties.get("dependency/target")).isNotNull(); + assertThat(properties.get("dependency/target")).isEqualTo("mock.codes"); assertThat(properties.get("dependency/type")).isEqualTo("http"); } else { + assertThat(properties).hasSize(7); assertThat(properties.get("_MS.MetricId")).isEqualTo("requests/duration"); assertThat(properties.get("request/resultCode")).isEqualTo(resultCode); assertThat(properties.get("request/success")).isEqualTo(expectedSuccess); diff --git a/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java b/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java index 7cd2a9fca17..947cebf3124 100644 --- a/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java +++ b/smoke-tests/apps/gRPC/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/GrpcTest.java @@ -215,13 +215,13 @@ private static void validateMetricData(String type, MetricData metricData) { assertThat(dataPoint.getMin()).isGreaterThan(0d).isLessThan(5 * 60 * 1000d); // (0 - 5) min Map properties = metricData.getProperties(); if ("client".equals(type)) { - assertThat(properties.get("dependency/resultCode")).isNull(); + assertThat(properties).hasSize(8); assertThat(properties.get("_MS.MetricId")).isEqualTo("dependencies/duration"); - assertThat(properties.get("dependency/target")).isNotNull(); + assertThat(properties.get("dependency/target")).isEqualTo("localhost:10203"); assertThat(properties.get("dependency/type")).isEqualTo("grpc"); } else { + assertThat(properties).hasSize(6); assertThat(properties.get("_MS.MetricId")).isEqualTo("requests/duration"); - assertThat(properties.get("request/resultCode")).isNull(); assertThat(properties.get("request/success")).isEqualTo("True"); } assertThat(properties.get("operation/synthetic")).isEqualTo("False"); From 9f77259ba7ebc2296b8e6536b8577169ddaa56f2 Mon Sep 17 00:00:00 2001 From: Helen Yang Date: Thu, 25 Aug 2022 16:40:40 -0700 Subject: [PATCH 95/95] Use 'Http' for dependency type --- .../opentelemetry/exporter/implementation/MetricDataMapper.java | 2 +- .../opentelemetry/exporter/PreAggregatedMetricsTest.java | 2 +- .../smoketest/HttpPreaggregatedMetricsSmokeTest.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java index 3b06554e3d2..b33a72c2a07 100644 --- a/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java +++ b/agent/azure-monitor-exporter/src/main/java/com/azure/monitor/opentelemetry/exporter/implementation/MetricDataMapper.java @@ -172,7 +172,7 @@ public static void updateMetricPointBuilder( } else if (metricData.getName().contains(".client.")) { String dependencyType = metricData.getName().startsWith("http") - ? "http" + ? "Http" : pointData.getAttributes().get(SemanticAttributes.RPC_SYSTEM); String target = pointData.getAttributes().get(TARGET); DependencyExtractor.extract( diff --git a/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java index dbdca09afef..bcfb1316c68 100644 --- a/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java +++ b/agent/azure-monitor-exporter/src/test/java/com/azure/monitor/opentelemetry/exporter/PreAggregatedMetricsTest.java @@ -333,7 +333,7 @@ private static Map generateExpectedDependencyCustomDimensions(St expectedMap.put(OPERATION_SYNTHETIC, FALSE); expectedMap.put(DEPENDENCY_SUCCESS, TRUE); if ("http".equals(type)) { - expectedMap.put(DEPENDENCY_TYPE, "http"); + expectedMap.put(DEPENDENCY_TYPE, "Http"); expectedMap.put(DEPENDENCY_RESULT_CODE, "200"); } else { expectedMap.put(DEPENDENCY_TYPE, "grpc"); diff --git a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java index f1a1bcf5287..12d04244fe0 100644 --- a/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java +++ b/smoke-tests/apps/HttpPreaggregatedMetrics/src/smokeTest/java/com/microsoft/applicationinsights/smoketest/HttpPreaggregatedMetricsSmokeTest.java @@ -197,7 +197,7 @@ private static void validateMetricData(String type, MetricData metricData, Strin assertThat(properties.get("dependency/resultCode")).isEqualTo(resultCode); assertThat(properties.get("dependency/success")).isEqualTo(expectedSuccess); assertThat(properties.get("dependency/target")).isEqualTo("mock.codes"); - assertThat(properties.get("dependency/type")).isEqualTo("http"); + assertThat(properties.get("dependency/type")).isEqualTo("Http"); } else { assertThat(properties).hasSize(7); assertThat(properties.get("_MS.MetricId")).isEqualTo("requests/duration");