Search in sources :

Example 11 with ProcessorAction

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

the class ExporterWithAttributeProcessorTest method simpleExcludeTest.

@Test
void simpleExcludeTest() {
    MockExporter mockExporter = new MockExporter();
    ProcessorConfig config = new ProcessorConfig();
    config.type = ProcessorType.ATTRIBUTE;
    config.id = "simpleExclude";
    config.exclude = new ProcessorIncludeExclude();
    config.exclude.matchType = MatchType.STRICT;
    config.exclude.spanNames = asList("svcA", "svcB");
    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("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"))).isEqualTo("testValue");
    assertThat(resultSpanB.getAttributes().get(AttributeKey.stringKey("testKey"))).isEqualTo("testValue");
    assertThat(resultSpanC.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) 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 12 with ProcessorAction

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

the class ExporterWithAttributeProcessorTest method actionInsertWithExtractDuplicateTest.

@Test
void actionInsertWithExtractDuplicateTest() {
    MockExporter mockExporter = new MockExporter();
    ProcessorConfig config = new ProcessorConfig();
    config.type = ProcessorType.ATTRIBUTE;
    config.id = "actionExtract";
    String regex = "^(?<httpProtocol>.*)://(?<httpDomain>.*)/(?<httpPath>.*)([?&])(?<httpQueryParams>.*)";
    ProcessorAction action = new ProcessorAction("testKey", ProcessorActionType.EXTRACT, null, null, regex, 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", "http://example.com/path?queryParam1=value1,queryParam2=value2").setAttribute("httpPath", "oldPath").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("httpProtocol"))).isEqualTo("http");
    assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("httpDomain"))).isEqualTo("example.com");
    assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("httpPath"))).isEqualTo("path");
    assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("httpPath"))).isNotEqualTo("oldPath");
    assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("httpQueryParams"))).isEqualTo("queryParam1=value1,queryParam2=value2");
    assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("testKey"))).isEqualTo("http://example.com/path?queryParam1=value1,queryParam2=value2");
}
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 13 with ProcessorAction

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

the class ExporterWithAttributeProcessorTest method actionInsertWithDuplicateTest.

@Test
void actionInsertWithDuplicateTest() {
    MockExporter mockExporter = new MockExporter();
    ProcessorConfig config = new ProcessorConfig();
    config.type = ProcessorType.ATTRIBUTE;
    config.id = "actionInsertWithDuplicate";
    ProcessorAction action = new ProcessorAction("testNewKey", ProcessorActionType.INSERT, "testNewValue", 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();
    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("testValue");
    assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("testKey"))).isNotEqualTo("testNewValue");
    assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("one"))).isEqualTo("1");
}
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 14 with ProcessorAction

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

the class ExporterWithAttributeProcessorTest method actionUpdateFromAttributeUpdateTest.

@Test
void actionUpdateFromAttributeUpdateTest() {
    MockExporter mockExporter = new MockExporter();
    ProcessorConfig config = new ProcessorConfig();
    config.type = ProcessorType.ATTRIBUTE;
    config.id = "actionUpdateFromAttributeUpdate";
    ProcessorAction action = new ProcessorAction("testKey", ProcessorActionType.UPDATE, null, "testKey2", 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("testKey2", "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("testKey"))).isEqualTo("testValue2");
}
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 15 with ProcessorAction

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

the class ExporterWithAttributeProcessorTest method complexActionTest.

@Test
void complexActionTest() {
    MockExporter mockExporter = new MockExporter();
    ProcessorConfig config = new ProcessorConfig();
    config.type = ProcessorType.ATTRIBUTE;
    config.id = "complexAction";
    ProcessorAction updateAction = new ProcessorAction("testKey", ProcessorActionType.UPDATE, "redacted", null, null, null);
    ProcessorAction deleteAction = new ProcessorAction("testKey2", ProcessorActionType.DELETE, null, null, null, null);
    List<ProcessorAction> actions = new ArrayList<>();
    actions.add(updateAction);
    actions.add(deleteAction);
    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("testKey2", "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("testKey"))).isEqualTo("redacted");
    assertThat(resultSpan.getAttributes().get(AttributeKey.stringKey("testKey2"))).isNull();
}
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

ProcessorAction (com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorAction)26 ProcessorConfig (com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorConfig)26 ArrayList (java.util.ArrayList)26 Test (org.junit.jupiter.api.Test)26 Span (io.opentelemetry.api.trace.Span)23 ReadableSpan (io.opentelemetry.sdk.trace.ReadableSpan)23 SpanData (io.opentelemetry.sdk.trace.data.SpanData)23 SpanExporter (io.opentelemetry.sdk.trace.export.SpanExporter)23 ProcessorIncludeExclude (com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorIncludeExclude)14 ProcessorAttribute (com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorAttribute)5