From 3049b4d652ed19e8b6377c23d064b8cb9f417191 Mon Sep 17 00:00:00 2001 From: Vaibhav Khamgaonkar Date: Mon, 18 Sep 2023 21:19:26 +0530 Subject: [PATCH 1/6] feat: fixed leak --- ...panExporterWithAttributeProcessorTest.java | 1354 ++++++++--------- 1 file changed, 677 insertions(+), 677 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 002dddc210a..2f0a4edf30e 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 @@ -91,22 +91,22 @@ void actionDeleteTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); - - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("TESTKEY", "testValue2") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); + try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("TESTKEY", "testValue2") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); + } // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -129,22 +129,22 @@ void actionInsertTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); - - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("TESTKEY", "testValue2") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); + try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("TESTKEY", "testValue2") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); + } // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -171,22 +171,22 @@ void actionInsertAndUpdateTest() { actions.add(action); actions.add(updateAction); config.actions = actions; - SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); - - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("TESTKEY", "testValue2") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); + try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("TESTKEY", "testValue2") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); + } // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -215,22 +215,22 @@ void actionInsertAndUpdateSameAttributeTest() { actions.add(action); actions.add(updateAction); config.actions = actions; - SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); - - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("TESTKEY", "testValue2") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); + try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("TESTKEY", "testValue2") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); + } // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -253,22 +253,22 @@ void actionInsertWithDuplicateTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); - - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("TESTKEY", "testValue2") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); + try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("TESTKEY", "testValue2") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); + } // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -292,23 +292,23 @@ void actionInsertFromAttributeTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); - - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("TESTKEY", "testValue2") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); + try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("TESTKEY", "testValue2") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); + } // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -332,34 +332,34 @@ void actionSimpleUpdateTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); - - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("TESTKEY", "testValue2") - .startSpan(); - - Span log = - tracer - .spanBuilder("my log") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("TESTKEY", "testValue2") - .setAttribute("applicationinsights.internal.log", true) - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - SpanData logData = ((ReadableSpan) log).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - spans.add(logData); - exampleExporter.export(spans); + try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("TESTKEY", "testValue2") + .startSpan(); + + Span log = + tracer + .spanBuilder("my log") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("TESTKEY", "testValue2") + .setAttribute("applicationinsights.internal.log", true) + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + SpanData logData = ((ReadableSpan) log).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + spans.add(logData); + exampleExporter.export(spans); + } // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -383,22 +383,22 @@ void actionUpdateFromAttributeUpdateTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); - - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); + try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); + } // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -422,22 +422,22 @@ void complexActionTest() { actions.add(updateAction); actions.add(deleteAction); config.actions = actions; - SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); - - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); + try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); + } // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -462,46 +462,46 @@ void simpleIncludeTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); - - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanC = - tracer - .spanBuilder("svcC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("svcD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - - exampleExporter.export(spans); + try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanC = + tracer + .spanBuilder("svcC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("svcD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + + exampleExporter.export(spans); + } // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -534,56 +534,56 @@ void simpleIncludeWithSpanNamesTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); - - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanC = - tracer - .spanBuilder("svcC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("svcD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span logA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .setAttribute("applicationinsights.internal.log", true) - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - spans.add(((ReadableSpan) logA).toSpanData()); - - exampleExporter.export(spans); + try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanC = + tracer + .spanBuilder("svcC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("svcD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span logA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .setAttribute("applicationinsights.internal.log", true) + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + spans.add(((ReadableSpan) logA).toSpanData()); + + exampleExporter.export(spans); + } // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -617,46 +617,46 @@ void simpleIncludeRegexTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); - - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanC = - tracer - .spanBuilder("serviceC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("serviceD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - - exampleExporter.export(spans); + try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanC = + tracer + .spanBuilder("serviceC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("serviceD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + + exampleExporter.export(spans); + } // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -713,54 +713,54 @@ void simpleIncludeRegexValueTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); - - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue1") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue2") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanC = - tracer - .spanBuilder("serviceC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("serviceD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanE = - tracer - .spanBuilder("svcE") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testV1") - .setAttribute("testKey2", "testValue2") - .startSpan(); - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - spans.add(((ReadableSpan) spanE).toSpanData()); - - exampleExporter.export(spans); + try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue1") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue2") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanC = + tracer + .spanBuilder("serviceC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("serviceD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanE = + tracer + .spanBuilder("svcE") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testV1") + .setAttribute("testKey2", "testValue2") + .startSpan(); + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + spans.add(((ReadableSpan) spanE).toSpanData()); + + exampleExporter.export(spans); + } // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -800,54 +800,54 @@ void simpleIncludeRegexNoValueTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); - - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue1") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue2") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanC = - tracer - .spanBuilder("serviceC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("serviceD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanE = - tracer - .spanBuilder("svcE") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testV1") - .setAttribute("testKey2", "testValue2") - .startSpan(); - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - spans.add(((ReadableSpan) spanE).toSpanData()); - - exampleExporter.export(spans); + try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue1") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue2") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanC = + tracer + .spanBuilder("serviceC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("serviceD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanE = + tracer + .spanBuilder("svcE") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testV1") + .setAttribute("testKey2", "testValue2") + .startSpan(); + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + spans.add(((ReadableSpan) spanE).toSpanData()); + + exampleExporter.export(spans); + } // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -883,46 +883,46 @@ void simpleIncludeHashTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); - - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", 2L) - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanC = - tracer - .spanBuilder("svcC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("svcD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - - exampleExporter.export(spans); + try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", 2L) + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanC = + tracer + .spanBuilder("svcC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("svcD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + + exampleExporter.export(spans); + } // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -955,46 +955,46 @@ void simpleExcludeTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); - - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanC = - tracer - .spanBuilder("svcC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("svcD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - - exampleExporter.export(spans); + try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanC = + tracer + .spanBuilder("svcC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("svcD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + + exampleExporter.export(spans); + } // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -1027,46 +1027,46 @@ void simpleExcludeRegexTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); - - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanC = - tracer - .spanBuilder("serviceC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("serviceD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - - exampleExporter.export(spans); + try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanC = + tracer + .spanBuilder("serviceC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("serviceD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + + exampleExporter.export(spans); + } // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -1107,46 +1107,46 @@ void multiIncludeTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); - - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue") - .setAttribute("testKey3", "testValue3") - .startSpan(); - Span spanC = - tracer - .spanBuilder("svcC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("svcD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - - exampleExporter.export(spans); + try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue") + .setAttribute("testKey3", "testValue3") + .startSpan(); + Span spanC = + tracer + .spanBuilder("svcC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("svcD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + + exampleExporter.export(spans); + } // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -1186,46 +1186,46 @@ void multiExcludeTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); - - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue") - .setAttribute("testKey3", "testValue2") - .startSpan(); - Span spanC = - tracer - .spanBuilder("svcC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("svcD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - - exampleExporter.export(spans); + try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue") + .setAttribute("testKey3", "testValue2") + .startSpan(); + Span spanC = + tracer + .spanBuilder("svcC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("svcD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + + exampleExporter.export(spans); + } // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -1262,46 +1262,46 @@ void selectiveProcessingTest() { // With both include and exclude List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); - - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue1") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanC = - tracer - .spanBuilder("svcC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("svcD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - - exampleExporter.export(spans); + try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue1") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanC = + tracer + .spanBuilder("svcC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("svcD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + + exampleExporter.export(spans); + } // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -1332,23 +1332,23 @@ void actionInsertWithExtractTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); - - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute( - "testKey", "http://example.com/path?queryParam1=value1,queryParam2=value2") - .setAttribute("TESTKEY", "testValue2") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); + try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute( + "testKey", "http://example.com/path?queryParam1=value1,queryParam2=value2") + .setAttribute("TESTKEY", "testValue2") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); + } // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -1379,23 +1379,23 @@ void actionInsertWithExtractDuplicateTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); - - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute( - "testKey", "http://example.com/path?queryParam1=value1,queryParam2=value2") - .setAttribute("httpPath", "oldPath") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); + try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute( + "testKey", "http://example.com/path?queryParam1=value1,queryParam2=value2") + .setAttribute("httpPath", "oldPath") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); + } // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -1457,26 +1457,26 @@ void actionInsertWithMaskTest() { actions.add(action4); actions.add(action5); config.actions = actions; - SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); - - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "http://example.com/cardid/1234562222227899") - .setAttribute("testKey2", "http://example.com/cardid/1234562222227899") - .setAttribute("testKey3", "http://example.com/cardid/1234562222227899") - .setAttribute("TESTKEY2", "testValue2") - .setAttribute("testKey4", "/TelemetryProcessors/test") - .setAttribute("testKey5", "/abc/xyz") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); + try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "http://example.com/cardid/1234562222227899") + .setAttribute("testKey2", "http://example.com/cardid/1234562222227899") + .setAttribute("testKey3", "http://example.com/cardid/1234562222227899") + .setAttribute("TESTKEY2", "testValue2") + .setAttribute("testKey4", "/TelemetryProcessors/test") + .setAttribute("testKey5", "/abc/xyz") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); + } // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); From 7e16cee406cb793118781db9ef0aec44bc2ca1b7 Mon Sep 17 00:00:00 2001 From: Vaibhav Khamgaonkar Date: Mon, 18 Sep 2023 22:18:31 +0530 Subject: [PATCH 2/6] scanner fixed --- .../gcmonitortests/GcEventGenerator.java | 99 ++++++++++--------- 1 file changed, 50 insertions(+), 49 deletions(-) diff --git a/agent/agent-gc-monitor/gc-monitor-tests/src/test/java/com/microsoft/gcmonitortests/GcEventGenerator.java b/agent/agent-gc-monitor/gc-monitor-tests/src/test/java/com/microsoft/gcmonitortests/GcEventGenerator.java index 2f38996aa4a..0f1bde5c85e 100644 --- a/agent/agent-gc-monitor/gc-monitor-tests/src/test/java/com/microsoft/gcmonitortests/GcEventGenerator.java +++ b/agent/agent-gc-monitor/gc-monitor-tests/src/test/java/com/microsoft/gcmonitortests/GcEventGenerator.java @@ -29,65 +29,66 @@ public static void main(String[] args) throws InterruptedException { private void run() throws InterruptedException { System.out.println("Hit return to start"); - // Block until consumer sends the ready signal - Scanner scanner = new Scanner(System.in, UTF_8.name()); - System.out.println(scanner.nextLine()); + try (// Block until consumer sends the ready signal + Scanner scanner = new Scanner(System.in, UTF_8.name())) { + System.out.println(scanner.nextLine()); - // Allocate 1mb - for (int i = 0; i < 1024; i++) { - memory.add(new MemoryConsumer(CHUNK_SIZE)); - } - - // Create 100mb of transient memory, invoking a number of YG gc's and promoting some to OG - for (int i = 0; i < 100 * 1024; i++) { - singleMemory = new MemoryConsumer(CHUNK_SIZE); - } - - // Run full GC - System.gc(); - - // Allocate 30mb, 25% of which is transient - for (int i = 0; i < 30 * 1024; i++) { - if ((i % 4) == 0) { - singleMemory = new MemoryConsumer(CHUNK_SIZE); - } else { + // Allocate 1mb + for (int i = 0; i < 1024; i++) { memory.add(new MemoryConsumer(CHUNK_SIZE)); } - } // Heap at 23.5mb - // Create 100mb of transient memory, invoking a number of YG gc's and promoting 40mb to OG - for (int i = 0; i < 100 * 1024; i++) { - singleMemory = new MemoryConsumer(CHUNK_SIZE); - } - - // free up 10mb - for (int i = 0; i < 10 * 1024; i++) { - memory.remove(0); - } // Heap at 13.5mb - - // Allocate 43mb, 50% of which is transient - for (int i = 0; i < 43 * 1024; i++) { - if ((i % 2) == 0) { + // Create 100mb of transient memory, invoking a number of YG gc's and promoting some to OG + for (int i = 0; i < 100 * 1024; i++) { singleMemory = new MemoryConsumer(CHUNK_SIZE); - } else { - memory.add(new MemoryConsumer(CHUNK_SIZE)); } - } // Heap at 35mb - // free up everything - memory.clear(); + // Run full GC + System.gc(); - // Run full GC - System.gc(); - // free up everything - memory.clear(); - // Run full GC - System.gc(); + // Allocate 30mb, 25% of which is transient + for (int i = 0; i < 30 * 1024; i++) { + if ((i % 4) == 0) { + singleMemory = new MemoryConsumer(CHUNK_SIZE); + } else { + memory.add(new MemoryConsumer(CHUNK_SIZE)); + } + } // Heap at 23.5mb - // Seems if the JVM exits too quickly MX beans do not report, give it some time + // Create 100mb of transient memory, invoking a number of YG gc's and promoting 40mb to OG + for (int i = 0; i < 100 * 1024; i++) { + singleMemory = new MemoryConsumer(CHUNK_SIZE); + } - System.out.println("Hit return to exit"); - System.out.println(scanner.nextLine()); + // free up 10mb + for (int i = 0; i < 10 * 1024; i++) { + memory.remove(0); + } // Heap at 13.5mb + + // Allocate 43mb, 50% of which is transient + for (int i = 0; i < 43 * 1024; i++) { + if ((i % 2) == 0) { + singleMemory = new MemoryConsumer(CHUNK_SIZE); + } else { + memory.add(new MemoryConsumer(CHUNK_SIZE)); + } + } // Heap at 35mb + + // free up everything + memory.clear(); + + // Run full GC + System.gc(); + // free up everything + memory.clear(); + // Run full GC + System.gc(); + + // Seems if the JVM exits too quickly MX beans do not report, give it some time + + System.out.println("Hit return to exit"); + System.out.println(scanner.nextLine()); + } } static class MemoryConsumer { From d05168f7793da75369d26d3e7da130276b6f50f4 Mon Sep 17 00:00:00 2001 From: Vaibhav Khamgaonkar Date: Mon, 18 Sep 2023 22:29:04 +0530 Subject: [PATCH 3/6] scanner fixed --- .../ExporterWithLogProcessorTest.java | 170 +-- .../ExporterWithSpanProcessorTest.java | 384 ++--- ...LogExporterWithAttributeProcessorTest.java | 1275 ++++++++--------- 3 files changed, 905 insertions(+), 924 deletions(-) diff --git a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/ExporterWithLogProcessorTest.java b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/ExporterWithLogProcessorTest.java index 4fddc756373..111207a5a0f 100644 --- a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/ExporterWithLogProcessorTest.java +++ b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/ExporterWithLogProcessorTest.java @@ -75,13 +75,13 @@ void simpleRenameLogMessageTest() { config.id = "SimpleRenameLogMessage"; config.body = new NameConfig(); config.body.fromAttributes = Arrays.asList("db.svc", "operation", "id"); - LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter); - TestLogRecordData mockLog = - TestLogRecordData.builder().setBody("logA").setAttributes(attributes).build(); - List logs = new ArrayList<>(); - logs.add(mockLog); - logExporter.export(logs); - + try (LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter)) { + TestLogRecordData mockLog = + TestLogRecordData.builder().setBody("logA").setAttributes(attributes).build(); + List logs = new ArrayList<>(); + logs.add(mockLog); + logExporter.export(logs); + } // verify that resulting logs are filtered in the way we want List result = mockExporter.getLogs(); LogRecordData resultLog = result.get(0); @@ -94,13 +94,13 @@ void simpleRenameLogWithSeparatorTest() { config.body = new NameConfig(); config.body.fromAttributes = Arrays.asList("db.svc", "operation", "id"); config.body.separator = "::"; - LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter); - TestLogRecordData mockLog = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributes).build(); - List logs = new ArrayList<>(); - logs.add(mockLog); - logExporter.export(logs); - + try (LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter)) { + TestLogRecordData mockLog = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributes).build(); + List logs = new ArrayList<>(); + logs.add(mockLog); + logExporter.export(logs); + } // verify that resulting logs are filtered in the way we want List result = mockExporter.getLogs(); LogRecordData resultLog = result.get(0); @@ -113,13 +113,13 @@ void simpleRenameLogWithMissingKeysTest() { config.body = new NameConfig(); config.body.fromAttributes = Arrays.asList("db.svc", "operation", "id"); config.body.separator = "::"; - LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter); - - TestLogRecordData mockLog = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributes).build(); - List logs = new ArrayList<>(); - logs.add(mockLog); - logExporter.export(logs); + try (LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter)) { + TestLogRecordData mockLog = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributes).build(); + List logs = new ArrayList<>(); + logs.add(mockLog); + logExporter.export(logs); + } // verify that resulting logs are filtered in the way we want List result = mockExporter.getLogs(); @@ -148,16 +148,16 @@ void simpleToAttributesTest() { toAttributeConfig.rules = new ArrayList<>(); toAttributeConfig.rules.add("^/api/v1/document/(?.*)/update$"); config.body.toAttributes = toAttributeConfig; - LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter); - TestLogRecordData mockLog = - TestLogRecordData.builder() - .setBody("/api/v1/document/12345678/update") - .setAttributes(attributes) - .build(); - List logs = new ArrayList<>(); - logs.add(mockLog); - logExporter.export(logs); - + try (LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter)) { + TestLogRecordData mockLog = + TestLogRecordData.builder() + .setBody("/api/v1/document/12345678/update") + .setAttributes(attributes) + .build(); + List logs = new ArrayList<>(); + logs.add(mockLog); + logExporter.export(logs); + } // verify that resulting logs are filtered in the way we want List result = mockExporter.getLogs(); LogRecordData resultLog = result.get(0); @@ -181,33 +181,33 @@ void multiRuleToAttributesTest() { toAttributeConfig.rules.add("Password=(?[^ ]+)"); toAttributeConfig.rules.add("Pass=(?[^ ]+)"); config.body.toAttributes = toAttributeConfig; - LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter); - TestLogRecordData mockLogA = - TestLogRecordData.builder() - .setBody("yyyPassword=123 aba Pass=555 xyx Pass=777 zzz") - .setAttributes(attributes) - .build(); - - Attributes attributesB = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("db.svc", "location") - .put("operation", "get") - .put("id", "1234") - .put("password", "234") - .build(); - TestLogRecordData mockLogB = - TestLogRecordData.builder() - .setBody("yyyPassword=**** aba") - .setAttributes(attributesB) - .build(); - - List logs = new ArrayList<>(); - logs.add(mockLogA); - logs.add(mockLogB); - logExporter.export(logs); - + try (LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter)) { + TestLogRecordData mockLogA = + TestLogRecordData.builder() + .setBody("yyyPassword=123 aba Pass=555 xyx Pass=777 zzz") + .setAttributes(attributes) + .build(); + + Attributes attributesB = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("db.svc", "location") + .put("operation", "get") + .put("id", "1234") + .put("password", "234") + .build(); + TestLogRecordData mockLogB = + TestLogRecordData.builder() + .setBody("yyyPassword=**** aba") + .setAttributes(attributesB) + .build(); + + List logs = new ArrayList<>(); + logs.add(mockLogA); + logs.add(mockLogB); + logExporter.export(logs); + } // verify that resulting logs are filtered in the way we want List result = mockExporter.getLogs(); LogRecordData resultA = result.get(0); @@ -249,17 +249,17 @@ void multiMatch() { toAttributeConfig.rules = new ArrayList<>(); toAttributeConfig.rules.add("Password=(?[^ ]+)"); config.body.toAttributes = toAttributeConfig; - LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter); - TestLogRecordData mockLogA = - TestLogRecordData.builder() - .setBody("yyyPassword=123 aba Password=555 xyx") - .setAttributes(attributes) - .build(); - - List logs = new ArrayList<>(); - logs.add(mockLogA); - logExporter.export(logs); - + try (LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter)) { + TestLogRecordData mockLogA = + TestLogRecordData.builder() + .setBody("yyyPassword=123 aba Password=555 xyx") + .setAttributes(attributes) + .build(); + + List logs = new ArrayList<>(); + logs.add(mockLogA); + logExporter.export(logs); + } // verify that resulting logs are filtered in the way we want List result = mockExporter.getLogs(); LogRecordData resultA = result.get(0); @@ -272,22 +272,22 @@ void simpleRenameLogTestWithLogProcessor() { config.id = "SimpleRenameLog"; config.body = new NameConfig(); config.body.fromAttributes = Arrays.asList("db.svc", "operation", "id"); - LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter); - - Attributes newAttributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("db.svc", "location") - .put("operation", "get") - .put("id", "1234") - .build(); - TestLogRecordData mockLog = - TestLogRecordData.builder().setBody("svcA").setAttributes(newAttributes).build(); - - List logs = new ArrayList<>(); - logs.add(mockLog); - logExporter.export(logs); + try (LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter)) { + Attributes newAttributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("db.svc", "location") + .put("operation", "get") + .put("id", "1234") + .build(); + TestLogRecordData mockLog = + TestLogRecordData.builder().setBody("svcA").setAttributes(newAttributes).build(); + + List logs = new ArrayList<>(); + logs.add(mockLog); + logExporter.export(logs); + } // verify that resulting logs are not modified List result = mockExporter.getLogs(); diff --git a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/ExporterWithSpanProcessorTest.java b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/ExporterWithSpanProcessorTest.java index 5003f3138f5..11104a20c2d 100644 --- a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/ExporterWithSpanProcessorTest.java +++ b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/ExporterWithSpanProcessorTest.java @@ -74,23 +74,23 @@ void simpleRenameSpanTest() { config.id = "SimpleRenameSpan"; config.name = new NameConfig(); config.name.fromAttributes = Arrays.asList("db.svc", "operation", "id"); - SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter); - - Span span = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); + try (SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter)) { + Span span = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); + } // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -107,23 +107,23 @@ void simpleRenameSpanWithSeparatorTest() { config.name = new NameConfig(); config.name.fromAttributes = Arrays.asList("db.svc", "operation", "id"); config.name.separator = "::"; - SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter); - - Span span = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); + try (SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter)) { + Span span = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); + } // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -140,22 +140,22 @@ void simpleRenameSpanWithMissingKeysTest() { config.name = new NameConfig(); config.name.fromAttributes = Arrays.asList("db.svc", "operation", "id"); config.name.separator = "::"; - SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter); - - Span span = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); + try (SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter)) { + Span span = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); + } // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -174,54 +174,54 @@ void renameSpanWithIncludeTest() { config.include = new ProcessorIncludeExclude(); config.include.matchType = MatchType.STRICT; config.include.spanNames = Arrays.asList("svcA", "svcB"); - SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter); - - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .startSpan(); - - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .startSpan(); - Span spanC = - tracer - .spanBuilder("svcC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .startSpan(); - Span spanD = - tracer - .spanBuilder("svcD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - - exampleExporter.export(spans); + try (SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter)) { + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .startSpan(); + + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .startSpan(); + Span spanC = + tracer + .spanBuilder("svcC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .startSpan(); + Span spanD = + tracer + .spanBuilder("svcD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + + exampleExporter.export(spans); + } // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -262,23 +262,23 @@ void simpleToAttributesTest() { toAttributeConfig.rules = new ArrayList<>(); toAttributeConfig.rules.add("^/api/v1/document/(?.*)/update$"); config.name.toAttributes = toAttributeConfig; - SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter); - - Span span = - tracer - .spanBuilder("/api/v1/document/12345678/update") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); + try (SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter)) { + Span span = + tracer + .spanBuilder("/api/v1/document/12345678/update") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); + } // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -306,35 +306,35 @@ void multiRuleToAttributesTest() { toAttributeConfig.rules.add("Password=(?[^ ]+)"); toAttributeConfig.rules.add("Pass=(?[^ ]+)"); config.name.toAttributes = toAttributeConfig; - SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter); - - Span spanA = - tracer - .spanBuilder("yyyPassword=123 aba Pass=555 xyx Pass=777 zzz") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .startSpan(); - Span spanB = - tracer - .spanBuilder("yyyPassword=**** aba") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .setAttribute("password", "234") - .startSpan(); - - SpanData spanDataA = ((ReadableSpan) spanA).toSpanData(); - SpanData spanDataB = ((ReadableSpan) spanB).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanDataA); - spans.add(spanDataB); - exampleExporter.export(spans); + try (SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter)) { + Span spanA = + tracer + .spanBuilder("yyyPassword=123 aba Pass=555 xyx Pass=777 zzz") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .startSpan(); + Span spanB = + tracer + .spanBuilder("yyyPassword=**** aba") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .setAttribute("password", "234") + .startSpan(); + + SpanData spanDataA = ((ReadableSpan) spanA).toSpanData(); + SpanData spanDataB = ((ReadableSpan) spanB).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanDataA); + spans.add(spanDataB); + exampleExporter.export(spans); + } // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -384,54 +384,54 @@ void extractAttributesWithIncludeExcludeTest() { config.exclude.spanNames = Arrays.asList("donot/change"); config.name.toAttributes = new ToAttributeConfig(); config.name.toAttributes.rules = Arrays.asList("(?.*?)/.*$"); - SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter); - - Span spanA = - tracer - .spanBuilder("svcA/test") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .startSpan(); - - Span spanB = - tracer - .spanBuilder("svcB/test") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .startSpan(); - Span spanC = - tracer - .spanBuilder("svcC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .startSpan(); - Span spanD = - tracer - .spanBuilder("donot/change") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - - exampleExporter.export(spans); + try (SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter)) { + Span spanA = + tracer + .spanBuilder("svcA/test") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .startSpan(); + + Span spanB = + tracer + .spanBuilder("svcB/test") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .startSpan(); + Span spanC = + tracer + .spanBuilder("svcC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .startSpan(); + Span spanD = + tracer + .spanBuilder("donot/change") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + + exampleExporter.export(spans); + } // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); diff --git a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/LogExporterWithAttributeProcessorTest.java b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/LogExporterWithAttributeProcessorTest.java index 14acd1f9453..cffdd4467f8 100644 --- a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/LogExporterWithAttributeProcessorTest.java +++ b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/LogExporterWithAttributeProcessorTest.java @@ -91,24 +91,23 @@ void actionDeleteTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter); - - Attributes attributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("TESTKEY", "testValue2") - .put("id", "1234") - .build(); - - TestLogRecordData mockLog = - TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); - - List logs = new ArrayList<>(); - logs.add(mockLog); - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("TESTKEY", "testValue2") + .put("id", "1234") + .build(); + + TestLogRecordData mockLog = + TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); + + List logs = new ArrayList<>(); + logs.add(mockLog); + exampleExporter.export(logs); + } // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -129,23 +128,22 @@ void actionInsertTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter); - - Attributes attributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("TESTKEY", "testValue2") - .build(); - - TestLogRecordData mockLog = - TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); - - List logs = new ArrayList<>(); - logs.add(mockLog); - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("TESTKEY", "testValue2") + .build(); + + TestLogRecordData mockLog = + TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); + + List logs = new ArrayList<>(); + logs.add(mockLog); + exampleExporter.export(logs); + } // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -168,23 +166,22 @@ void actionInsertAndUpdateTest() { actions.add(action); actions.add(updateAction); config.actions = actions; - LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter); - - Attributes attributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("TESTKEY", "testValue2") - .build(); - - TestLogRecordData mockLog = - TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); - - List logs = new ArrayList<>(); - logs.add(mockLog); - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("TESTKEY", "testValue2") + .build(); + + TestLogRecordData mockLog = + TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); + + List logs = new ArrayList<>(); + logs.add(mockLog); + exampleExporter.export(logs); + } // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -209,22 +206,21 @@ void actionInsertAndUpdateSameAttributeTest() { actions.add(action); actions.add(updateAction); config.actions = actions; - LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter); - - Attributes attributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("TESTKEY", "testValue2") - .build(); - TestLogRecordData log = - TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); - - List logs = new ArrayList<>(); - logs.add(log); - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("TESTKEY", "testValue2") + .build(); + TestLogRecordData log = + TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); + + List logs = new ArrayList<>(); + logs.add(log); + exampleExporter.export(logs); + } // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -243,22 +239,21 @@ void actionInsertWithDuplicateTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter); - - Attributes attributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("TESTKEY", "testValue2") - .build(); - TestLogRecordData log = - TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); - - List logs = new ArrayList<>(); - logs.add(log); - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("TESTKEY", "testValue2") + .build(); + TestLogRecordData log = + TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); + + List logs = new ArrayList<>(); + logs.add(log); + exampleExporter.export(logs); + } // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -278,23 +273,22 @@ void actionInsertFromAttributeTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter); - - Attributes attributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("TESTKEY", "testValue2") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData log = - TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); - - List logs = new ArrayList<>(); - logs.add(log); - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("TESTKEY", "testValue2") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData log = + TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); + + List logs = new ArrayList<>(); + logs.add(log); + exampleExporter.export(logs); + } // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -314,57 +308,56 @@ void actionSimpleUpdateLogAndSpanTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - LogRecordExporter logExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter); - - // set up log - Attributes attributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("TESTKEY", "testValue2") - .build(); - TestLogRecordData log = - TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); - - // set up span - Span span = - OpenTelemetrySdk.builder() - .build() - .getTracer("test") - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("TESTKEY", "testValue2") - .startSpan(); - - // export log - List logs = new ArrayList<>(); - logs.add(log); - logExporter.export(logs); - - // export span - MockSpanExporter mockSpanExporter = new MockSpanExporter(); - SpanExporter spanExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) span).toSpanData()); - spanExporter.export(spans); - - // retrieve updated log - List resultLogs = mockLoggerExporter.getLogs(); - LogRecordData resultLog = resultLogs.get(0); - - // retrieve updated span - List resultSpans = mockSpanExporter.getSpans(); - SpanData resultSpan = resultSpans.get(0); - - // verify that resulting logs are filtered in the way we want - assertThat(resultLog.getAttributes().get(AttributeKey.stringKey("testKey"))) - .isEqualTo("redacted"); - assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("testKey"))) - .isEqualTo("redacted"); + try (LogRecordExporter logExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + // set up log + Attributes attributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("TESTKEY", "testValue2") + .build(); + TestLogRecordData log = + TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); + + // set up span + Span span = + OpenTelemetrySdk.builder() + .build() + .getTracer("test") + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("TESTKEY", "testValue2") + .startSpan(); + + // export log + List logs = new ArrayList<>(); + logs.add(log); + logExporter.export(logs); + + // export span + MockSpanExporter mockSpanExporter = new MockSpanExporter(); + try (SpanExporter spanExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) span).toSpanData()); + spanExporter.export(spans); + } + // retrieve updated log + List resultLogs = mockLoggerExporter.getLogs(); + LogRecordData resultLog = resultLogs.get(0); + + // retrieve updated span + List resultSpans = mockSpanExporter.getSpans(); + SpanData resultSpan = resultSpans.get(0); + + // verify that resulting logs are filtered in the way we want + assertThat(resultLog.getAttributes().get(AttributeKey.stringKey("testKey"))) + .isEqualTo("redacted"); + assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("testKey"))) + .isEqualTo("redacted"); + } } @Test @@ -375,22 +368,21 @@ void actionUpdateFromAttributeUpdateTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter); - - Attributes attributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData log = - TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); - - List logs = new ArrayList<>(); - logs.add(log); - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData log = + TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); + + List logs = new ArrayList<>(); + logs.add(log); + exampleExporter.export(logs); + } // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -410,22 +402,21 @@ void complexActionTest() { actions.add(updateAction); actions.add(deleteAction); config.actions = actions; - LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter); - - Attributes attributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData log = - TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); - - List logs = new ArrayList<>(); - logs.add(log); - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData log = + TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); + + List logs = new ArrayList<>(); + logs.add(log); + exampleExporter.export(logs); + } // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -446,54 +437,53 @@ void simpleIncludeTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter); - - Attributes attributesA = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logA = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); - - Attributes attributesB = - Attributes.builder() - .put("one", "1") - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logB = - TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); - - Attributes attributesC = - Attributes.builder() - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logC = - TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); - - Attributes attributesD = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logD = - TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); - - List logs = new ArrayList<>(); - logs.add(logA); - logs.add(logB); - logs.add(logC); - logs.add(logD); - - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributesA = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logA = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); + + Attributes attributesB = + Attributes.builder() + .put("one", "1") + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logB = + TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); + + Attributes attributesC = + Attributes.builder() + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logC = + TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); + + Attributes attributesD = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logD = + TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); + + List logs = new ArrayList<>(); + logs.add(logA); + logs.add(logB); + logs.add(logC); + logs.add(logD); + + exampleExporter.export(logs); + } // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -523,54 +513,53 @@ void simpleIncludeWithLogNameTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter); - - Attributes attributesA = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logA = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); - - Attributes attributesB = - Attributes.builder() - .put("one", "1") - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logB = - TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); - - Attributes attributesC = - Attributes.builder() - .put("two", 2L) - .put("testKey", "testValueC") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logC = - TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); - - Attributes attributesD = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValueD") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logD = - TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); - - List logs = new ArrayList<>(); - logs.add(logA); - logs.add(logB); - logs.add(logC); - logs.add(logD); - - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributesA = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logA = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); + + Attributes attributesB = + Attributes.builder() + .put("one", "1") + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logB = + TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); + + Attributes attributesC = + Attributes.builder() + .put("two", 2L) + .put("testKey", "testValueC") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logC = + TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); + + Attributes attributesD = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValueD") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logD = + TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); + + List logs = new ArrayList<>(); + logs.add(logA); + logs.add(logB); + logs.add(logC); + logs.add(logD); + + exampleExporter.export(logs); + } // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -600,54 +589,53 @@ void simpleIncludeRegexTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter); - - Attributes attributesA = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logA = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); - - Attributes attributesB = - Attributes.builder() - .put("one", "1") - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logB = - TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); - - Attributes attributesC = - Attributes.builder() - .put("two", 2L) - .put("testKey", "testValueC") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logC = - TestLogRecordData.builder().setBody("serviceC").setAttributes(attributesC).build(); - - Attributes attributesD = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValueD") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logD = - TestLogRecordData.builder().setBody("serviceD").setAttributes(attributesD).build(); - - List logs = new ArrayList<>(); - logs.add(logA); - logs.add(logB); - logs.add(logC); - logs.add(logD); - - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributesA = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logA = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); + + Attributes attributesB = + Attributes.builder() + .put("one", "1") + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logB = + TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); + + Attributes attributesC = + Attributes.builder() + .put("two", 2L) + .put("testKey", "testValueC") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logC = + TestLogRecordData.builder().setBody("serviceC").setAttributes(attributesC).build(); + + Attributes attributesD = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValueD") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logD = + TestLogRecordData.builder().setBody("serviceD").setAttributes(attributesD).build(); + + List logs = new ArrayList<>(); + logs.add(logA); + logs.add(logB); + logs.add(logC); + logs.add(logD); + + exampleExporter.export(logs); + } // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -698,65 +686,64 @@ void simpleIncludeRegexValueTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter); - - Attributes attributesA = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logA = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); - - Attributes attributesB = - Attributes.builder() - .put("one", "1") - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logB = - TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); - - Attributes attributesC = - Attributes.builder() - .put("two", 2L) - .put("testKey", "testValueC") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logC = - TestLogRecordData.builder().setBody("serviceC").setAttributes(attributesC).build(); - - Attributes attributesD = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValueD") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logD = - TestLogRecordData.builder().setBody("serviceD").setAttributes(attributesD).build(); - - Attributes attributesE = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testV1") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logE = - TestLogRecordData.builder().setBody("svcE").setAttributes(attributesE).build(); - - List logs = new ArrayList<>(); - logs.add(logA); - logs.add(logB); - logs.add(logC); - logs.add(logD); - logs.add(logE); - - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributesA = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logA = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); + + Attributes attributesB = + Attributes.builder() + .put("one", "1") + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logB = + TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); + + Attributes attributesC = + Attributes.builder() + .put("two", 2L) + .put("testKey", "testValueC") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logC = + TestLogRecordData.builder().setBody("serviceC").setAttributes(attributesC).build(); + + Attributes attributesD = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValueD") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logD = + TestLogRecordData.builder().setBody("serviceD").setAttributes(attributesD).build(); + + Attributes attributesE = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testV1") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logE = + TestLogRecordData.builder().setBody("svcE").setAttributes(attributesE).build(); + + List logs = new ArrayList<>(); + logs.add(logA); + logs.add(logB); + logs.add(logC); + logs.add(logD); + logs.add(logE); + + exampleExporter.export(logs); + } // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -788,54 +775,53 @@ void simpleIncludeHashTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter); - - Attributes attributesA = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logA = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); - - Attributes attributesB = - Attributes.builder() - .put("one", "1") - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logB = - TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); - - Attributes attributesC = - Attributes.builder() - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logC = - TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); - - Attributes attributesD = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logD = - TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); - - List logs = new ArrayList<>(); - logs.add(logA); - logs.add(logB); - logs.add(logC); - logs.add(logD); - - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributesA = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logA = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); + + Attributes attributesB = + Attributes.builder() + .put("one", "1") + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logB = + TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); + + Attributes attributesC = + Attributes.builder() + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logC = + TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); + + Attributes attributesD = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logD = + TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); + + List logs = new ArrayList<>(); + logs.add(logA); + logs.add(logB); + logs.add(logC); + logs.add(logD); + + exampleExporter.export(logs); + } // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -865,54 +851,53 @@ void simpleExcludeTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter); - - Attributes attributesA = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logA = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); - - Attributes attributesB = - Attributes.builder() - .put("one", "1") - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logB = - TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); - - Attributes attributesC = - Attributes.builder() - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logC = - TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); - - Attributes attributesD = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logD = - TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); - - List logs = new ArrayList<>(); - logs.add(logA); - logs.add(logB); - logs.add(logC); - logs.add(logD); - - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributesA = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logA = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); + + Attributes attributesB = + Attributes.builder() + .put("one", "1") + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logB = + TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); + + Attributes attributesC = + Attributes.builder() + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logC = + TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); + + Attributes attributesD = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logD = + TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); + + List logs = new ArrayList<>(); + logs.add(logA); + logs.add(logB); + logs.add(logC); + logs.add(logD); + + exampleExporter.export(logs); + } // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -950,54 +935,53 @@ void multiIncludeTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter); - - Attributes attributesA = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logA = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); - - Attributes attributesB = - Attributes.builder() - .put("one", "1") - .put("testKey", "testValue") - .put("testKey3", "testValue3") - .build(); - TestLogRecordData logB = - TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); - - Attributes attributesC = - Attributes.builder() - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logC = - TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); - - Attributes attributesD = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logD = - TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); - - List logs = new ArrayList<>(); - logs.add(logA); - logs.add(logB); - logs.add(logC); - logs.add(logD); - - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributesA = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logA = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); + + Attributes attributesB = + Attributes.builder() + .put("one", "1") + .put("testKey", "testValue") + .put("testKey3", "testValue3") + .build(); + TestLogRecordData logB = + TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); + + Attributes attributesC = + Attributes.builder() + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logC = + TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); + + Attributes attributesD = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logD = + TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); + + List logs = new ArrayList<>(); + logs.add(logA); + logs.add(logB); + logs.add(logC); + logs.add(logD); + + exampleExporter.export(logs); + } // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -1034,54 +1018,53 @@ void multiExcludeTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter); - - Attributes attributesA = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logA = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); - - Attributes attributesB = - Attributes.builder() - .put("one", "1") - .put("testKey", "testValue") - .put("testKey3", "testValue2") - .build(); - TestLogRecordData logB = - TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); - - Attributes attributesC = - Attributes.builder() - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logC = - TestLogRecordData.builder().setBody("serviceC").setAttributes(attributesC).build(); - - Attributes attributesD = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logD = - TestLogRecordData.builder().setBody("serviceD").setAttributes(attributesD).build(); - - List logs = new ArrayList<>(); - logs.add(logA); - logs.add(logB); - logs.add(logC); - logs.add(logD); - - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributesA = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logA = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); + + Attributes attributesB = + Attributes.builder() + .put("one", "1") + .put("testKey", "testValue") + .put("testKey3", "testValue2") + .build(); + TestLogRecordData logB = + TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); + + Attributes attributesC = + Attributes.builder() + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logC = + TestLogRecordData.builder().setBody("serviceC").setAttributes(attributesC).build(); + + Attributes attributesD = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logD = + TestLogRecordData.builder().setBody("serviceD").setAttributes(attributesD).build(); + + List logs = new ArrayList<>(); + logs.add(logA); + logs.add(logB); + logs.add(logC); + logs.add(logD); + + exampleExporter.export(logs); + } // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -1115,54 +1098,53 @@ void selectiveProcessingTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter); - - Attributes attributesA = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logA = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); - - Attributes attributesB = - Attributes.builder() - .put("one", "1") - .put("testKey", "testValue1") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logB = - TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); - - Attributes attributesC = - Attributes.builder() - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logC = - TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); - - Attributes attributesD = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logD = - TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); - - List logs = new ArrayList<>(); - logs.add(logA); - logs.add(logB); - logs.add(logC); - logs.add(logD); - - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributesA = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logA = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); + + Attributes attributesB = + Attributes.builder() + .put("one", "1") + .put("testKey", "testValue1") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logB = + TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); + + Attributes attributesC = + Attributes.builder() + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logC = + TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); + + Attributes attributesD = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logD = + TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); + + List logs = new ArrayList<>(); + logs.add(logA); + logs.add(logB); + logs.add(logC); + logs.add(logD); + + exampleExporter.export(logs); + } // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -1219,26 +1201,25 @@ void actionInsertWithMaskTest() { actions.add(action4); actions.add(action5); config.actions = actions; - LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter); - - Attributes attributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "http://example.com/cardid/1234562222227899") - .put("testKey2", "http://example.com/cardid/1234562222227899") - .put("testKey3", "http://example.com/cardid/1234562222227899") - .put("TESTKEY2", "testValue2") - .put("testKey4", "/TelemetryProcessors/test") - .put("testKey5", "/abc/xyz") - .build(); - TestLogRecordData log = - TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); - - List logs = new ArrayList<>(); - logs.add(log); - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "http://example.com/cardid/1234562222227899") + .put("testKey2", "http://example.com/cardid/1234562222227899") + .put("testKey3", "http://example.com/cardid/1234562222227899") + .put("TESTKEY2", "testValue2") + .put("testKey4", "/TelemetryProcessors/test") + .put("testKey5", "/abc/xyz") + .build(); + TestLogRecordData log = + TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); + + List logs = new ArrayList<>(); + logs.add(log); + exampleExporter.export(logs); + } // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); From b56b69a3f85ec0cb30ed53176b624d393446f526 Mon Sep 17 00:00:00 2001 From: Vaibhav Khamgaonkar Date: Tue, 19 Sep 2023 07:44:56 +0530 Subject: [PATCH 4/6] formatting fix --- .../java/com/microsoft/gcmonitortests/GcEventGenerator.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/agent/agent-gc-monitor/gc-monitor-tests/src/test/java/com/microsoft/gcmonitortests/GcEventGenerator.java b/agent/agent-gc-monitor/gc-monitor-tests/src/test/java/com/microsoft/gcmonitortests/GcEventGenerator.java index 0f1bde5c85e..b68ac5985cd 100644 --- a/agent/agent-gc-monitor/gc-monitor-tests/src/test/java/com/microsoft/gcmonitortests/GcEventGenerator.java +++ b/agent/agent-gc-monitor/gc-monitor-tests/src/test/java/com/microsoft/gcmonitortests/GcEventGenerator.java @@ -28,9 +28,8 @@ public static void main(String[] args) throws InterruptedException { @SuppressWarnings("SystemOut") private void run() throws InterruptedException { System.out.println("Hit return to start"); - - try (// Block until consumer sends the ready signal - Scanner scanner = new Scanner(System.in, UTF_8.name())) { + // Block until consumer sends the ready signal + try (Scanner scanner = new Scanner(System.in, UTF_8.name())) { System.out.println(scanner.nextLine()); // Allocate 1mb From 6fa35c208759e925b90242639d3b1da30f5be6ed Mon Sep 17 00:00:00 2001 From: Vaibhav Khamgaonkar Date: Tue, 19 Sep 2023 07:59:20 +0530 Subject: [PATCH 5/6] format fix --- .../ExporterWithLogProcessorTest.java | 134 +- .../ExporterWithSpanProcessorTest.java | 356 ++--- ...LogExporterWithAttributeProcessorTest.java | 1238 +++++++-------- ...panExporterWithAttributeProcessorTest.java | 1331 +++++++++-------- 4 files changed, 1551 insertions(+), 1508 deletions(-) diff --git a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/ExporterWithLogProcessorTest.java b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/ExporterWithLogProcessorTest.java index 111207a5a0f..11443ae2a71 100644 --- a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/ExporterWithLogProcessorTest.java +++ b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/ExporterWithLogProcessorTest.java @@ -76,11 +76,11 @@ void simpleRenameLogMessageTest() { config.body = new NameConfig(); config.body.fromAttributes = Arrays.asList("db.svc", "operation", "id"); try (LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter)) { - TestLogRecordData mockLog = - TestLogRecordData.builder().setBody("logA").setAttributes(attributes).build(); - List logs = new ArrayList<>(); - logs.add(mockLog); - logExporter.export(logs); + TestLogRecordData mockLog = + TestLogRecordData.builder().setBody("logA").setAttributes(attributes).build(); + List logs = new ArrayList<>(); + logs.add(mockLog); + logExporter.export(logs); } // verify that resulting logs are filtered in the way we want List result = mockExporter.getLogs(); @@ -95,11 +95,11 @@ void simpleRenameLogWithSeparatorTest() { config.body.fromAttributes = Arrays.asList("db.svc", "operation", "id"); config.body.separator = "::"; try (LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter)) { - TestLogRecordData mockLog = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributes).build(); - List logs = new ArrayList<>(); - logs.add(mockLog); - logExporter.export(logs); + TestLogRecordData mockLog = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributes).build(); + List logs = new ArrayList<>(); + logs.add(mockLog); + logExporter.export(logs); } // verify that resulting logs are filtered in the way we want List result = mockExporter.getLogs(); @@ -114,11 +114,11 @@ void simpleRenameLogWithMissingKeysTest() { config.body.fromAttributes = Arrays.asList("db.svc", "operation", "id"); config.body.separator = "::"; try (LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter)) { - TestLogRecordData mockLog = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributes).build(); - List logs = new ArrayList<>(); - logs.add(mockLog); - logExporter.export(logs); + TestLogRecordData mockLog = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributes).build(); + List logs = new ArrayList<>(); + logs.add(mockLog); + logExporter.export(logs); } // verify that resulting logs are filtered in the way we want @@ -149,14 +149,14 @@ void simpleToAttributesTest() { toAttributeConfig.rules.add("^/api/v1/document/(?.*)/update$"); config.body.toAttributes = toAttributeConfig; try (LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter)) { - TestLogRecordData mockLog = - TestLogRecordData.builder() - .setBody("/api/v1/document/12345678/update") - .setAttributes(attributes) - .build(); - List logs = new ArrayList<>(); - logs.add(mockLog); - logExporter.export(logs); + TestLogRecordData mockLog = + TestLogRecordData.builder() + .setBody("/api/v1/document/12345678/update") + .setAttributes(attributes) + .build(); + List logs = new ArrayList<>(); + logs.add(mockLog); + logExporter.export(logs); } // verify that resulting logs are filtered in the way we want List result = mockExporter.getLogs(); @@ -182,31 +182,31 @@ void multiRuleToAttributesTest() { toAttributeConfig.rules.add("Pass=(?[^ ]+)"); config.body.toAttributes = toAttributeConfig; try (LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter)) { - TestLogRecordData mockLogA = - TestLogRecordData.builder() - .setBody("yyyPassword=123 aba Pass=555 xyx Pass=777 zzz") - .setAttributes(attributes) - .build(); + TestLogRecordData mockLogA = + TestLogRecordData.builder() + .setBody("yyyPassword=123 aba Pass=555 xyx Pass=777 zzz") + .setAttributes(attributes) + .build(); - Attributes attributesB = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("db.svc", "location") - .put("operation", "get") - .put("id", "1234") - .put("password", "234") - .build(); - TestLogRecordData mockLogB = - TestLogRecordData.builder() - .setBody("yyyPassword=**** aba") - .setAttributes(attributesB) - .build(); + Attributes attributesB = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("db.svc", "location") + .put("operation", "get") + .put("id", "1234") + .put("password", "234") + .build(); + TestLogRecordData mockLogB = + TestLogRecordData.builder() + .setBody("yyyPassword=**** aba") + .setAttributes(attributesB) + .build(); - List logs = new ArrayList<>(); - logs.add(mockLogA); - logs.add(mockLogB); - logExporter.export(logs); + List logs = new ArrayList<>(); + logs.add(mockLogA); + logs.add(mockLogB); + logExporter.export(logs); } // verify that resulting logs are filtered in the way we want List result = mockExporter.getLogs(); @@ -250,15 +250,15 @@ void multiMatch() { toAttributeConfig.rules.add("Password=(?[^ ]+)"); config.body.toAttributes = toAttributeConfig; try (LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter)) { - TestLogRecordData mockLogA = - TestLogRecordData.builder() - .setBody("yyyPassword=123 aba Password=555 xyx") - .setAttributes(attributes) - .build(); + TestLogRecordData mockLogA = + TestLogRecordData.builder() + .setBody("yyyPassword=123 aba Password=555 xyx") + .setAttributes(attributes) + .build(); - List logs = new ArrayList<>(); - logs.add(mockLogA); - logExporter.export(logs); + List logs = new ArrayList<>(); + logs.add(mockLogA); + logExporter.export(logs); } // verify that resulting logs are filtered in the way we want List result = mockExporter.getLogs(); @@ -273,20 +273,20 @@ void simpleRenameLogTestWithLogProcessor() { config.body = new NameConfig(); config.body.fromAttributes = Arrays.asList("db.svc", "operation", "id"); try (LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter)) { - Attributes newAttributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("db.svc", "location") - .put("operation", "get") - .put("id", "1234") - .build(); - TestLogRecordData mockLog = - TestLogRecordData.builder().setBody("svcA").setAttributes(newAttributes).build(); + Attributes newAttributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("db.svc", "location") + .put("operation", "get") + .put("id", "1234") + .build(); + TestLogRecordData mockLog = + TestLogRecordData.builder().setBody("svcA").setAttributes(newAttributes).build(); - List logs = new ArrayList<>(); - logs.add(mockLog); - logExporter.export(logs); + List logs = new ArrayList<>(); + logs.add(mockLog); + logExporter.export(logs); } // verify that resulting logs are not modified diff --git a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/ExporterWithSpanProcessorTest.java b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/ExporterWithSpanProcessorTest.java index 11104a20c2d..183e74e92cc 100644 --- a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/ExporterWithSpanProcessorTest.java +++ b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/ExporterWithSpanProcessorTest.java @@ -75,21 +75,21 @@ void simpleRenameSpanTest() { config.name = new NameConfig(); config.name.fromAttributes = Arrays.asList("db.svc", "operation", "id"); try (SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); + Span span = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); } // verify that resulting spans are filtered in the way we want @@ -108,21 +108,21 @@ void simpleRenameSpanWithSeparatorTest() { config.name.fromAttributes = Arrays.asList("db.svc", "operation", "id"); config.name.separator = "::"; try (SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); + Span span = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); } // verify that resulting spans are filtered in the way we want @@ -141,20 +141,20 @@ void simpleRenameSpanWithMissingKeysTest() { config.name.fromAttributes = Arrays.asList("db.svc", "operation", "id"); config.name.separator = "::"; try (SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); + Span span = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); } // verify that resulting spans are filtered in the way we want @@ -175,52 +175,52 @@ void renameSpanWithIncludeTest() { config.include.matchType = MatchType.STRICT; config.include.spanNames = Arrays.asList("svcA", "svcB"); try (SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter)) { - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .startSpan(); - - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .startSpan(); - Span spanC = - tracer - .spanBuilder("svcC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .startSpan(); - Span spanD = - tracer - .spanBuilder("svcD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - - exampleExporter.export(spans); + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .startSpan(); + + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .startSpan(); + Span spanC = + tracer + .spanBuilder("svcC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .startSpan(); + Span spanD = + tracer + .spanBuilder("svcD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + + exampleExporter.export(spans); } // verify that resulting spans are filtered in the way we want @@ -263,21 +263,21 @@ void simpleToAttributesTest() { toAttributeConfig.rules.add("^/api/v1/document/(?.*)/update$"); config.name.toAttributes = toAttributeConfig; try (SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("/api/v1/document/12345678/update") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); + Span span = + tracer + .spanBuilder("/api/v1/document/12345678/update") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); } // verify that resulting spans are filtered in the way we want @@ -307,33 +307,33 @@ void multiRuleToAttributesTest() { toAttributeConfig.rules.add("Pass=(?[^ ]+)"); config.name.toAttributes = toAttributeConfig; try (SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter)) { - Span spanA = - tracer - .spanBuilder("yyyPassword=123 aba Pass=555 xyx Pass=777 zzz") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .startSpan(); - Span spanB = - tracer - .spanBuilder("yyyPassword=**** aba") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .setAttribute("password", "234") - .startSpan(); - - SpanData spanDataA = ((ReadableSpan) spanA).toSpanData(); - SpanData spanDataB = ((ReadableSpan) spanB).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanDataA); - spans.add(spanDataB); - exampleExporter.export(spans); + Span spanA = + tracer + .spanBuilder("yyyPassword=123 aba Pass=555 xyx Pass=777 zzz") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .startSpan(); + Span spanB = + tracer + .spanBuilder("yyyPassword=**** aba") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .setAttribute("password", "234") + .startSpan(); + + SpanData spanDataA = ((ReadableSpan) spanA).toSpanData(); + SpanData spanDataB = ((ReadableSpan) spanB).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanDataA); + spans.add(spanDataB); + exampleExporter.export(spans); } // verify that resulting spans are filtered in the way we want @@ -385,52 +385,52 @@ void extractAttributesWithIncludeExcludeTest() { config.name.toAttributes = new ToAttributeConfig(); config.name.toAttributes.rules = Arrays.asList("(?.*?)/.*$"); try (SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter)) { - Span spanA = - tracer - .spanBuilder("svcA/test") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .startSpan(); - - Span spanB = - tracer - .spanBuilder("svcB/test") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .startSpan(); - Span spanC = - tracer - .spanBuilder("svcC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .startSpan(); - Span spanD = - tracer - .spanBuilder("donot/change") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - - exampleExporter.export(spans); + Span spanA = + tracer + .spanBuilder("svcA/test") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .startSpan(); + + Span spanB = + tracer + .spanBuilder("svcB/test") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .startSpan(); + Span spanC = + tracer + .spanBuilder("svcC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .startSpan(); + Span spanD = + tracer + .spanBuilder("donot/change") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + + exampleExporter.export(spans); } // verify that resulting spans are filtered in the way we want diff --git a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/LogExporterWithAttributeProcessorTest.java b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/LogExporterWithAttributeProcessorTest.java index cffdd4467f8..4f13a607d54 100644 --- a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/LogExporterWithAttributeProcessorTest.java +++ b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/LogExporterWithAttributeProcessorTest.java @@ -91,22 +91,23 @@ void actionDeleteTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("TESTKEY", "testValue2") - .put("id", "1234") - .build(); - - TestLogRecordData mockLog = - TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); - - List logs = new ArrayList<>(); - logs.add(mockLog); - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("TESTKEY", "testValue2") + .put("id", "1234") + .build(); + + TestLogRecordData mockLog = + TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); + + List logs = new ArrayList<>(); + logs.add(mockLog); + exampleExporter.export(logs); } // verify that resulting logs are filtered in the way we want @@ -128,21 +129,22 @@ void actionInsertTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("TESTKEY", "testValue2") - .build(); - - TestLogRecordData mockLog = - TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); - - List logs = new ArrayList<>(); - logs.add(mockLog); - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("TESTKEY", "testValue2") + .build(); + + TestLogRecordData mockLog = + TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); + + List logs = new ArrayList<>(); + logs.add(mockLog); + exampleExporter.export(logs); } // verify that resulting logs are filtered in the way we want @@ -166,21 +168,22 @@ void actionInsertAndUpdateTest() { actions.add(action); actions.add(updateAction); config.actions = actions; - try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("TESTKEY", "testValue2") - .build(); - - TestLogRecordData mockLog = - TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); - - List logs = new ArrayList<>(); - logs.add(mockLog); - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("TESTKEY", "testValue2") + .build(); + + TestLogRecordData mockLog = + TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); + + List logs = new ArrayList<>(); + logs.add(mockLog); + exampleExporter.export(logs); } // verify that resulting logs are filtered in the way we want @@ -206,20 +209,21 @@ void actionInsertAndUpdateSameAttributeTest() { actions.add(action); actions.add(updateAction); config.actions = actions; - try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("TESTKEY", "testValue2") - .build(); - TestLogRecordData log = - TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); - - List logs = new ArrayList<>(); - logs.add(log); - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("TESTKEY", "testValue2") + .build(); + TestLogRecordData log = + TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); + + List logs = new ArrayList<>(); + logs.add(log); + exampleExporter.export(logs); } // verify that resulting logs are filtered in the way we want @@ -239,20 +243,21 @@ void actionInsertWithDuplicateTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("TESTKEY", "testValue2") - .build(); - TestLogRecordData log = - TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); - - List logs = new ArrayList<>(); - logs.add(log); - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("TESTKEY", "testValue2") + .build(); + TestLogRecordData log = + TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); + + List logs = new ArrayList<>(); + logs.add(log); + exampleExporter.export(logs); } // verify that resulting logs are filtered in the way we want @@ -273,21 +278,22 @@ void actionInsertFromAttributeTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("TESTKEY", "testValue2") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData log = - TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); - - List logs = new ArrayList<>(); - logs.add(log); - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("TESTKEY", "testValue2") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData log = + TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); + + List logs = new ArrayList<>(); + logs.add(log); + exampleExporter.export(logs); } // verify that resulting logs are filtered in the way we want @@ -308,55 +314,57 @@ void actionSimpleUpdateLogAndSpanTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (LogRecordExporter logExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - // set up log - Attributes attributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("TESTKEY", "testValue2") - .build(); - TestLogRecordData log = - TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); - - // set up span - Span span = - OpenTelemetrySdk.builder() - .build() - .getTracer("test") - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("TESTKEY", "testValue2") - .startSpan(); - - // export log - List logs = new ArrayList<>(); - logs.add(log); - logExporter.export(logs); - - // export span - MockSpanExporter mockSpanExporter = new MockSpanExporter(); - try (SpanExporter spanExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) span).toSpanData()); - spanExporter.export(spans); - } - // retrieve updated log - List resultLogs = mockLoggerExporter.getLogs(); - LogRecordData resultLog = resultLogs.get(0); - - // retrieve updated span - List resultSpans = mockSpanExporter.getSpans(); - SpanData resultSpan = resultSpans.get(0); - - // verify that resulting logs are filtered in the way we want - assertThat(resultLog.getAttributes().get(AttributeKey.stringKey("testKey"))) - .isEqualTo("redacted"); - assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("testKey"))) - .isEqualTo("redacted"); + try (LogRecordExporter logExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + // set up log + Attributes attributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("TESTKEY", "testValue2") + .build(); + TestLogRecordData log = + TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); + + // set up span + Span span = + OpenTelemetrySdk.builder() + .build() + .getTracer("test") + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("TESTKEY", "testValue2") + .startSpan(); + + // export log + List logs = new ArrayList<>(); + logs.add(log); + logExporter.export(logs); + + // export span + MockSpanExporter mockSpanExporter = new MockSpanExporter(); + try (SpanExporter spanExporter = + new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) span).toSpanData()); + spanExporter.export(spans); + } + // retrieve updated log + List resultLogs = mockLoggerExporter.getLogs(); + LogRecordData resultLog = resultLogs.get(0); + + // retrieve updated span + List resultSpans = mockSpanExporter.getSpans(); + SpanData resultSpan = resultSpans.get(0); + + // verify that resulting logs are filtered in the way we want + assertThat(resultLog.getAttributes().get(AttributeKey.stringKey("testKey"))) + .isEqualTo("redacted"); + assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("testKey"))) + .isEqualTo("redacted"); } } @@ -368,20 +376,21 @@ void actionUpdateFromAttributeUpdateTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData log = - TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); - - List logs = new ArrayList<>(); - logs.add(log); - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData log = + TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); + + List logs = new ArrayList<>(); + logs.add(log); + exampleExporter.export(logs); } // verify that resulting logs are filtered in the way we want @@ -402,20 +411,21 @@ void complexActionTest() { actions.add(updateAction); actions.add(deleteAction); config.actions = actions; - try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData log = - TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); - - List logs = new ArrayList<>(); - logs.add(log); - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData log = + TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); + + List logs = new ArrayList<>(); + logs.add(log); + exampleExporter.export(logs); } // verify that resulting logs are filtered in the way we want @@ -437,52 +447,53 @@ void simpleIncludeTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributesA = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logA = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); - - Attributes attributesB = - Attributes.builder() - .put("one", "1") - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logB = - TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); - - Attributes attributesC = - Attributes.builder() - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logC = - TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); - - Attributes attributesD = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logD = - TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); - - List logs = new ArrayList<>(); - logs.add(logA); - logs.add(logB); - logs.add(logC); - logs.add(logD); - - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributesA = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logA = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); + + Attributes attributesB = + Attributes.builder() + .put("one", "1") + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logB = + TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); + + Attributes attributesC = + Attributes.builder() + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logC = + TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); + + Attributes attributesD = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logD = + TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); + + List logs = new ArrayList<>(); + logs.add(logA); + logs.add(logB); + logs.add(logC); + logs.add(logD); + + exampleExporter.export(logs); } // verify that resulting logs are filtered in the way we want @@ -513,52 +524,53 @@ void simpleIncludeWithLogNameTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributesA = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logA = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); - - Attributes attributesB = - Attributes.builder() - .put("one", "1") - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logB = - TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); - - Attributes attributesC = - Attributes.builder() - .put("two", 2L) - .put("testKey", "testValueC") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logC = - TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); - - Attributes attributesD = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValueD") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logD = - TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); - - List logs = new ArrayList<>(); - logs.add(logA); - logs.add(logB); - logs.add(logC); - logs.add(logD); - - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributesA = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logA = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); + + Attributes attributesB = + Attributes.builder() + .put("one", "1") + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logB = + TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); + + Attributes attributesC = + Attributes.builder() + .put("two", 2L) + .put("testKey", "testValueC") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logC = + TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); + + Attributes attributesD = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValueD") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logD = + TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); + + List logs = new ArrayList<>(); + logs.add(logA); + logs.add(logB); + logs.add(logC); + logs.add(logD); + + exampleExporter.export(logs); } // verify that resulting logs are filtered in the way we want @@ -589,52 +601,53 @@ void simpleIncludeRegexTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributesA = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logA = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); - - Attributes attributesB = - Attributes.builder() - .put("one", "1") - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logB = - TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); - - Attributes attributesC = - Attributes.builder() - .put("two", 2L) - .put("testKey", "testValueC") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logC = - TestLogRecordData.builder().setBody("serviceC").setAttributes(attributesC).build(); - - Attributes attributesD = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValueD") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logD = - TestLogRecordData.builder().setBody("serviceD").setAttributes(attributesD).build(); - - List logs = new ArrayList<>(); - logs.add(logA); - logs.add(logB); - logs.add(logC); - logs.add(logD); - - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributesA = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logA = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); + + Attributes attributesB = + Attributes.builder() + .put("one", "1") + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logB = + TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); + + Attributes attributesC = + Attributes.builder() + .put("two", 2L) + .put("testKey", "testValueC") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logC = + TestLogRecordData.builder().setBody("serviceC").setAttributes(attributesC).build(); + + Attributes attributesD = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValueD") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logD = + TestLogRecordData.builder().setBody("serviceD").setAttributes(attributesD).build(); + + List logs = new ArrayList<>(); + logs.add(logA); + logs.add(logB); + logs.add(logC); + logs.add(logD); + + exampleExporter.export(logs); } // verify that resulting logs are filtered in the way we want @@ -686,63 +699,64 @@ void simpleIncludeRegexValueTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributesA = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logA = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); - - Attributes attributesB = - Attributes.builder() - .put("one", "1") - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logB = - TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); - - Attributes attributesC = - Attributes.builder() - .put("two", 2L) - .put("testKey", "testValueC") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logC = - TestLogRecordData.builder().setBody("serviceC").setAttributes(attributesC).build(); - - Attributes attributesD = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValueD") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logD = - TestLogRecordData.builder().setBody("serviceD").setAttributes(attributesD).build(); - - Attributes attributesE = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testV1") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logE = - TestLogRecordData.builder().setBody("svcE").setAttributes(attributesE).build(); - - List logs = new ArrayList<>(); - logs.add(logA); - logs.add(logB); - logs.add(logC); - logs.add(logD); - logs.add(logE); - - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributesA = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logA = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); + + Attributes attributesB = + Attributes.builder() + .put("one", "1") + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logB = + TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); + + Attributes attributesC = + Attributes.builder() + .put("two", 2L) + .put("testKey", "testValueC") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logC = + TestLogRecordData.builder().setBody("serviceC").setAttributes(attributesC).build(); + + Attributes attributesD = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValueD") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logD = + TestLogRecordData.builder().setBody("serviceD").setAttributes(attributesD).build(); + + Attributes attributesE = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testV1") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logE = + TestLogRecordData.builder().setBody("svcE").setAttributes(attributesE).build(); + + List logs = new ArrayList<>(); + logs.add(logA); + logs.add(logB); + logs.add(logC); + logs.add(logD); + logs.add(logE); + + exampleExporter.export(logs); } // verify that resulting logs are filtered in the way we want @@ -775,52 +789,53 @@ void simpleIncludeHashTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributesA = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logA = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); - - Attributes attributesB = - Attributes.builder() - .put("one", "1") - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logB = - TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); - - Attributes attributesC = - Attributes.builder() - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logC = - TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); - - Attributes attributesD = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logD = - TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); - - List logs = new ArrayList<>(); - logs.add(logA); - logs.add(logB); - logs.add(logC); - logs.add(logD); - - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributesA = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logA = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); + + Attributes attributesB = + Attributes.builder() + .put("one", "1") + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logB = + TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); + + Attributes attributesC = + Attributes.builder() + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logC = + TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); + + Attributes attributesD = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logD = + TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); + + List logs = new ArrayList<>(); + logs.add(logA); + logs.add(logB); + logs.add(logC); + logs.add(logD); + + exampleExporter.export(logs); } // verify that resulting logs are filtered in the way we want @@ -851,52 +866,53 @@ void simpleExcludeTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributesA = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logA = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); - - Attributes attributesB = - Attributes.builder() - .put("one", "1") - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logB = - TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); - - Attributes attributesC = - Attributes.builder() - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logC = - TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); - - Attributes attributesD = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logD = - TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); - - List logs = new ArrayList<>(); - logs.add(logA); - logs.add(logB); - logs.add(logC); - logs.add(logD); - - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributesA = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logA = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); + + Attributes attributesB = + Attributes.builder() + .put("one", "1") + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logB = + TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); + + Attributes attributesC = + Attributes.builder() + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logC = + TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); + + Attributes attributesD = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logD = + TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); + + List logs = new ArrayList<>(); + logs.add(logA); + logs.add(logB); + logs.add(logC); + logs.add(logD); + + exampleExporter.export(logs); } // verify that resulting logs are filtered in the way we want @@ -935,52 +951,53 @@ void multiIncludeTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributesA = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logA = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); - - Attributes attributesB = - Attributes.builder() - .put("one", "1") - .put("testKey", "testValue") - .put("testKey3", "testValue3") - .build(); - TestLogRecordData logB = - TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); - - Attributes attributesC = - Attributes.builder() - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logC = - TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); - - Attributes attributesD = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logD = - TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); - - List logs = new ArrayList<>(); - logs.add(logA); - logs.add(logB); - logs.add(logC); - logs.add(logD); - - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributesA = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logA = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); + + Attributes attributesB = + Attributes.builder() + .put("one", "1") + .put("testKey", "testValue") + .put("testKey3", "testValue3") + .build(); + TestLogRecordData logB = + TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); + + Attributes attributesC = + Attributes.builder() + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logC = + TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); + + Attributes attributesD = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logD = + TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); + + List logs = new ArrayList<>(); + logs.add(logA); + logs.add(logB); + logs.add(logC); + logs.add(logD); + + exampleExporter.export(logs); } // verify that resulting logs are filtered in the way we want @@ -1018,52 +1035,53 @@ void multiExcludeTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributesA = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logA = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); - - Attributes attributesB = - Attributes.builder() - .put("one", "1") - .put("testKey", "testValue") - .put("testKey3", "testValue2") - .build(); - TestLogRecordData logB = - TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); - - Attributes attributesC = - Attributes.builder() - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logC = - TestLogRecordData.builder().setBody("serviceC").setAttributes(attributesC).build(); - - Attributes attributesD = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logD = - TestLogRecordData.builder().setBody("serviceD").setAttributes(attributesD).build(); - - List logs = new ArrayList<>(); - logs.add(logA); - logs.add(logB); - logs.add(logC); - logs.add(logD); - - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributesA = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logA = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); + + Attributes attributesB = + Attributes.builder() + .put("one", "1") + .put("testKey", "testValue") + .put("testKey3", "testValue2") + .build(); + TestLogRecordData logB = + TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); + + Attributes attributesC = + Attributes.builder() + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logC = + TestLogRecordData.builder().setBody("serviceC").setAttributes(attributesC).build(); + + Attributes attributesD = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logD = + TestLogRecordData.builder().setBody("serviceD").setAttributes(attributesD).build(); + + List logs = new ArrayList<>(); + logs.add(logA); + logs.add(logB); + logs.add(logC); + logs.add(logD); + + exampleExporter.export(logs); } // verify that resulting logs are filtered in the way we want @@ -1098,52 +1116,53 @@ void selectiveProcessingTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributesA = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logA = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); - - Attributes attributesB = - Attributes.builder() - .put("one", "1") - .put("testKey", "testValue1") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logB = - TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); - - Attributes attributesC = - Attributes.builder() - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logC = - TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); - - Attributes attributesD = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logD = - TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); - - List logs = new ArrayList<>(); - logs.add(logA); - logs.add(logB); - logs.add(logC); - logs.add(logD); - - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributesA = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logA = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); + + Attributes attributesB = + Attributes.builder() + .put("one", "1") + .put("testKey", "testValue1") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logB = + TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); + + Attributes attributesC = + Attributes.builder() + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logC = + TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); + + Attributes attributesD = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logD = + TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); + + List logs = new ArrayList<>(); + logs.add(logA); + logs.add(logB); + logs.add(logC); + logs.add(logD); + + exampleExporter.export(logs); } // verify that resulting logs are filtered in the way we want @@ -1201,24 +1220,25 @@ void actionInsertWithMaskTest() { actions.add(action4); actions.add(action5); config.actions = actions; - try (LogRecordExporter exampleExporter = new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "http://example.com/cardid/1234562222227899") - .put("testKey2", "http://example.com/cardid/1234562222227899") - .put("testKey3", "http://example.com/cardid/1234562222227899") - .put("TESTKEY2", "testValue2") - .put("testKey4", "/TelemetryProcessors/test") - .put("testKey5", "/abc/xyz") - .build(); - TestLogRecordData log = - TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); - - List logs = new ArrayList<>(); - logs.add(log); - exampleExporter.export(logs); + try (LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { + Attributes attributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "http://example.com/cardid/1234562222227899") + .put("testKey2", "http://example.com/cardid/1234562222227899") + .put("testKey3", "http://example.com/cardid/1234562222227899") + .put("TESTKEY2", "testValue2") + .put("testKey4", "/TelemetryProcessors/test") + .put("testKey5", "/abc/xyz") + .build(); + TestLogRecordData log = + TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); + + List logs = new ArrayList<>(); + logs.add(log); + exampleExporter.export(logs); } // verify that resulting logs are filtered in the way we want 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 2f0a4edf30e..64753a0eb22 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 @@ -91,21 +91,22 @@ void actionDeleteTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("TESTKEY", "testValue2") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); + try (SpanExporter exampleExporter = + new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("TESTKEY", "testValue2") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); } // verify that resulting spans are filtered in the way we want @@ -129,21 +130,22 @@ void actionInsertTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("TESTKEY", "testValue2") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); + try (SpanExporter exampleExporter = + new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("TESTKEY", "testValue2") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); } // verify that resulting spans are filtered in the way we want @@ -171,21 +173,22 @@ void actionInsertAndUpdateTest() { actions.add(action); actions.add(updateAction); config.actions = actions; - try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("TESTKEY", "testValue2") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); + try (SpanExporter exampleExporter = + new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("TESTKEY", "testValue2") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); } // verify that resulting spans are filtered in the way we want @@ -215,21 +218,22 @@ void actionInsertAndUpdateSameAttributeTest() { actions.add(action); actions.add(updateAction); config.actions = actions; - try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("TESTKEY", "testValue2") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); + try (SpanExporter exampleExporter = + new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("TESTKEY", "testValue2") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); } // verify that resulting spans are filtered in the way we want @@ -253,21 +257,22 @@ void actionInsertWithDuplicateTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("TESTKEY", "testValue2") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); + try (SpanExporter exampleExporter = + new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("TESTKEY", "testValue2") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); } // verify that resulting spans are filtered in the way we want @@ -292,22 +297,23 @@ void actionInsertFromAttributeTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("TESTKEY", "testValue2") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); + try (SpanExporter exampleExporter = + new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("TESTKEY", "testValue2") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); } // verify that resulting spans are filtered in the way we want @@ -332,33 +338,34 @@ void actionSimpleUpdateTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("TESTKEY", "testValue2") - .startSpan(); - - Span log = - tracer - .spanBuilder("my log") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("TESTKEY", "testValue2") - .setAttribute("applicationinsights.internal.log", true) - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - SpanData logData = ((ReadableSpan) log).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - spans.add(logData); - exampleExporter.export(spans); + try (SpanExporter exampleExporter = + new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("TESTKEY", "testValue2") + .startSpan(); + + Span log = + tracer + .spanBuilder("my log") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("TESTKEY", "testValue2") + .setAttribute("applicationinsights.internal.log", true) + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + SpanData logData = ((ReadableSpan) log).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + spans.add(logData); + exampleExporter.export(spans); } // verify that resulting spans are filtered in the way we want @@ -383,21 +390,22 @@ void actionUpdateFromAttributeUpdateTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); + try (SpanExporter exampleExporter = + new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); } // verify that resulting spans are filtered in the way we want @@ -422,21 +430,22 @@ void complexActionTest() { actions.add(updateAction); actions.add(deleteAction); config.actions = actions; - try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); + try (SpanExporter exampleExporter = + new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); } // verify that resulting spans are filtered in the way we want @@ -462,45 +471,46 @@ void simpleIncludeTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanC = - tracer - .spanBuilder("svcC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("svcD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - - exampleExporter.export(spans); + try (SpanExporter exampleExporter = + new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanC = + tracer + .spanBuilder("svcC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("svcD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + + exampleExporter.export(spans); } // verify that resulting spans are filtered in the way we want @@ -534,55 +544,56 @@ void simpleIncludeWithSpanNamesTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanC = - tracer - .spanBuilder("svcC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("svcD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span logA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .setAttribute("applicationinsights.internal.log", true) - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - spans.add(((ReadableSpan) logA).toSpanData()); - - exampleExporter.export(spans); + try (SpanExporter exampleExporter = + new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanC = + tracer + .spanBuilder("svcC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("svcD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span logA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .setAttribute("applicationinsights.internal.log", true) + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + spans.add(((ReadableSpan) logA).toSpanData()); + + exampleExporter.export(spans); } // verify that resulting spans are filtered in the way we want @@ -617,45 +628,46 @@ void simpleIncludeRegexTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanC = - tracer - .spanBuilder("serviceC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("serviceD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - - exampleExporter.export(spans); + try (SpanExporter exampleExporter = + new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanC = + tracer + .spanBuilder("serviceC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("serviceD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + + exampleExporter.export(spans); } // verify that resulting spans are filtered in the way we want @@ -713,53 +725,54 @@ void simpleIncludeRegexValueTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue1") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue2") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanC = - tracer - .spanBuilder("serviceC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("serviceD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanE = - tracer - .spanBuilder("svcE") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testV1") - .setAttribute("testKey2", "testValue2") - .startSpan(); - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - spans.add(((ReadableSpan) spanE).toSpanData()); - - exampleExporter.export(spans); + try (SpanExporter exampleExporter = + new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue1") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue2") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanC = + tracer + .spanBuilder("serviceC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("serviceD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanE = + tracer + .spanBuilder("svcE") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testV1") + .setAttribute("testKey2", "testValue2") + .startSpan(); + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + spans.add(((ReadableSpan) spanE).toSpanData()); + + exampleExporter.export(spans); } // verify that resulting spans are filtered in the way we want @@ -800,53 +813,54 @@ void simpleIncludeRegexNoValueTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue1") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue2") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanC = - tracer - .spanBuilder("serviceC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("serviceD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanE = - tracer - .spanBuilder("svcE") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testV1") - .setAttribute("testKey2", "testValue2") - .startSpan(); - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - spans.add(((ReadableSpan) spanE).toSpanData()); - - exampleExporter.export(spans); + try (SpanExporter exampleExporter = + new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue1") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue2") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanC = + tracer + .spanBuilder("serviceC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("serviceD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanE = + tracer + .spanBuilder("svcE") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testV1") + .setAttribute("testKey2", "testValue2") + .startSpan(); + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + spans.add(((ReadableSpan) spanE).toSpanData()); + + exampleExporter.export(spans); } // verify that resulting spans are filtered in the way we want @@ -883,45 +897,46 @@ void simpleIncludeHashTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", 2L) - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanC = - tracer - .spanBuilder("svcC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("svcD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - - exampleExporter.export(spans); + try (SpanExporter exampleExporter = + new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", 2L) + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanC = + tracer + .spanBuilder("svcC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("svcD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + + exampleExporter.export(spans); } // verify that resulting spans are filtered in the way we want @@ -955,45 +970,46 @@ void simpleExcludeTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanC = - tracer - .spanBuilder("svcC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("svcD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - - exampleExporter.export(spans); + try (SpanExporter exampleExporter = + new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanC = + tracer + .spanBuilder("svcC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("svcD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + + exampleExporter.export(spans); } // verify that resulting spans are filtered in the way we want @@ -1027,45 +1043,46 @@ void simpleExcludeRegexTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanC = - tracer - .spanBuilder("serviceC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("serviceD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - - exampleExporter.export(spans); + try (SpanExporter exampleExporter = + new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanC = + tracer + .spanBuilder("serviceC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("serviceD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + + exampleExporter.export(spans); } // verify that resulting spans are filtered in the way we want @@ -1107,45 +1124,46 @@ void multiIncludeTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue") - .setAttribute("testKey3", "testValue3") - .startSpan(); - Span spanC = - tracer - .spanBuilder("svcC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("svcD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - - exampleExporter.export(spans); + try (SpanExporter exampleExporter = + new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue") + .setAttribute("testKey3", "testValue3") + .startSpan(); + Span spanC = + tracer + .spanBuilder("svcC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("svcD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + + exampleExporter.export(spans); } // verify that resulting spans are filtered in the way we want @@ -1186,45 +1204,46 @@ void multiExcludeTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue") - .setAttribute("testKey3", "testValue2") - .startSpan(); - Span spanC = - tracer - .spanBuilder("svcC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("svcD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - - exampleExporter.export(spans); + try (SpanExporter exampleExporter = + new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue") + .setAttribute("testKey3", "testValue2") + .startSpan(); + Span spanC = + tracer + .spanBuilder("svcC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("svcD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + + exampleExporter.export(spans); } // verify that resulting spans are filtered in the way we want @@ -1262,45 +1281,46 @@ void selectiveProcessingTest() { // With both include and exclude List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue1") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanC = - tracer - .spanBuilder("svcC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("svcD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - - exampleExporter.export(spans); + try (SpanExporter exampleExporter = + new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue1") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanC = + tracer + .spanBuilder("svcC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("svcD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + + exampleExporter.export(spans); } // verify that resulting spans are filtered in the way we want @@ -1332,22 +1352,23 @@ void actionInsertWithExtractTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute( - "testKey", "http://example.com/path?queryParam1=value1,queryParam2=value2") - .setAttribute("TESTKEY", "testValue2") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); + try (SpanExporter exampleExporter = + new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute( + "testKey", "http://example.com/path?queryParam1=value1,queryParam2=value2") + .setAttribute("TESTKEY", "testValue2") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); } // verify that resulting spans are filtered in the way we want @@ -1379,22 +1400,23 @@ void actionInsertWithExtractDuplicateTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute( - "testKey", "http://example.com/path?queryParam1=value1,queryParam2=value2") - .setAttribute("httpPath", "oldPath") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); + try (SpanExporter exampleExporter = + new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute( + "testKey", "http://example.com/path?queryParam1=value1,queryParam2=value2") + .setAttribute("httpPath", "oldPath") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); } // verify that resulting spans are filtered in the way we want @@ -1457,25 +1479,26 @@ void actionInsertWithMaskTest() { actions.add(action4); actions.add(action5); config.actions = actions; - try (SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "http://example.com/cardid/1234562222227899") - .setAttribute("testKey2", "http://example.com/cardid/1234562222227899") - .setAttribute("testKey3", "http://example.com/cardid/1234562222227899") - .setAttribute("TESTKEY2", "testValue2") - .setAttribute("testKey4", "/TelemetryProcessors/test") - .setAttribute("testKey5", "/abc/xyz") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); + try (SpanExporter exampleExporter = + new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "http://example.com/cardid/1234562222227899") + .setAttribute("testKey2", "http://example.com/cardid/1234562222227899") + .setAttribute("testKey3", "http://example.com/cardid/1234562222227899") + .setAttribute("TESTKEY2", "testValue2") + .setAttribute("testKey4", "/TelemetryProcessors/test") + .setAttribute("testKey5", "/abc/xyz") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); } // verify that resulting spans are filtered in the way we want From b37e6007c9a676c5d710a6dc2fad9c88d44cc331 Mon Sep 17 00:00:00 2001 From: Vaibhav Khamgaonkar Date: Wed, 20 Sep 2023 17:32:22 +0530 Subject: [PATCH 6/6] updated review comments --- .../ExporterWithLogProcessorTest.java | 170 +- .../ExporterWithSpanProcessorTest.java | 384 ++--- ...LogExporterWithAttributeProcessorTest.java | 1295 ++++++++-------- ...panExporterWithAttributeProcessorTest.java | 1377 ++++++++--------- 4 files changed, 1601 insertions(+), 1625 deletions(-) diff --git a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/ExporterWithLogProcessorTest.java b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/ExporterWithLogProcessorTest.java index 11443ae2a71..4fddc756373 100644 --- a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/ExporterWithLogProcessorTest.java +++ b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/ExporterWithLogProcessorTest.java @@ -75,13 +75,13 @@ void simpleRenameLogMessageTest() { config.id = "SimpleRenameLogMessage"; config.body = new NameConfig(); config.body.fromAttributes = Arrays.asList("db.svc", "operation", "id"); - try (LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter)) { - TestLogRecordData mockLog = - TestLogRecordData.builder().setBody("logA").setAttributes(attributes).build(); - List logs = new ArrayList<>(); - logs.add(mockLog); - logExporter.export(logs); - } + LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter); + TestLogRecordData mockLog = + TestLogRecordData.builder().setBody("logA").setAttributes(attributes).build(); + List logs = new ArrayList<>(); + logs.add(mockLog); + logExporter.export(logs); + // verify that resulting logs are filtered in the way we want List result = mockExporter.getLogs(); LogRecordData resultLog = result.get(0); @@ -94,13 +94,13 @@ void simpleRenameLogWithSeparatorTest() { config.body = new NameConfig(); config.body.fromAttributes = Arrays.asList("db.svc", "operation", "id"); config.body.separator = "::"; - try (LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter)) { - TestLogRecordData mockLog = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributes).build(); - List logs = new ArrayList<>(); - logs.add(mockLog); - logExporter.export(logs); - } + LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter); + TestLogRecordData mockLog = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributes).build(); + List logs = new ArrayList<>(); + logs.add(mockLog); + logExporter.export(logs); + // verify that resulting logs are filtered in the way we want List result = mockExporter.getLogs(); LogRecordData resultLog = result.get(0); @@ -113,13 +113,13 @@ void simpleRenameLogWithMissingKeysTest() { config.body = new NameConfig(); config.body.fromAttributes = Arrays.asList("db.svc", "operation", "id"); config.body.separator = "::"; - try (LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter)) { - TestLogRecordData mockLog = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributes).build(); - List logs = new ArrayList<>(); - logs.add(mockLog); - logExporter.export(logs); - } + LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter); + + TestLogRecordData mockLog = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributes).build(); + List logs = new ArrayList<>(); + logs.add(mockLog); + logExporter.export(logs); // verify that resulting logs are filtered in the way we want List result = mockExporter.getLogs(); @@ -148,16 +148,16 @@ void simpleToAttributesTest() { toAttributeConfig.rules = new ArrayList<>(); toAttributeConfig.rules.add("^/api/v1/document/(?.*)/update$"); config.body.toAttributes = toAttributeConfig; - try (LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter)) { - TestLogRecordData mockLog = - TestLogRecordData.builder() - .setBody("/api/v1/document/12345678/update") - .setAttributes(attributes) - .build(); - List logs = new ArrayList<>(); - logs.add(mockLog); - logExporter.export(logs); - } + LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter); + TestLogRecordData mockLog = + TestLogRecordData.builder() + .setBody("/api/v1/document/12345678/update") + .setAttributes(attributes) + .build(); + List logs = new ArrayList<>(); + logs.add(mockLog); + logExporter.export(logs); + // verify that resulting logs are filtered in the way we want List result = mockExporter.getLogs(); LogRecordData resultLog = result.get(0); @@ -181,33 +181,33 @@ void multiRuleToAttributesTest() { toAttributeConfig.rules.add("Password=(?[^ ]+)"); toAttributeConfig.rules.add("Pass=(?[^ ]+)"); config.body.toAttributes = toAttributeConfig; - try (LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter)) { - TestLogRecordData mockLogA = - TestLogRecordData.builder() - .setBody("yyyPassword=123 aba Pass=555 xyx Pass=777 zzz") - .setAttributes(attributes) - .build(); - - Attributes attributesB = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("db.svc", "location") - .put("operation", "get") - .put("id", "1234") - .put("password", "234") - .build(); - TestLogRecordData mockLogB = - TestLogRecordData.builder() - .setBody("yyyPassword=**** aba") - .setAttributes(attributesB) - .build(); - - List logs = new ArrayList<>(); - logs.add(mockLogA); - logs.add(mockLogB); - logExporter.export(logs); - } + LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter); + TestLogRecordData mockLogA = + TestLogRecordData.builder() + .setBody("yyyPassword=123 aba Pass=555 xyx Pass=777 zzz") + .setAttributes(attributes) + .build(); + + Attributes attributesB = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("db.svc", "location") + .put("operation", "get") + .put("id", "1234") + .put("password", "234") + .build(); + TestLogRecordData mockLogB = + TestLogRecordData.builder() + .setBody("yyyPassword=**** aba") + .setAttributes(attributesB) + .build(); + + List logs = new ArrayList<>(); + logs.add(mockLogA); + logs.add(mockLogB); + logExporter.export(logs); + // verify that resulting logs are filtered in the way we want List result = mockExporter.getLogs(); LogRecordData resultA = result.get(0); @@ -249,17 +249,17 @@ void multiMatch() { toAttributeConfig.rules = new ArrayList<>(); toAttributeConfig.rules.add("Password=(?[^ ]+)"); config.body.toAttributes = toAttributeConfig; - try (LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter)) { - TestLogRecordData mockLogA = - TestLogRecordData.builder() - .setBody("yyyPassword=123 aba Password=555 xyx") - .setAttributes(attributes) - .build(); - - List logs = new ArrayList<>(); - logs.add(mockLogA); - logExporter.export(logs); - } + LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter); + TestLogRecordData mockLogA = + TestLogRecordData.builder() + .setBody("yyyPassword=123 aba Password=555 xyx") + .setAttributes(attributes) + .build(); + + List logs = new ArrayList<>(); + logs.add(mockLogA); + logExporter.export(logs); + // verify that resulting logs are filtered in the way we want List result = mockExporter.getLogs(); LogRecordData resultA = result.get(0); @@ -272,22 +272,22 @@ void simpleRenameLogTestWithLogProcessor() { config.id = "SimpleRenameLog"; config.body = new NameConfig(); config.body.fromAttributes = Arrays.asList("db.svc", "operation", "id"); - try (LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter)) { - Attributes newAttributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("db.svc", "location") - .put("operation", "get") - .put("id", "1234") - .build(); - TestLogRecordData mockLog = - TestLogRecordData.builder().setBody("svcA").setAttributes(newAttributes).build(); - - List logs = new ArrayList<>(); - logs.add(mockLog); - logExporter.export(logs); - } + LogRecordExporter logExporter = new ExporterWithLogProcessor(config, mockExporter); + + Attributes newAttributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("db.svc", "location") + .put("operation", "get") + .put("id", "1234") + .build(); + TestLogRecordData mockLog = + TestLogRecordData.builder().setBody("svcA").setAttributes(newAttributes).build(); + + List logs = new ArrayList<>(); + logs.add(mockLog); + logExporter.export(logs); // verify that resulting logs are not modified List result = mockExporter.getLogs(); diff --git a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/ExporterWithSpanProcessorTest.java b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/ExporterWithSpanProcessorTest.java index 183e74e92cc..5003f3138f5 100644 --- a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/ExporterWithSpanProcessorTest.java +++ b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/ExporterWithSpanProcessorTest.java @@ -74,23 +74,23 @@ void simpleRenameSpanTest() { config.id = "SimpleRenameSpan"; config.name = new NameConfig(); config.name.fromAttributes = Arrays.asList("db.svc", "operation", "id"); - try (SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); - } + SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter); + + Span span = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -107,23 +107,23 @@ void simpleRenameSpanWithSeparatorTest() { config.name = new NameConfig(); config.name.fromAttributes = Arrays.asList("db.svc", "operation", "id"); config.name.separator = "::"; - try (SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); - } + SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter); + + Span span = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -140,22 +140,22 @@ void simpleRenameSpanWithMissingKeysTest() { config.name = new NameConfig(); config.name.fromAttributes = Arrays.asList("db.svc", "operation", "id"); config.name.separator = "::"; - try (SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); - } + SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter); + + Span span = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -174,54 +174,54 @@ void renameSpanWithIncludeTest() { config.include = new ProcessorIncludeExclude(); config.include.matchType = MatchType.STRICT; config.include.spanNames = Arrays.asList("svcA", "svcB"); - try (SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter)) { - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .startSpan(); - - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .startSpan(); - Span spanC = - tracer - .spanBuilder("svcC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .startSpan(); - Span spanD = - tracer - .spanBuilder("svcD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - - exampleExporter.export(spans); - } + SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter); + + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .startSpan(); + + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .startSpan(); + Span spanC = + tracer + .spanBuilder("svcC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .startSpan(); + Span spanD = + tracer + .spanBuilder("svcD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + + exampleExporter.export(spans); // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -262,23 +262,23 @@ void simpleToAttributesTest() { toAttributeConfig.rules = new ArrayList<>(); toAttributeConfig.rules.add("^/api/v1/document/(?.*)/update$"); config.name.toAttributes = toAttributeConfig; - try (SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("/api/v1/document/12345678/update") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); - } + SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter); + + Span span = + tracer + .spanBuilder("/api/v1/document/12345678/update") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -306,35 +306,35 @@ void multiRuleToAttributesTest() { toAttributeConfig.rules.add("Password=(?[^ ]+)"); toAttributeConfig.rules.add("Pass=(?[^ ]+)"); config.name.toAttributes = toAttributeConfig; - try (SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter)) { - Span spanA = - tracer - .spanBuilder("yyyPassword=123 aba Pass=555 xyx Pass=777 zzz") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .startSpan(); - Span spanB = - tracer - .spanBuilder("yyyPassword=**** aba") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .setAttribute("password", "234") - .startSpan(); - - SpanData spanDataA = ((ReadableSpan) spanA).toSpanData(); - SpanData spanDataB = ((ReadableSpan) spanB).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanDataA); - spans.add(spanDataB); - exampleExporter.export(spans); - } + SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter); + + Span spanA = + tracer + .spanBuilder("yyyPassword=123 aba Pass=555 xyx Pass=777 zzz") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .startSpan(); + Span spanB = + tracer + .spanBuilder("yyyPassword=**** aba") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .setAttribute("password", "234") + .startSpan(); + + SpanData spanDataA = ((ReadableSpan) spanA).toSpanData(); + SpanData spanDataB = ((ReadableSpan) spanB).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanDataA); + spans.add(spanDataB); + exampleExporter.export(spans); // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -384,54 +384,54 @@ void extractAttributesWithIncludeExcludeTest() { config.exclude.spanNames = Arrays.asList("donot/change"); config.name.toAttributes = new ToAttributeConfig(); config.name.toAttributes.rules = Arrays.asList("(?.*?)/.*$"); - try (SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter)) { - Span spanA = - tracer - .spanBuilder("svcA/test") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .startSpan(); - - Span spanB = - tracer - .spanBuilder("svcB/test") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .startSpan(); - Span spanC = - tracer - .spanBuilder("svcC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .setAttribute("db.svc", "location") - .setAttribute("operation", "get") - .setAttribute("id", "1234") - .startSpan(); - Span spanD = - tracer - .spanBuilder("donot/change") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - - exampleExporter.export(spans); - } + SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockSpanExporter); + + Span spanA = + tracer + .spanBuilder("svcA/test") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .startSpan(); + + Span spanB = + tracer + .spanBuilder("svcB/test") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .startSpan(); + Span spanC = + tracer + .spanBuilder("svcC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .setAttribute("db.svc", "location") + .setAttribute("operation", "get") + .setAttribute("id", "1234") + .startSpan(); + Span spanD = + tracer + .spanBuilder("donot/change") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + + exampleExporter.export(spans); // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); diff --git a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/LogExporterWithAttributeProcessorTest.java b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/LogExporterWithAttributeProcessorTest.java index 4f13a607d54..14acd1f9453 100644 --- a/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/LogExporterWithAttributeProcessorTest.java +++ b/agent/agent-tooling/src/test/java/com/microsoft/applicationinsights/agent/internal/processors/LogExporterWithAttributeProcessorTest.java @@ -91,24 +91,24 @@ void actionDeleteTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("TESTKEY", "testValue2") - .put("id", "1234") - .build(); - - TestLogRecordData mockLog = - TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); - - List logs = new ArrayList<>(); - logs.add(mockLog); - exampleExporter.export(logs); - } + LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter); + + Attributes attributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("TESTKEY", "testValue2") + .put("id", "1234") + .build(); + + TestLogRecordData mockLog = + TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); + + List logs = new ArrayList<>(); + logs.add(mockLog); + exampleExporter.export(logs); // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -129,23 +129,23 @@ void actionInsertTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("TESTKEY", "testValue2") - .build(); - - TestLogRecordData mockLog = - TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); - - List logs = new ArrayList<>(); - logs.add(mockLog); - exampleExporter.export(logs); - } + LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter); + + Attributes attributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("TESTKEY", "testValue2") + .build(); + + TestLogRecordData mockLog = + TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); + + List logs = new ArrayList<>(); + logs.add(mockLog); + exampleExporter.export(logs); // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -168,23 +168,23 @@ void actionInsertAndUpdateTest() { actions.add(action); actions.add(updateAction); config.actions = actions; - try (LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("TESTKEY", "testValue2") - .build(); - - TestLogRecordData mockLog = - TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); - - List logs = new ArrayList<>(); - logs.add(mockLog); - exampleExporter.export(logs); - } + LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter); + + Attributes attributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("TESTKEY", "testValue2") + .build(); + + TestLogRecordData mockLog = + TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); + + List logs = new ArrayList<>(); + logs.add(mockLog); + exampleExporter.export(logs); // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -209,22 +209,22 @@ void actionInsertAndUpdateSameAttributeTest() { actions.add(action); actions.add(updateAction); config.actions = actions; - try (LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("TESTKEY", "testValue2") - .build(); - TestLogRecordData log = - TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); - - List logs = new ArrayList<>(); - logs.add(log); - exampleExporter.export(logs); - } + LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter); + + Attributes attributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("TESTKEY", "testValue2") + .build(); + TestLogRecordData log = + TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); + + List logs = new ArrayList<>(); + logs.add(log); + exampleExporter.export(logs); // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -243,22 +243,22 @@ void actionInsertWithDuplicateTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("TESTKEY", "testValue2") - .build(); - TestLogRecordData log = - TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); - - List logs = new ArrayList<>(); - logs.add(log); - exampleExporter.export(logs); - } + LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter); + + Attributes attributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("TESTKEY", "testValue2") + .build(); + TestLogRecordData log = + TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); + + List logs = new ArrayList<>(); + logs.add(log); + exampleExporter.export(logs); // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -278,23 +278,23 @@ void actionInsertFromAttributeTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("TESTKEY", "testValue2") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData log = - TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); - - List logs = new ArrayList<>(); - logs.add(log); - exampleExporter.export(logs); - } + LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter); + + Attributes attributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("TESTKEY", "testValue2") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData log = + TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); + + List logs = new ArrayList<>(); + logs.add(log); + exampleExporter.export(logs); // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -314,58 +314,57 @@ void actionSimpleUpdateLogAndSpanTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (LogRecordExporter logExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - // set up log - Attributes attributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("TESTKEY", "testValue2") - .build(); - TestLogRecordData log = - TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); - - // set up span - Span span = - OpenTelemetrySdk.builder() - .build() - .getTracer("test") - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("TESTKEY", "testValue2") - .startSpan(); - - // export log - List logs = new ArrayList<>(); - logs.add(log); - logExporter.export(logs); - - // export span - MockSpanExporter mockSpanExporter = new MockSpanExporter(); - try (SpanExporter spanExporter = - new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) span).toSpanData()); - spanExporter.export(spans); - } - // retrieve updated log - List resultLogs = mockLoggerExporter.getLogs(); - LogRecordData resultLog = resultLogs.get(0); - - // retrieve updated span - List resultSpans = mockSpanExporter.getSpans(); - SpanData resultSpan = resultSpans.get(0); - - // verify that resulting logs are filtered in the way we want - assertThat(resultLog.getAttributes().get(AttributeKey.stringKey("testKey"))) - .isEqualTo("redacted"); - assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("testKey"))) - .isEqualTo("redacted"); - } + LogRecordExporter logExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter); + + // set up log + Attributes attributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("TESTKEY", "testValue2") + .build(); + TestLogRecordData log = + TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); + + // set up span + Span span = + OpenTelemetrySdk.builder() + .build() + .getTracer("test") + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("TESTKEY", "testValue2") + .startSpan(); + + // export log + List logs = new ArrayList<>(); + logs.add(log); + logExporter.export(logs); + + // export span + MockSpanExporter mockSpanExporter = new MockSpanExporter(); + SpanExporter spanExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) span).toSpanData()); + spanExporter.export(spans); + + // retrieve updated log + List resultLogs = mockLoggerExporter.getLogs(); + LogRecordData resultLog = resultLogs.get(0); + + // retrieve updated span + List resultSpans = mockSpanExporter.getSpans(); + SpanData resultSpan = resultSpans.get(0); + + // verify that resulting logs are filtered in the way we want + assertThat(resultLog.getAttributes().get(AttributeKey.stringKey("testKey"))) + .isEqualTo("redacted"); + assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("testKey"))) + .isEqualTo("redacted"); } @Test @@ -376,22 +375,22 @@ void actionUpdateFromAttributeUpdateTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData log = - TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); - - List logs = new ArrayList<>(); - logs.add(log); - exampleExporter.export(logs); - } + LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter); + + Attributes attributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData log = + TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); + + List logs = new ArrayList<>(); + logs.add(log); + exampleExporter.export(logs); // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -411,22 +410,22 @@ void complexActionTest() { actions.add(updateAction); actions.add(deleteAction); config.actions = actions; - try (LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData log = - TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); - - List logs = new ArrayList<>(); - logs.add(log); - exampleExporter.export(logs); - } + LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter); + + Attributes attributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData log = + TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); + + List logs = new ArrayList<>(); + logs.add(log); + exampleExporter.export(logs); // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -447,54 +446,54 @@ void simpleIncludeTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributesA = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logA = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); - - Attributes attributesB = - Attributes.builder() - .put("one", "1") - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logB = - TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); - - Attributes attributesC = - Attributes.builder() - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logC = - TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); - - Attributes attributesD = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logD = - TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); - - List logs = new ArrayList<>(); - logs.add(logA); - logs.add(logB); - logs.add(logC); - logs.add(logD); - - exampleExporter.export(logs); - } + LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter); + + Attributes attributesA = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logA = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); + + Attributes attributesB = + Attributes.builder() + .put("one", "1") + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logB = + TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); + + Attributes attributesC = + Attributes.builder() + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logC = + TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); + + Attributes attributesD = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logD = + TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); + + List logs = new ArrayList<>(); + logs.add(logA); + logs.add(logB); + logs.add(logC); + logs.add(logD); + + exampleExporter.export(logs); // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -524,54 +523,54 @@ void simpleIncludeWithLogNameTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributesA = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logA = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); - - Attributes attributesB = - Attributes.builder() - .put("one", "1") - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logB = - TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); - - Attributes attributesC = - Attributes.builder() - .put("two", 2L) - .put("testKey", "testValueC") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logC = - TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); - - Attributes attributesD = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValueD") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logD = - TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); - - List logs = new ArrayList<>(); - logs.add(logA); - logs.add(logB); - logs.add(logC); - logs.add(logD); - - exampleExporter.export(logs); - } + LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter); + + Attributes attributesA = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logA = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); + + Attributes attributesB = + Attributes.builder() + .put("one", "1") + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logB = + TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); + + Attributes attributesC = + Attributes.builder() + .put("two", 2L) + .put("testKey", "testValueC") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logC = + TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); + + Attributes attributesD = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValueD") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logD = + TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); + + List logs = new ArrayList<>(); + logs.add(logA); + logs.add(logB); + logs.add(logC); + logs.add(logD); + + exampleExporter.export(logs); // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -601,54 +600,54 @@ void simpleIncludeRegexTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributesA = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logA = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); - - Attributes attributesB = - Attributes.builder() - .put("one", "1") - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logB = - TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); - - Attributes attributesC = - Attributes.builder() - .put("two", 2L) - .put("testKey", "testValueC") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logC = - TestLogRecordData.builder().setBody("serviceC").setAttributes(attributesC).build(); - - Attributes attributesD = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValueD") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logD = - TestLogRecordData.builder().setBody("serviceD").setAttributes(attributesD).build(); - - List logs = new ArrayList<>(); - logs.add(logA); - logs.add(logB); - logs.add(logC); - logs.add(logD); - - exampleExporter.export(logs); - } + LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter); + + Attributes attributesA = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logA = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); + + Attributes attributesB = + Attributes.builder() + .put("one", "1") + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logB = + TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); + + Attributes attributesC = + Attributes.builder() + .put("two", 2L) + .put("testKey", "testValueC") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logC = + TestLogRecordData.builder().setBody("serviceC").setAttributes(attributesC).build(); + + Attributes attributesD = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValueD") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logD = + TestLogRecordData.builder().setBody("serviceD").setAttributes(attributesD).build(); + + List logs = new ArrayList<>(); + logs.add(logA); + logs.add(logB); + logs.add(logC); + logs.add(logD); + + exampleExporter.export(logs); // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -699,65 +698,65 @@ void simpleIncludeRegexValueTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributesA = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logA = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); - - Attributes attributesB = - Attributes.builder() - .put("one", "1") - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logB = - TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); - - Attributes attributesC = - Attributes.builder() - .put("two", 2L) - .put("testKey", "testValueC") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logC = - TestLogRecordData.builder().setBody("serviceC").setAttributes(attributesC).build(); - - Attributes attributesD = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValueD") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logD = - TestLogRecordData.builder().setBody("serviceD").setAttributes(attributesD).build(); - - Attributes attributesE = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testV1") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logE = - TestLogRecordData.builder().setBody("svcE").setAttributes(attributesE).build(); - - List logs = new ArrayList<>(); - logs.add(logA); - logs.add(logB); - logs.add(logC); - logs.add(logD); - logs.add(logE); - - exampleExporter.export(logs); - } + LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter); + + Attributes attributesA = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logA = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); + + Attributes attributesB = + Attributes.builder() + .put("one", "1") + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logB = + TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); + + Attributes attributesC = + Attributes.builder() + .put("two", 2L) + .put("testKey", "testValueC") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logC = + TestLogRecordData.builder().setBody("serviceC").setAttributes(attributesC).build(); + + Attributes attributesD = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValueD") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logD = + TestLogRecordData.builder().setBody("serviceD").setAttributes(attributesD).build(); + + Attributes attributesE = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testV1") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logE = + TestLogRecordData.builder().setBody("svcE").setAttributes(attributesE).build(); + + List logs = new ArrayList<>(); + logs.add(logA); + logs.add(logB); + logs.add(logC); + logs.add(logD); + logs.add(logE); + + exampleExporter.export(logs); // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -789,54 +788,54 @@ void simpleIncludeHashTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributesA = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logA = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); - - Attributes attributesB = - Attributes.builder() - .put("one", "1") - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logB = - TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); - - Attributes attributesC = - Attributes.builder() - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logC = - TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); - - Attributes attributesD = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logD = - TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); - - List logs = new ArrayList<>(); - logs.add(logA); - logs.add(logB); - logs.add(logC); - logs.add(logD); - - exampleExporter.export(logs); - } + LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter); + + Attributes attributesA = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logA = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); + + Attributes attributesB = + Attributes.builder() + .put("one", "1") + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logB = + TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); + + Attributes attributesC = + Attributes.builder() + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logC = + TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); + + Attributes attributesD = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logD = + TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); + + List logs = new ArrayList<>(); + logs.add(logA); + logs.add(logB); + logs.add(logC); + logs.add(logD); + + exampleExporter.export(logs); // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -866,54 +865,54 @@ void simpleExcludeTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributesA = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logA = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); - - Attributes attributesB = - Attributes.builder() - .put("one", "1") - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logB = - TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); - - Attributes attributesC = - Attributes.builder() - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logC = - TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); - - Attributes attributesD = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logD = - TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); - - List logs = new ArrayList<>(); - logs.add(logA); - logs.add(logB); - logs.add(logC); - logs.add(logD); - - exampleExporter.export(logs); - } + LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter); + + Attributes attributesA = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logA = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); + + Attributes attributesB = + Attributes.builder() + .put("one", "1") + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logB = + TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); + + Attributes attributesC = + Attributes.builder() + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logC = + TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); + + Attributes attributesD = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logD = + TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); + + List logs = new ArrayList<>(); + logs.add(logA); + logs.add(logB); + logs.add(logC); + logs.add(logD); + + exampleExporter.export(logs); // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -951,54 +950,54 @@ void multiIncludeTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributesA = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logA = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); - - Attributes attributesB = - Attributes.builder() - .put("one", "1") - .put("testKey", "testValue") - .put("testKey3", "testValue3") - .build(); - TestLogRecordData logB = - TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); - - Attributes attributesC = - Attributes.builder() - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logC = - TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); - - Attributes attributesD = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logD = - TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); - - List logs = new ArrayList<>(); - logs.add(logA); - logs.add(logB); - logs.add(logC); - logs.add(logD); - - exampleExporter.export(logs); - } + LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter); + + Attributes attributesA = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logA = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); + + Attributes attributesB = + Attributes.builder() + .put("one", "1") + .put("testKey", "testValue") + .put("testKey3", "testValue3") + .build(); + TestLogRecordData logB = + TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); + + Attributes attributesC = + Attributes.builder() + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logC = + TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); + + Attributes attributesD = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logD = + TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); + + List logs = new ArrayList<>(); + logs.add(logA); + logs.add(logB); + logs.add(logC); + logs.add(logD); + + exampleExporter.export(logs); // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -1035,54 +1034,54 @@ void multiExcludeTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributesA = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logA = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); - - Attributes attributesB = - Attributes.builder() - .put("one", "1") - .put("testKey", "testValue") - .put("testKey3", "testValue2") - .build(); - TestLogRecordData logB = - TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); - - Attributes attributesC = - Attributes.builder() - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logC = - TestLogRecordData.builder().setBody("serviceC").setAttributes(attributesC).build(); - - Attributes attributesD = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logD = - TestLogRecordData.builder().setBody("serviceD").setAttributes(attributesD).build(); - - List logs = new ArrayList<>(); - logs.add(logA); - logs.add(logB); - logs.add(logC); - logs.add(logD); - - exampleExporter.export(logs); - } + LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter); + + Attributes attributesA = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logA = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); + + Attributes attributesB = + Attributes.builder() + .put("one", "1") + .put("testKey", "testValue") + .put("testKey3", "testValue2") + .build(); + TestLogRecordData logB = + TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); + + Attributes attributesC = + Attributes.builder() + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logC = + TestLogRecordData.builder().setBody("serviceC").setAttributes(attributesC).build(); + + Attributes attributesD = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logD = + TestLogRecordData.builder().setBody("serviceD").setAttributes(attributesD).build(); + + List logs = new ArrayList<>(); + logs.add(logA); + logs.add(logB); + logs.add(logC); + logs.add(logD); + + exampleExporter.export(logs); // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -1116,54 +1115,54 @@ void selectiveProcessingTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributesA = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logA = - TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); - - Attributes attributesB = - Attributes.builder() - .put("one", "1") - .put("testKey", "testValue1") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logB = - TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); - - Attributes attributesC = - Attributes.builder() - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logC = - TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); - - Attributes attributesD = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "testValue") - .put("testKey2", "testValue2") - .build(); - TestLogRecordData logD = - TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); - - List logs = new ArrayList<>(); - logs.add(logA); - logs.add(logB); - logs.add(logC); - logs.add(logD); - - exampleExporter.export(logs); - } + LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter); + + Attributes attributesA = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logA = + TestLogRecordData.builder().setBody("svcA").setAttributes(attributesA).build(); + + Attributes attributesB = + Attributes.builder() + .put("one", "1") + .put("testKey", "testValue1") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logB = + TestLogRecordData.builder().setBody("svcB").setAttributes(attributesB).build(); + + Attributes attributesC = + Attributes.builder() + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logC = + TestLogRecordData.builder().setBody("svcC").setAttributes(attributesC).build(); + + Attributes attributesD = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "testValue") + .put("testKey2", "testValue2") + .build(); + TestLogRecordData logD = + TestLogRecordData.builder().setBody("svcD").setAttributes(attributesD).build(); + + List logs = new ArrayList<>(); + logs.add(logA); + logs.add(logB); + logs.add(logC); + logs.add(logD); + + exampleExporter.export(logs); // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); @@ -1220,26 +1219,26 @@ void actionInsertWithMaskTest() { actions.add(action4); actions.add(action5); config.actions = actions; - try (LogRecordExporter exampleExporter = - new LogExporterWithAttributeProcessor(config, mockLoggerExporter)) { - Attributes attributes = - Attributes.builder() - .put("one", "1") - .put("two", 2L) - .put("testKey", "http://example.com/cardid/1234562222227899") - .put("testKey2", "http://example.com/cardid/1234562222227899") - .put("testKey3", "http://example.com/cardid/1234562222227899") - .put("TESTKEY2", "testValue2") - .put("testKey4", "/TelemetryProcessors/test") - .put("testKey5", "/abc/xyz") - .build(); - TestLogRecordData log = - TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); - - List logs = new ArrayList<>(); - logs.add(log); - exampleExporter.export(logs); - } + LogRecordExporter exampleExporter = + new LogExporterWithAttributeProcessor(config, mockLoggerExporter); + + Attributes attributes = + Attributes.builder() + .put("one", "1") + .put("two", 2L) + .put("testKey", "http://example.com/cardid/1234562222227899") + .put("testKey2", "http://example.com/cardid/1234562222227899") + .put("testKey3", "http://example.com/cardid/1234562222227899") + .put("TESTKEY2", "testValue2") + .put("testKey4", "/TelemetryProcessors/test") + .put("testKey5", "/abc/xyz") + .build(); + TestLogRecordData log = + TestLogRecordData.builder().setBody("my log").setAttributes(attributes).build(); + + List logs = new ArrayList<>(); + logs.add(log); + exampleExporter.export(logs); // verify that resulting logs are filtered in the way we want List result = mockLoggerExporter.getLogs(); 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 64753a0eb22..002dddc210a 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 @@ -91,23 +91,22 @@ void actionDeleteTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = - new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("TESTKEY", "testValue2") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); - } + SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); + + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("TESTKEY", "testValue2") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -130,23 +129,22 @@ void actionInsertTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = - new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("TESTKEY", "testValue2") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); - } + SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); + + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("TESTKEY", "testValue2") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -173,23 +171,22 @@ void actionInsertAndUpdateTest() { actions.add(action); actions.add(updateAction); config.actions = actions; - try (SpanExporter exampleExporter = - new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("TESTKEY", "testValue2") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); - } + SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); + + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("TESTKEY", "testValue2") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -218,23 +215,22 @@ void actionInsertAndUpdateSameAttributeTest() { actions.add(action); actions.add(updateAction); config.actions = actions; - try (SpanExporter exampleExporter = - new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("TESTKEY", "testValue2") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); - } + SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); + + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("TESTKEY", "testValue2") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -257,23 +253,22 @@ void actionInsertWithDuplicateTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = - new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("TESTKEY", "testValue2") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); - } + SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); + + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("TESTKEY", "testValue2") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -297,24 +292,23 @@ void actionInsertFromAttributeTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = - new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("TESTKEY", "testValue2") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); - } + SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); + + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("TESTKEY", "testValue2") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -338,35 +332,34 @@ void actionSimpleUpdateTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = - new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("TESTKEY", "testValue2") - .startSpan(); - - Span log = - tracer - .spanBuilder("my log") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("TESTKEY", "testValue2") - .setAttribute("applicationinsights.internal.log", true) - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - SpanData logData = ((ReadableSpan) log).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - spans.add(logData); - exampleExporter.export(spans); - } + SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); + + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("TESTKEY", "testValue2") + .startSpan(); + + Span log = + tracer + .spanBuilder("my log") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("TESTKEY", "testValue2") + .setAttribute("applicationinsights.internal.log", true) + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + SpanData logData = ((ReadableSpan) log).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + spans.add(logData); + exampleExporter.export(spans); // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -390,23 +383,22 @@ void actionUpdateFromAttributeUpdateTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = - new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); - } + SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); + + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -430,23 +422,22 @@ void complexActionTest() { actions.add(updateAction); actions.add(deleteAction); config.actions = actions; - try (SpanExporter exampleExporter = - new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); - } + SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); + + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -471,47 +462,46 @@ void simpleIncludeTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = - new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanC = - tracer - .spanBuilder("svcC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("svcD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - - exampleExporter.export(spans); - } + SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); + + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanC = + tracer + .spanBuilder("svcC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("svcD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + + exampleExporter.export(spans); // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -544,57 +534,56 @@ void simpleIncludeWithSpanNamesTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = - new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanC = - tracer - .spanBuilder("svcC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("svcD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span logA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .setAttribute("applicationinsights.internal.log", true) - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - spans.add(((ReadableSpan) logA).toSpanData()); - - exampleExporter.export(spans); - } + SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); + + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanC = + tracer + .spanBuilder("svcC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("svcD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span logA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .setAttribute("applicationinsights.internal.log", true) + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + spans.add(((ReadableSpan) logA).toSpanData()); + + exampleExporter.export(spans); // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -628,47 +617,46 @@ void simpleIncludeRegexTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = - new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanC = - tracer - .spanBuilder("serviceC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("serviceD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - - exampleExporter.export(spans); - } + SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); + + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanC = + tracer + .spanBuilder("serviceC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("serviceD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + + exampleExporter.export(spans); // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -725,55 +713,54 @@ void simpleIncludeRegexValueTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = - new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue1") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue2") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanC = - tracer - .spanBuilder("serviceC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("serviceD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanE = - tracer - .spanBuilder("svcE") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testV1") - .setAttribute("testKey2", "testValue2") - .startSpan(); - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - spans.add(((ReadableSpan) spanE).toSpanData()); - - exampleExporter.export(spans); - } + SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); + + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue1") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue2") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanC = + tracer + .spanBuilder("serviceC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("serviceD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanE = + tracer + .spanBuilder("svcE") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testV1") + .setAttribute("testKey2", "testValue2") + .startSpan(); + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + spans.add(((ReadableSpan) spanE).toSpanData()); + + exampleExporter.export(spans); // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -813,55 +800,54 @@ void simpleIncludeRegexNoValueTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = - new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue1") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue2") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanC = - tracer - .spanBuilder("serviceC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("serviceD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanE = - tracer - .spanBuilder("svcE") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testV1") - .setAttribute("testKey2", "testValue2") - .startSpan(); - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - spans.add(((ReadableSpan) spanE).toSpanData()); - - exampleExporter.export(spans); - } + SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); + + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue1") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue2") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanC = + tracer + .spanBuilder("serviceC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("serviceD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanE = + tracer + .spanBuilder("svcE") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testV1") + .setAttribute("testKey2", "testValue2") + .startSpan(); + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + spans.add(((ReadableSpan) spanE).toSpanData()); + + exampleExporter.export(spans); // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -897,47 +883,46 @@ void simpleIncludeHashTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = - new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", 2L) - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanC = - tracer - .spanBuilder("svcC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("svcD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - - exampleExporter.export(spans); - } + SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); + + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", 2L) + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanC = + tracer + .spanBuilder("svcC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("svcD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + + exampleExporter.export(spans); // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -970,47 +955,46 @@ void simpleExcludeTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = - new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanC = - tracer - .spanBuilder("svcC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("svcD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - - exampleExporter.export(spans); - } + SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); + + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanC = + tracer + .spanBuilder("svcC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("svcD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + + exampleExporter.export(spans); // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -1043,47 +1027,46 @@ void simpleExcludeRegexTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = - new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanC = - tracer - .spanBuilder("serviceC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("serviceD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - - exampleExporter.export(spans); - } + SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); + + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanC = + tracer + .spanBuilder("serviceC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("serviceD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + + exampleExporter.export(spans); // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -1124,47 +1107,46 @@ void multiIncludeTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = - new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue") - .setAttribute("testKey3", "testValue3") - .startSpan(); - Span spanC = - tracer - .spanBuilder("svcC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("svcD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - - exampleExporter.export(spans); - } + SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); + + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue") + .setAttribute("testKey3", "testValue3") + .startSpan(); + Span spanC = + tracer + .spanBuilder("svcC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("svcD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + + exampleExporter.export(spans); // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -1204,47 +1186,46 @@ void multiExcludeTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = - new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue") - .setAttribute("testKey3", "testValue2") - .startSpan(); - Span spanC = - tracer - .spanBuilder("svcC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("svcD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - - exampleExporter.export(spans); - } + SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); + + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue") + .setAttribute("testKey3", "testValue2") + .startSpan(); + Span spanC = + tracer + .spanBuilder("svcC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("svcD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + + exampleExporter.export(spans); // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -1281,47 +1262,46 @@ void selectiveProcessingTest() { // With both include and exclude List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = - new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span spanA = - tracer - .spanBuilder("svcA") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanB = - tracer - .spanBuilder("svcB") - .setAttribute("one", "1") - .setAttribute("testKey", "testValue1") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanC = - tracer - .spanBuilder("svcC") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - Span spanD = - tracer - .spanBuilder("svcD") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "testValue") - .setAttribute("testKey2", "testValue2") - .startSpan(); - - List spans = new ArrayList<>(); - spans.add(((ReadableSpan) spanA).toSpanData()); - spans.add(((ReadableSpan) spanB).toSpanData()); - spans.add(((ReadableSpan) spanC).toSpanData()); - spans.add(((ReadableSpan) spanD).toSpanData()); - - exampleExporter.export(spans); - } + SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); + + Span spanA = + tracer + .spanBuilder("svcA") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanB = + tracer + .spanBuilder("svcB") + .setAttribute("one", "1") + .setAttribute("testKey", "testValue1") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanC = + tracer + .spanBuilder("svcC") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + Span spanD = + tracer + .spanBuilder("svcD") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "testValue") + .setAttribute("testKey2", "testValue2") + .startSpan(); + + List spans = new ArrayList<>(); + spans.add(((ReadableSpan) spanA).toSpanData()); + spans.add(((ReadableSpan) spanB).toSpanData()); + spans.add(((ReadableSpan) spanC).toSpanData()); + spans.add(((ReadableSpan) spanD).toSpanData()); + + exampleExporter.export(spans); // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -1352,24 +1332,23 @@ void actionInsertWithExtractTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = - new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute( - "testKey", "http://example.com/path?queryParam1=value1,queryParam2=value2") - .setAttribute("TESTKEY", "testValue2") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); - } + SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); + + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute( + "testKey", "http://example.com/path?queryParam1=value1,queryParam2=value2") + .setAttribute("TESTKEY", "testValue2") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -1400,24 +1379,23 @@ void actionInsertWithExtractDuplicateTest() { List actions = new ArrayList<>(); actions.add(action); config.actions = actions; - try (SpanExporter exampleExporter = - new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute( - "testKey", "http://example.com/path?queryParam1=value1,queryParam2=value2") - .setAttribute("httpPath", "oldPath") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); - } + SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); + + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute( + "testKey", "http://example.com/path?queryParam1=value1,queryParam2=value2") + .setAttribute("httpPath", "oldPath") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans(); @@ -1479,27 +1457,26 @@ void actionInsertWithMaskTest() { actions.add(action4); actions.add(action5); config.actions = actions; - try (SpanExporter exampleExporter = - new SpanExporterWithAttributeProcessor(config, mockSpanExporter)) { - Span span = - tracer - .spanBuilder("my span") - .setAttribute("one", "1") - .setAttribute("two", 2L) - .setAttribute("testKey", "http://example.com/cardid/1234562222227899") - .setAttribute("testKey2", "http://example.com/cardid/1234562222227899") - .setAttribute("testKey3", "http://example.com/cardid/1234562222227899") - .setAttribute("TESTKEY2", "testValue2") - .setAttribute("testKey4", "/TelemetryProcessors/test") - .setAttribute("testKey5", "/abc/xyz") - .startSpan(); - - SpanData spanData = ((ReadableSpan) span).toSpanData(); - - List spans = new ArrayList<>(); - spans.add(spanData); - exampleExporter.export(spans); - } + SpanExporter exampleExporter = new SpanExporterWithAttributeProcessor(config, mockSpanExporter); + + Span span = + tracer + .spanBuilder("my span") + .setAttribute("one", "1") + .setAttribute("two", 2L) + .setAttribute("testKey", "http://example.com/cardid/1234562222227899") + .setAttribute("testKey2", "http://example.com/cardid/1234562222227899") + .setAttribute("testKey3", "http://example.com/cardid/1234562222227899") + .setAttribute("TESTKEY2", "testValue2") + .setAttribute("testKey4", "/TelemetryProcessors/test") + .setAttribute("testKey5", "/abc/xyz") + .startSpan(); + + SpanData spanData = ((ReadableSpan) span).toSpanData(); + + List spans = new ArrayList<>(); + spans.add(spanData); + exampleExporter.export(spans); // verify that resulting spans are filtered in the way we want List result = mockSpanExporter.getSpans();