Search in sources :

Example 6 with ToAttributeConfig

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

the class ExporterWithLogProcessorTest method invalidRegexInRulesTest.

@Test
void invalidRegexInRulesTest() {
    MockExporter mockExporter = new MockExporter();
    ProcessorConfig config = new ProcessorConfig();
    config.type = ProcessorType.LOG;
    config.id = "InvalidRegexInRules";
    config.body = new NameConfig();
    ToAttributeConfig toAttributeConfig = new ToAttributeConfig();
    toAttributeConfig.rules = new ArrayList<>();
    toAttributeConfig.rules.add("***");
    config.body.toAttributes = toAttributeConfig;
    assertThatThrownBy(() -> new ExporterWithLogProcessor(config, mockExporter)).isInstanceOf(FriendlyException.class);
}
Also used : NameConfig(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.NameConfig) ToAttributeConfig(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ToAttributeConfig) ProcessorConfig(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorConfig) Test(org.junit.jupiter.api.Test)

Example 7 with ToAttributeConfig

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

the class ExporterWithSpanProcessorTest method invalidRegexInRulesTest.

@Test
void invalidRegexInRulesTest() {
    MockExporter mockExporter = new MockExporter();
    ProcessorConfig config = new ProcessorConfig();
    config.type = ProcessorType.SPAN;
    config.id = "InvalidRegexInRules";
    config.name = new NameConfig();
    ToAttributeConfig toAttributeConfig = new ToAttributeConfig();
    toAttributeConfig.rules = new ArrayList<>();
    toAttributeConfig.rules.add("***");
    config.name.toAttributes = toAttributeConfig;
    assertThatThrownBy(() -> new ExporterWithSpanProcessor(config, mockExporter)).isInstanceOf(FriendlyException.class);
}
Also used : NameConfig(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.NameConfig) ToAttributeConfig(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ToAttributeConfig) ProcessorConfig(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorConfig) Test(org.junit.jupiter.api.Test)

Example 8 with ToAttributeConfig

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

the class ExporterWithSpanProcessorTest method inValidConfigTestWithToAttributesNoRulesTest.

@Test
void inValidConfigTestWithToAttributesNoRulesTest() {
    MockExporter mockExporter = new MockExporter();
    ProcessorConfig config = new ProcessorConfig();
    config.type = ProcessorType.SPAN;
    config.id = "inValidConfigTestWithToAttributesNoRules";
    config.name = new NameConfig();
    config.name.toAttributes = new ToAttributeConfig();
    assertThatThrownBy(() -> new ExporterWithSpanProcessor(config, mockExporter)).isInstanceOf(FriendlyException.class);
}
Also used : NameConfig(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.NameConfig) ToAttributeConfig(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ToAttributeConfig) ProcessorConfig(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorConfig) Test(org.junit.jupiter.api.Test)

Example 9 with ToAttributeConfig

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

the class ExporterWithSpanProcessorTest method multiRuleToAttributesTest.

@Test
void multiRuleToAttributesTest() {
    MockExporter mockExporter = new MockExporter();
    ProcessorConfig config = new ProcessorConfig();
    config.type = ProcessorType.SPAN;
    config.id = "MultiRuleToAttributes";
    config.name = new NameConfig();
    ToAttributeConfig toAttributeConfig = new ToAttributeConfig();
    toAttributeConfig.rules = new ArrayList<>();
    toAttributeConfig.rules.add("Password=(?<password1>[^ ]+)");
    toAttributeConfig.rules.add("Pass=(?<password2>[^ ]+)");
    config.name.toAttributes = toAttributeConfig;
    SpanExporter exampleExporter = new ExporterWithSpanProcessor(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").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").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)

Aggregations

NameConfig (com.microsoft.applicationinsights.agent.internal.configuration.Configuration.NameConfig)9 ProcessorConfig (com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorConfig)9 ToAttributeConfig (com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ToAttributeConfig)9 Test (org.junit.jupiter.api.Test)9 Span (io.opentelemetry.api.trace.Span)5 ReadableSpan (io.opentelemetry.sdk.trace.ReadableSpan)5 SpanData (io.opentelemetry.sdk.trace.data.SpanData)5 SpanExporter (io.opentelemetry.sdk.trace.export.SpanExporter)5 ArrayList (java.util.ArrayList)5 ProcessorIncludeExclude (com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ProcessorIncludeExclude)1