use of com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorAction in project ApplicationInsights-Java by microsoft.
the class ExporterWithAttributeProcessorTest method simpleExcludeRegexTest.
@Test
void simpleExcludeRegexTest() {
MockExporter mockExporter = new MockExporter();
ProcessorConfig config = new ProcessorConfig();
config.type = ProcessorType.ATTRIBUTE;
config.id = "simpleExcludeRegex";
config.exclude = new ProcessorIncludeExclude();
config.exclude.matchType = MatchType.REGEXP;
config.exclude.spanNames = Collections.singletonList("svc.*");
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", "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<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"))).isEqualTo("testValue");
assertThat(resultSpanC.getAttributes().get(AttributeKey.stringKey("testKey"))).isEqualTo("redacted");
assertThat(resultSpanD.getAttributes().get(AttributeKey.stringKey("testKey"))).isEqualTo("redacted");
}
use of com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorAction in project ApplicationInsights-Java by microsoft.
the class ExporterWithAttributeProcessorTest method simpleIncludeRegexTest.
@Test
void simpleIncludeRegexTest() {
MockExporter mockExporter = new MockExporter();
ProcessorConfig config = new ProcessorConfig();
config.type = ProcessorType.ATTRIBUTE;
config.id = "simpleIncludeRegex";
config.include = new ProcessorIncludeExclude();
config.include.matchType = MatchType.REGEXP;
config.include.spanNames = asList("svc.*", "test.*");
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", "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<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"))).isEqualTo("redacted");
assertThat(resultSpanB.getAttributes().get(AttributeKey.stringKey("testKey"))).isEqualTo("redacted");
assertThat(resultSpanC.getAttributes().get(AttributeKey.stringKey("testKey"))).isEqualTo("testValue");
}
use of com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorAction in project ApplicationInsights-Java by microsoft.
the class ExporterWithAttributeProcessorTest method inValidConfigTestWithNoValueInActionTest.
@Test
void inValidConfigTestWithNoValueInActionTest() {
MockExporter mockExporter = new MockExporter();
ProcessorConfig config = new ProcessorConfig();
config.type = ProcessorType.ATTRIBUTE;
config.id = "inValidConfigTestWithNoValueInAction";
config.include = new ProcessorIncludeExclude();
config.include.matchType = MatchType.STRICT;
config.include.spanNames = asList("svcA", "svcB");
ProcessorAction action = new ProcessorAction("testKey", ProcessorActionType.UPDATE, null, null, null, null);
List<ProcessorAction> actions = new ArrayList<>();
actions.add(action);
config.actions = actions;
assertThatThrownBy(() -> new ExporterWithAttributeProcessor(config, mockExporter)).isInstanceOf(FriendlyException.class);
}
use of com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorAction in project ApplicationInsights-Java by microsoft.
the class ExporterWithAttributeProcessorTest method actionInsertAndUpdateSameAttributeTest.
@Test
void actionInsertAndUpdateSameAttributeTest() {
MockExporter mockExporter = new MockExporter();
ProcessorConfig config = new ProcessorConfig();
config.type = ProcessorType.ATTRIBUTE;
config.id = "actionInsertAndUpdate";
ProcessorAction action = new ProcessorAction("testNewKey", ProcessorActionType.INSERT, "testNewValue", null, null, null);
ProcessorAction updateAction = new ProcessorAction("testNewKey", ProcessorActionType.UPDATE, "testNewValue2", null, null, null);
List<ProcessorAction> actions = new ArrayList<>();
actions.add(action);
actions.add(updateAction);
config.actions = actions;
SpanExporter exampleExporter = new ExporterWithAttributeProcessor(config, mockExporter);
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<SpanData> spans = new ArrayList<>();
spans.add(spanData);
exampleExporter.export(spans);
// verify that resulting spans are filtered in the way we want
List<SpanData> result = mockExporter.getSpans();
SpanData resultSpan = result.get(0);
assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("testNewKey"))).isNotNull();
assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("testNewKey"))).isEqualTo("testNewValue2");
}
use of com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorAction in project ApplicationInsights-Java by microsoft.
the class ExporterWithAttributeProcessorTest method actionSimpleUpdateTest.
@Test
void actionSimpleUpdateTest() {
MockExporter mockExporter = new MockExporter();
ProcessorConfig config = new ProcessorConfig();
config.type = ProcessorType.ATTRIBUTE;
config.id = "actionSimpleUpdate";
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 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<SpanData> spans = new ArrayList<>();
spans.add(spanData);
spans.add(logData);
exampleExporter.export(spans);
// verify that resulting spans are filtered in the way we want
List<SpanData> result = mockExporter.getSpans();
SpanData resultSpan = result.get(0);
SpanData resultLog = result.get(1);
assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("testKey"))).isEqualTo("redacted");
assertThat(resultLog.getAttributes().get(AttributeKey.stringKey("testKey"))).isEqualTo("redacted");
}
Aggregations