Search in sources :

Example 31 with ProcessorConfig

use of com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorConfig 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");
}
Also used : ProcessorAction(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorAction) SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) SpanData(io.opentelemetry.sdk.trace.data.SpanData) ArrayList(java.util.ArrayList) ProcessorIncludeExclude(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorIncludeExclude) Span(io.opentelemetry.api.trace.Span) ReadableSpan(io.opentelemetry.sdk.trace.ReadableSpan) ProcessorConfig(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorConfig) Test(org.junit.jupiter.api.Test)

Example 32 with ProcessorConfig

use of com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorConfig 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);
}
Also used : ProcessorAction(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorAction) ArrayList(java.util.ArrayList) ProcessorIncludeExclude(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorIncludeExclude) ProcessorConfig(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorConfig) Test(org.junit.jupiter.api.Test)

Example 33 with ProcessorConfig

use of com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorConfig 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");
}
Also used : ProcessorAction(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorAction) SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) SpanData(io.opentelemetry.sdk.trace.data.SpanData) ArrayList(java.util.ArrayList) Span(io.opentelemetry.api.trace.Span) ReadableSpan(io.opentelemetry.sdk.trace.ReadableSpan) ReadableSpan(io.opentelemetry.sdk.trace.ReadableSpan) ProcessorConfig(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorConfig) Test(org.junit.jupiter.api.Test)

Example 34 with ProcessorConfig

use of com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorConfig 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");
}
Also used : ProcessorAction(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorAction) SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) SpanData(io.opentelemetry.sdk.trace.data.SpanData) ArrayList(java.util.ArrayList) Span(io.opentelemetry.api.trace.Span) ReadableSpan(io.opentelemetry.sdk.trace.ReadableSpan) ReadableSpan(io.opentelemetry.sdk.trace.ReadableSpan) ProcessorConfig(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorConfig) Test(org.junit.jupiter.api.Test)

Example 35 with ProcessorConfig

use of com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorConfig in project ApplicationInsights-Java by microsoft.

the class ExporterWithAttributeProcessorTest method actionInsertWithMaskTest.

@Test
void actionInsertWithMaskTest() {
    MockExporter mockExporter = new MockExporter();
    ProcessorConfig config = new ProcessorConfig();
    config.type = ProcessorType.ATTRIBUTE;
    config.id = "actionMask";
    String regex = "^(?<uriNoCard>.*\\/cardid\\/)(?<cardStart>[0-9]{6})[0-9]{6}(?<cardEnd>[0-9]{4,6}).*";
    String regex2 = "(?<httpPath>.+)";
    String regex3 = "(?<httpPath>[a-zA-Z]+)";
    ProcessorAction action = new ProcessorAction("testKey", ProcessorActionType.MASK, null, null, regex, "${uriNoCard}****${cardEnd}");
    ProcessorAction action2 = new ProcessorAction("testKey2", ProcessorActionType.MASK, null, null, regex, "${uriNoCard}${cardStart}****${cardEnd}");
    ProcessorAction action3 = new ProcessorAction("testKey3", ProcessorActionType.MASK, null, null, regex, "${cardStart}****${cardStart}");
    ProcessorAction action4 = new ProcessorAction("testKey4", ProcessorActionType.MASK, null, null, regex2, "*${httpPath}*");
    ProcessorAction action5 = new ProcessorAction("testKey5", ProcessorActionType.MASK, null, null, regex3, "**${httpPath}**");
    List<ProcessorAction> actions = new ArrayList<>();
    actions.add(action);
    actions.add(action2);
    actions.add(action3);
    actions.add(action4);
    actions.add(action5);
    config.actions = actions;
    SpanExporter exampleExporter = new ExporterWithAttributeProcessor(config, mockExporter);
    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<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("testKey"))).isEqualTo("http://example.com/cardid/****7899");
    assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("testKey2"))).isEqualTo("http://example.com/cardid/123456****7899");
    assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("testKey3"))).isEqualTo("123456****123456");
    assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("TESTKEY2"))).isEqualTo("testValue2");
    assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("testKey4"))).isEqualTo("*/TelemetryProcessors/test*");
    assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("testKey5"))).isEqualTo("/**abc**/**xyz**");
}
Also used : ProcessorAction(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorAction) SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) SpanData(io.opentelemetry.sdk.trace.data.SpanData) ArrayList(java.util.ArrayList) Span(io.opentelemetry.api.trace.Span) ReadableSpan(io.opentelemetry.sdk.trace.ReadableSpan) ReadableSpan(io.opentelemetry.sdk.trace.ReadableSpan) ProcessorConfig(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorConfig) Test(org.junit.jupiter.api.Test)

Aggregations

ProcessorConfig (com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorConfig)52 Test (org.junit.jupiter.api.Test)50 ArrayList (java.util.ArrayList)41 SpanData (io.opentelemetry.sdk.trace.data.SpanData)38 SpanExporter (io.opentelemetry.sdk.trace.export.SpanExporter)38 Span (io.opentelemetry.api.trace.Span)37 ReadableSpan (io.opentelemetry.sdk.trace.ReadableSpan)37 ProcessorAction (com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorAction)26 NameConfig (com.microsoft.applicationinsights.agent.internal.configuration.Configuration.NameConfig)20 ProcessorIncludeExclude (com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorIncludeExclude)16 ToAttributeConfig (com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ToAttributeConfig)9 ProcessorAttribute (com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorAttribute)5 Configuration (com.microsoft.applicationinsights.agent.internal.configuration.Configuration)2 TelemetryClient (com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryClient)2 AutoService (com.google.auto.service.AutoService)1 FriendlyException (com.microsoft.applicationinsights.agent.internal.common.FriendlyException)1 PreviewConfiguration (com.microsoft.applicationinsights.agent.internal.configuration.Configuration.PreviewConfiguration)1 ProfilerConfiguration (com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProfilerConfiguration)1 RpConfiguration (com.microsoft.applicationinsights.agent.internal.configuration.RpConfiguration)1 Exporter (com.microsoft.applicationinsights.agent.internal.exporter.Exporter)1