From 993f6f53fd1d344b96bb1ae39fe0a53edbe4640f Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Wed, 1 Jun 2022 13:28:01 -0700 Subject: [PATCH] Don't capture exception records on dependencies (#2307) --- .../exporter/implementation/SpanDataMapper.java | 15 ++++++++++----- .../SpringBootControllerSpansEnabledTest.java | 4 ++-- 2 files changed, 12 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 8241a1064ba..fa94ee873be 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 @@ -32,6 +32,7 @@ import com.azure.monitor.opentelemetry.exporter.implementation.builders.RemoteDependencyTelemetryBuilder; import com.azure.monitor.opentelemetry.exporter.implementation.builders.RequestTelemetryBuilder; import com.azure.monitor.opentelemetry.exporter.implementation.models.ContextTagKeys; +import com.azure.monitor.opentelemetry.exporter.implementation.models.RequestData; import com.azure.monitor.opentelemetry.exporter.implementation.models.TelemetryItem; import com.azure.monitor.opentelemetry.exporter.implementation.utils.FormattedDuration; import com.azure.monitor.opentelemetry.exporter.implementation.utils.FormattedTime; @@ -166,6 +167,7 @@ public void map(SpanData span, Consumer consumer) { consumer.accept(telemetryItem); exportEvents( span, + telemetryItem.getData().getBaseData() instanceof RequestData, telemetryItem.getTags().get(ContextTagKeys.AI_OPERATION_NAME.toString()), samplingPercentage, consumer); @@ -775,6 +777,7 @@ private static String nullAwareConcat( private void exportEvents( SpanData span, + boolean captureExceptionEvents, @Nullable String operationName, float samplingPercentage, Consumer consumer) { @@ -786,11 +789,13 @@ private void exportEvents( if (event.getAttributes().get(SemanticAttributes.EXCEPTION_TYPE) != null || event.getAttributes().get(SemanticAttributes.EXCEPTION_MESSAGE) != null) { - // TODO (trask) map OpenTelemetry exception to Application Insights exception better - String stacktrace = event.getAttributes().get(SemanticAttributes.EXCEPTION_STACKTRACE); - if (stacktrace != null) { - consumer.accept( - createExceptionTelemetryItem(stacktrace, span, operationName, samplingPercentage)); + if (captureExceptionEvents) { + // TODO (trask) map OpenTelemetry exception to Application Insights exception better + String stacktrace = event.getAttributes().get(SemanticAttributes.EXCEPTION_STACKTRACE); + if (stacktrace != null) { + consumer.accept( + createExceptionTelemetryItem(stacktrace, span, operationName, samplingPercentage)); + } } return; } 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 a0363f89fa2..345d171bdd2 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 @@ -131,7 +131,7 @@ public boolean test(Envelope input) { return !data.getProperties().containsKey("LoggerName"); } }, - 2, + 1, 10, TimeUnit.SECONDS); assertEquals(0, mockedIngestion.getCountForType("EventData")); @@ -155,8 +155,8 @@ public boolean test(Envelope input) { assertTrue(rdd1.getProperties().isEmpty()); assertFalse(rdd1.getSuccess()); + assertParentChild(rd, rdEnvelope, edEnvelope1, "GET /SpringBootTest/throwsException"); assertParentChild(rd, rdEnvelope, rddEnvelope1, "GET /SpringBootTest/throwsException"); - assertParentChild(rdd1, rddEnvelope1, edEnvelope1, "GET /SpringBootTest/throwsException"); } @Test