|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +package com.microsoft.applicationinsights.smoketest; |
| 5 | + |
| 6 | +import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_8; |
| 7 | +import static org.assertj.core.api.Assertions.assertThat; |
| 8 | + |
| 9 | +import com.microsoft.applicationinsights.smoketest.schemav2.Data; |
| 10 | +import com.microsoft.applicationinsights.smoketest.schemav2.Envelope; |
| 11 | +import com.microsoft.applicationinsights.smoketest.schemav2.ExceptionData; |
| 12 | +import com.microsoft.applicationinsights.smoketest.schemav2.RequestData; |
| 13 | +import java.util.List; |
| 14 | +import org.junit.jupiter.api.Test; |
| 15 | +import org.junit.jupiter.api.extension.RegisterExtension; |
| 16 | + |
| 17 | +@Environment(TOMCAT_8_JAVA_8) |
| 18 | +@UseAgent("level_off_applicationinsights.json") |
| 19 | +class LogbackLevelOffTest { |
| 20 | + |
| 21 | + @RegisterExtension static final SmokeTestExtension testing = SmokeTestExtension.create(); |
| 22 | + |
| 23 | + @Test |
| 24 | + @TargetUri("/test") |
| 25 | + void testDisabled() throws Exception { |
| 26 | + List<Envelope> rdList = testing.mockedIngestion.waitForItems("RequestData", 1); |
| 27 | + |
| 28 | + Envelope rdEnvelope = rdList.get(0); |
| 29 | + RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData(); |
| 30 | + assertThat(rd.getName()).isEqualTo("GET /Logback/test"); |
| 31 | + |
| 32 | + assertThat(testing.mockedIngestion.getCountForType("MessageData")).isZero(); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + @TargetUri("/testWithSpanException") |
| 37 | + void testWithSpanException() throws Exception { |
| 38 | + List<Envelope> rdList = testing.mockedIngestion.waitForItems("RequestData", 1); |
| 39 | + |
| 40 | + Envelope rdEnvelope = rdList.get(0); |
| 41 | + RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData(); |
| 42 | + assertThat(rd.getName()).isEqualTo("GET /Logback/testWithSpanException"); |
| 43 | + |
| 44 | + assertThat(testing.mockedIngestion.getCountForType("MessageData")).isZero(); |
| 45 | + |
| 46 | + // check that span exception is still captured |
| 47 | + String operationId = rdEnvelope.getTags().get("ai.operation.id"); |
| 48 | + List<Envelope> edList = |
| 49 | + testing.mockedIngestion.waitForItemsInOperation("ExceptionData", 1, operationId); |
| 50 | + |
| 51 | + Envelope edEnvelope = edList.get(0); |
| 52 | + ExceptionData ed = (ExceptionData) ((Data<?>) edEnvelope.getData()).getBaseData(); |
| 53 | + |
| 54 | + assertThat(ed.getExceptions().get(0).getTypeName()).isEqualTo("java.lang.RuntimeException"); |
| 55 | + assertThat(ed.getExceptions().get(0).getMessage()).isEqualTo("Test Exception"); |
| 56 | + assertThat(ed.getProperties()).isEmpty(); // this is not a logger-based exception |
| 57 | + |
| 58 | + SmokeTestExtension.assertParentChild( |
| 59 | + rd, rdEnvelope, edEnvelope, "GET /Logback/testWithSpanException"); |
| 60 | + } |
| 61 | +} |
0 commit comments