Search in sources :

Example 6 with ProcessorConfig

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

the class ExporterWithAttributeProcessorTest method simpleIncludeWithSpanNamesTest.

@Test
void simpleIncludeWithSpanNamesTest() {
    MockExporter mockExporter = new MockExporter();
    ProcessorConfig config = new ProcessorConfig();
    config.type = ProcessorType.ATTRIBUTE;
    config.id = "simpleIncludeWithSpanNames";
    config.include = new ProcessorIncludeExclude();
    config.include.matchType = MatchType.STRICT;
    config.include.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();
    Span logA = tracer.spanBuilder("svcA").setAttribute("one", "1").setAttribute("two", 2L).setAttribute("testKey", "testValue").setAttribute("testKey2", "testValue2").setAttribute("applicationinsights.internal.log", true).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) logA).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 resultLogA = 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");
    // Make sure log is not updated, since we have spanNames in include criteria
    assertThat(resultLogA.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 7 with ProcessorConfig

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

the class ExporterWithAttributeProcessorTest method simpleIncludeHashTest.

@Test
void simpleIncludeHashTest() {
    MockExporter mockExporter = new MockExporter();
    ProcessorConfig config = new ProcessorConfig();
    config.type = ProcessorType.ATTRIBUTE;
    config.id = "simpleIncludeHash";
    config.include = new ProcessorIncludeExclude();
    config.include.matchType = MatchType.STRICT;
    config.include.spanNames = asList("svcA", "svcB", "svcC");
    ProcessorAction action = new ProcessorAction("testKey", ProcessorActionType.HASH, 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", 2L).setAttribute("testKey2", "testValue2").startSpan();
    Span spanC = tracer.spanBuilder("svcC").setAttribute("two", 2L).setAttribute("testKey", 123).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 resultSpanD = result.get(3);
    assertThat(resultSpanA.getAttributes().get(AttributeKey.stringKey("testKey"))).isNotEqualTo("testValue");
    assertThat(resultSpanB.getAttributes().get(AttributeKey.stringKey("testKey2"))).isEqualTo("testValue2");
    assertThat(resultSpanD.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 8 with ProcessorConfig

use of com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorConfig 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");
}
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) ProcessorAttribute(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorAttribute) Test(org.junit.jupiter.api.Test)

Example 9 with ProcessorConfig

use of com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorConfig 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");
}
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) ProcessorAttribute(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorAttribute) Test(org.junit.jupiter.api.Test)

Example 10 with ProcessorConfig

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

the class ExporterWithAttributeProcessorTest method simpleIncludeTest.

@Test
void simpleIncludeTest() {
    MockExporter mockExporter = new MockExporter();
    ProcessorConfig config = new ProcessorConfig();
    config.type = ProcessorType.ATTRIBUTE;
    config.id = "simpleInclude";
    config.include = new ProcessorIncludeExclude();
    config.include.matchType = MatchType.STRICT;
    config.include.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("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)

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