use of com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorAttribute in project ApplicationInsights-Java by microsoft.
the class ExporterWithAttributeProcessorTest method multiExcludeTest.
@Test
void multiExcludeTest() {
MockExporter mockExporter = new MockExporter();
ProcessorConfig config = new ProcessorConfig();
config.type = ProcessorType.ATTRIBUTE;
config.id = "multiExclude";
config.exclude = new ProcessorIncludeExclude();
config.exclude.matchType = MatchType.STRICT;
config.exclude.spanNames = asList("svcA", "svcB");
config.exclude.attributes = new ArrayList<>();
ProcessorAttribute attributeWithValue = new ProcessorAttribute();
attributeWithValue.key = "testKey";
attributeWithValue.value = "testValue";
config.exclude.attributes.add(attributeWithValue);
ProcessorAttribute attributeWithNoValue = new ProcessorAttribute();
attributeWithNoValue.key = "testKey2";
config.exclude.attributes.add(attributeWithNoValue);
ProcessorAction action = new ProcessorAction("testKey", ProcessorActionType.DELETE, null, null, null, null);
List<ProcessorAction> actions = new ArrayList<>();
actions.add(action);
config.actions = actions;
SpanExporter exampleExporter = new ExporterWithAttributeProcessor(config, mockExporter);
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<SpanData> 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<SpanData> result = mockExporter.getSpans();
SpanData resultSpanA = result.get(0);
SpanData resultSpanB = result.get(1);
SpanData resultSpanC = result.get(2);
SpanData resultSpanD = result.get(3);
assertThat(resultSpanA.getAttributes().get(AttributeKey.stringKey("testKey"))).isEqualTo("testValue");
assertThat(resultSpanB.getAttributes().get(AttributeKey.stringKey("testKey"))).isNull();
assertThat(resultSpanC.getAttributes().get(AttributeKey.stringKey("testKey"))).isNull();
assertThat(resultSpanD.getAttributes().get(AttributeKey.stringKey("testKey"))).isNull();
}
use of com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorAttribute in project ApplicationInsights-Java by microsoft.
the class ExporterWithAttributeProcessorTest method simpleIncludeRegexNoValueTest.
@Test
void simpleIncludeRegexNoValueTest() {
MockExporter mockExporter = new MockExporter();
ProcessorConfig config = new ProcessorConfig();
config.type = ProcessorType.ATTRIBUTE;
config.id = "simpleIncludeRegexNoValue";
config.include = new ProcessorIncludeExclude();
config.include.matchType = MatchType.REGEXP;
config.include.spanNames = asList("svc.*", "test.*");
ProcessorAttribute attributeWithNoValue = new ProcessorAttribute();
attributeWithNoValue.key = "testKey";
config.include.attributes = new ArrayList<>();
config.include.attributes.add(attributeWithNoValue);
ProcessorAction action = new ProcessorAction("testKey", ProcessorActionType.UPDATE, "redacted", null, null, null);
List<ProcessorAction> actions = new ArrayList<>();
actions.add(action);
config.actions = actions;
SpanExporter exampleExporter = new ExporterWithAttributeProcessor(config, mockExporter);
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<SpanData> 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<SpanData> result = mockExporter.getSpans();
SpanData resultSpanA = result.get(0);
SpanData resultSpanB = result.get(1);
SpanData resultSpanC = result.get(2);
SpanData resultSpanE = result.get(4);
assertThat(resultSpanA.getAttributes().get(AttributeKey.stringKey("testKey"))).isEqualTo("redacted");
assertThat(resultSpanB.getAttributes().get(AttributeKey.stringKey("testKey"))).isEqualTo("redacted");
assertThat(resultSpanC.getAttributes().get(AttributeKey.stringKey("testKey"))).isEqualTo("testValue");
assertThat(resultSpanE.getAttributes().get(AttributeKey.stringKey("testKey"))).isEqualTo("redacted");
}
use of com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorAttribute in project ApplicationInsights-Java by microsoft.
the class ExporterWithAttributeProcessorTest method selectiveProcessingTest.
@Test
void selectiveProcessingTest() {
// With both include and exclude
MockExporter mockExporter = new MockExporter();
ProcessorConfig config = new ProcessorConfig();
config.type = ProcessorType.ATTRIBUTE;
config.id = "selectiveProcessing";
config.include = new ProcessorIncludeExclude();
config.exclude = new ProcessorIncludeExclude();
config.include.matchType = MatchType.STRICT;
config.include.spanNames = asList("svcA", "svcB");
config.exclude.matchType = MatchType.STRICT;
config.exclude.attributes = new ArrayList<>();
ProcessorAttribute attributeWithValue = new ProcessorAttribute();
attributeWithValue.key = "testKey";
attributeWithValue.value = "testValue";
config.exclude.attributes.add(attributeWithValue);
ProcessorAction action = new ProcessorAction("testKey2", ProcessorActionType.DELETE, null, null, null, null);
List<ProcessorAction> actions = new ArrayList<>();
actions.add(action);
config.actions = actions;
SpanExporter exampleExporter = new ExporterWithAttributeProcessor(config, mockExporter);
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<SpanData> 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<SpanData> result = mockExporter.getSpans();
SpanData resultSpanA = result.get(0);
SpanData resultSpanB = result.get(1);
SpanData resultSpanC = result.get(2);
assertThat(resultSpanA.getAttributes().get(AttributeKey.stringKey("testKey2"))).isEqualTo("testValue2");
assertThat(resultSpanB.getAttributes().get(AttributeKey.stringKey("testKey2"))).isNull();
assertThat(resultSpanC.getAttributes().get(AttributeKey.stringKey("testKey2"))).isEqualTo("testValue2");
}
use of com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorAttribute in project ApplicationInsights-Java by microsoft.
the class ExporterWithAttributeProcessorTest method multiIncludeTest.
@Test
void multiIncludeTest() {
MockExporter mockExporter = new MockExporter();
ProcessorConfig config = new ProcessorConfig();
config.type = ProcessorType.ATTRIBUTE;
config.id = "multiInclude";
config.include = new ProcessorIncludeExclude();
config.include.matchType = MatchType.STRICT;
config.include.spanNames = asList("svcA", "svcB");
config.include.attributes = new ArrayList<>();
ProcessorAttribute attributeWithValue = new ProcessorAttribute();
attributeWithValue.key = "testKey";
attributeWithValue.value = "testValue";
ProcessorAttribute attributeWithNoValue = new ProcessorAttribute();
attributeWithNoValue.key = "testKey2";
config.include.attributes.add(attributeWithValue);
config.include.attributes.add(attributeWithNoValue);
ProcessorAction action = new ProcessorAction("testKey", ProcessorActionType.DELETE, null, null, null, null);
List<ProcessorAction> actions = new ArrayList<>();
actions.add(action);
config.actions = actions;
SpanExporter exampleExporter = new ExporterWithAttributeProcessor(config, mockExporter);
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<SpanData> 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<SpanData> result = mockExporter.getSpans();
SpanData resultSpanA = result.get(0);
SpanData resultSpanB = result.get(1);
SpanData resultSpanC = result.get(2);
assertThat(resultSpanA.getAttributes().get(AttributeKey.stringKey("testKey"))).isNull();
assertThat(resultSpanB.getAttributes().get(AttributeKey.stringKey("testKey"))).isEqualTo("testValue");
assertThat(resultSpanC.getAttributes().get(AttributeKey.stringKey("testKey"))).isEqualTo("testValue");
}
use of com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorAttribute in project ApplicationInsights-Java by microsoft.
the class ExporterWithAttributeProcessorTest method simpleIncludeRegexValueTest.
@Test
void simpleIncludeRegexValueTest() {
MockExporter mockExporter = new MockExporter();
ProcessorConfig config = new ProcessorConfig();
config.type = ProcessorType.ATTRIBUTE;
config.id = "simpleIncludeRegexValue";
config.include = new ProcessorIncludeExclude();
config.include.matchType = MatchType.REGEXP;
config.include.spanNames = asList("svc.*", "test.*");
ProcessorAttribute attributeWithValue = new ProcessorAttribute();
attributeWithValue.key = "testKey";
attributeWithValue.value = "Value.*";
config.include.attributes = new ArrayList<>();
config.include.attributes.add(attributeWithValue);
ProcessorAction action = new ProcessorAction("testKey", ProcessorActionType.UPDATE, "redacted", null, null, null);
List<ProcessorAction> actions = new ArrayList<>();
actions.add(action);
config.actions = actions;
SpanExporter exampleExporter = new ExporterWithAttributeProcessor(config, mockExporter);
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<SpanData> 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<SpanData> result = mockExporter.getSpans();
SpanData resultSpanA = result.get(0);
SpanData resultSpanB = result.get(1);
SpanData resultSpanC = result.get(2);
SpanData resultSpanE = result.get(4);
assertThat(resultSpanA.getAttributes().get(AttributeKey.stringKey("testKey"))).isEqualTo("redacted");
assertThat(resultSpanB.getAttributes().get(AttributeKey.stringKey("testKey"))).isEqualTo("redacted");
assertThat(resultSpanC.getAttributes().get(AttributeKey.stringKey("testKey"))).isEqualTo("testValue");
assertThat(resultSpanE.getAttributes().get(AttributeKey.stringKey("testKey"))).isEqualTo("testV1");
}
Aggregations