Search in sources :

Example 11 with NameConfig

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

the class ExporterWithLogProcessorTest method simpleRenameLogWithMissingKeysTest.

@Test
void simpleRenameLogWithMissingKeysTest() {
    MockExporter mockExporter = new MockExporter();
    ProcessorConfig config = new ProcessorConfig();
    config.type = ProcessorType.LOG;
    config.id = "SimpleRenameLogWithMissingKeys";
    config.body = new NameConfig();
    config.body.fromAttributes = Arrays.asList("db.svc", "operation", "id");
    config.body.separator = "::";
    SpanExporter exampleExporter = new ExporterWithLogProcessor(config, mockExporter);
    Span span = tracer.spanBuilder("svcA").setAttribute("one", "1").setAttribute("two", 2L).setAttribute("db.svc", "location").setAttribute("operation", "get").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("svcA");
}
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 12 with NameConfig

use of com.microsoft.applicationinsights.agent.internal.configuration.Configuration.NameConfig 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 13 with NameConfig

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

the class ExporterWithSpanProcessorTest method simpleRenameSpanTestWithLogProcessor.

@Test
void simpleRenameSpanTestWithLogProcessor() {
    MockExporter mockExporter = new MockExporter();
    ProcessorConfig config = new ProcessorConfig();
    config.type = ProcessorType.SPAN;
    config.id = "SimpleRenameSpan";
    config.name = new NameConfig();
    config.name.fromAttributes = Arrays.asList("db.svc", "operation", "id");
    SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockExporter);
    Span span = tracer.spanBuilder("svcA").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 spans are not modified
    List<SpanData> result = mockExporter.getSpans();
    SpanData resultSpan = result.get(0);
    assertThat(resultSpan.getName()).isEqualTo("svcA");
}
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 14 with NameConfig

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

the class ExporterWithSpanProcessorTest method simpleRenameSpanTest.

@Test
void simpleRenameSpanTest() {
    MockExporter mockExporter = new MockExporter();
    ProcessorConfig config = new ProcessorConfig();
    config.type = ProcessorType.SPAN;
    config.id = "SimpleRenameSpan";
    config.name = new NameConfig();
    config.name.fromAttributes = Arrays.asList("db.svc", "operation", "id");
    SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockExporter);
    Span span = tracer.spanBuilder("svcA").setAttribute("one", "1").setAttribute("two", 2L).setAttribute("db.svc", "location").setAttribute("operation", "get").setAttribute("id", "1234").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.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 15 with NameConfig

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

Aggregations

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