Search in sources :

Example 16 with ProcessorConfig

use of com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorConfig 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)

Example 17 with ProcessorConfig

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

the class ExporterWithLogProcessorTest method noBodyObjectTest.

@Test
void noBodyObjectTest() {
    MockExporter mockExporter = new MockExporter();
    ProcessorConfig config = new ProcessorConfig();
    config.type = ProcessorType.LOG;
    config.id = "noBodyObjectTest";
    assertThatThrownBy(() -> new ExporterWithLogProcessor(config, mockExporter)).isInstanceOf(FriendlyException.class);
}
Also used : ProcessorConfig(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorConfig) Test(org.junit.jupiter.api.Test)

Example 18 with ProcessorConfig

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

the class ExporterWithLogProcessorTest method multiRuleToAttributesTest.

@Test
void multiRuleToAttributesTest() {
    MockExporter mockExporter = new MockExporter();
    ProcessorConfig config = new ProcessorConfig();
    config.type = ProcessorType.LOG;
    config.id = "MultiRuleToAttributes";
    config.body = new NameConfig();
    ToAttributeConfig toAttributeConfig = new ToAttributeConfig();
    toAttributeConfig.rules = new ArrayList<>();
    toAttributeConfig.rules.add("Password=(?<password1>[^ ]+)");
    toAttributeConfig.rules.add("Pass=(?<password2>[^ ]+)");
    config.body.toAttributes = toAttributeConfig;
    SpanExporter exampleExporter = new ExporterWithLogProcessor(config, mockExporter);
    Span spanA = tracer.spanBuilder("yyyPassword=123 aba Pass=555 xyx Pass=777 zzz").setAttribute("one", "1").setAttribute("two", 2L).setAttribute("db.svc", "location").setAttribute("operation", "get").setAttribute("id", "1234").setAttribute("applicationinsights.internal.log", true).startSpan();
    Span spanB = tracer.spanBuilder("yyyPassword=**** aba").setAttribute("one", "1").setAttribute("two", 2L).setAttribute("db.svc", "location").setAttribute("operation", "get").setAttribute("id", "1234").setAttribute("password", "234").setAttribute("applicationinsights.internal.log", true).startSpan();
    SpanData spanDataA = ((ReadableSpan) spanA).toSpanData();
    SpanData spanDataB = ((ReadableSpan) spanB).toSpanData();
    List<SpanData> spans = new ArrayList<>();
    spans.add(spanDataA);
    spans.add(spanDataB);
    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);
    assertThat(Objects.requireNonNull(resultSpanA.getAttributes().get(AttributeKey.stringKey("password1")))).isNotNull();
    assertThat(Objects.requireNonNull(resultSpanA.getAttributes().get(AttributeKey.stringKey("password1")))).isEqualTo("123");
    assertThat(Objects.requireNonNull(resultSpanA.getAttributes().get(AttributeKey.stringKey("password2")))).isNotNull();
    assertThat(Objects.requireNonNull(resultSpanA.getAttributes().get(AttributeKey.stringKey("password2")))).isEqualTo("555");
    assertThat(resultSpanA.getName()).isEqualTo("yyyPassword={password1} aba Pass={password2} xyx Pass=777 zzz");
    assertThat(Objects.requireNonNull(resultSpanB.getAttributes().get(AttributeKey.stringKey("password1")))).isNotNull();
    assertThat(Objects.requireNonNull(resultSpanB.getAttributes().get(AttributeKey.stringKey("password1")))).isEqualTo("****");
    assertThat(resultSpanB.getName()).isEqualTo("yyyPassword={password1} aba");
}
Also used : SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) SpanData(io.opentelemetry.sdk.trace.data.SpanData) NameConfig(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.NameConfig) ArrayList(java.util.ArrayList) ToAttributeConfig(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ToAttributeConfig) 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 19 with ProcessorConfig

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

the class ExporterWithLogProcessorTest method simpleRenameLogMessageTest.

@Test
void simpleRenameLogMessageTest() {
    MockExporter mockExporter = new MockExporter();
    ProcessorConfig config = new ProcessorConfig();
    config.type = ProcessorType.LOG;
    config.id = "SimpleRenameLogMessage";
    config.body = new NameConfig();
    config.body.fromAttributes = Arrays.asList("db.svc", "operation", "id");
    SpanExporter exampleExporter = new ExporterWithLogProcessor(config, mockExporter);
    Span span = tracer.spanBuilder("logA").setAttribute("one", "1").setAttribute("two", 2L).setAttribute("db.svc", "location").setAttribute("operation", "get").setAttribute("id", "1234").setAttribute("applicationinsights.internal.log", true).startSpan();
    SpanData spanData = ((ReadableSpan) span).toSpanData();
    List<SpanData> spans = new ArrayList<>();
    spans.add(spanData);
    exampleExporter.export(spans);
    // verify that resulting logs are filtered in the way we want
    List<SpanData> result = mockExporter.getSpans();
    SpanData resultSpan = result.get(0);
    assertThat(resultSpan.getName()).isEqualTo("locationget1234");
}
Also used : SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) SpanData(io.opentelemetry.sdk.trace.data.SpanData) NameConfig(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.NameConfig) 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 20 with ProcessorConfig

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

the class ExporterWithLogProcessorTest method simpleToAttributesTest.

@Test
void simpleToAttributesTest() {
    MockExporter mockExporter = new MockExporter();
    ProcessorConfig config = new ProcessorConfig();
    config.type = ProcessorType.LOG;
    config.id = "SimpleToAttributes";
    config.body = new NameConfig();
    ToAttributeConfig toAttributeConfig = new ToAttributeConfig();
    toAttributeConfig.rules = new ArrayList<>();
    toAttributeConfig.rules.add("^/api/v1/document/(?<documentId>.*)/update$");
    config.body.toAttributes = toAttributeConfig;
    SpanExporter exampleExporter = new ExporterWithLogProcessor(config, mockExporter);
    Span span = tracer.spanBuilder("/api/v1/document/12345678/update").setAttribute("one", "1").setAttribute("two", 2L).setAttribute("db.svc", "location").setAttribute("operation", "get").setAttribute("id", "1234").setAttribute("applicationinsights.internal.log", true).startSpan();
    SpanData spanData = ((ReadableSpan) span).toSpanData();
    List<SpanData> spans = new ArrayList<>();
    spans.add(spanData);
    exampleExporter.export(spans);
    // verify that resulting logs are filtered in the way we want
    List<SpanData> result = mockExporter.getSpans();
    SpanData resultSpan = result.get(0);
    assertThat(Objects.requireNonNull(resultSpan.getAttributes().get(AttributeKey.stringKey("documentId")))).isNotNull();
    assertThat(Objects.requireNonNull(resultSpan.getAttributes().get(AttributeKey.stringKey("documentId")))).isEqualTo("12345678");
    assertThat(resultSpan.getName()).isEqualTo("/api/v1/document/{documentId}/update");
}
Also used : SpanExporter(io.opentelemetry.sdk.trace.export.SpanExporter) SpanData(io.opentelemetry.sdk.trace.data.SpanData) NameConfig(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.NameConfig) ArrayList(java.util.ArrayList) ToAttributeConfig(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ToAttributeConfig) 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