Search in sources :

Example 46 with ProcessorConfig

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

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

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

the class ExporterWithSpanProcessorTest method renameSpanWithIncludeTest.

@Test
void renameSpanWithIncludeTest() {
    MockExporter mockExporter = new MockExporter();
    ProcessorConfig config = new ProcessorConfig();
    config.type = ProcessorType.SPAN;
    config.id = "RenameSpanWithInclude";
    config.name = new NameConfig();
    config.name.fromAttributes = Arrays.asList("db.svc", "operation", "id");
    config.include = new ProcessorIncludeExclude();
    config.include.matchType = MatchType.STRICT;
    config.include.spanNames = Arrays.asList("svcA", "svcB");
    SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockExporter);
    Span spanA = tracer.spanBuilder("svcA").setAttribute("one", "1").setAttribute("two", 2L).setAttribute("db.svc", "location").setAttribute("operation", "get").setAttribute("id", "1234").startSpan();
    Span spanB = tracer.spanBuilder("svcB").setAttribute("one", "1").setAttribute("testKey", "testValue").setAttribute("testKey2", "testValue2").setAttribute("db.svc", "location").setAttribute("operation", "get").setAttribute("id", "1234").startSpan();
    Span spanC = tracer.spanBuilder("svcC").setAttribute("two", 2L).setAttribute("testKey", "testValue").setAttribute("testKey2", "testValue2").setAttribute("db.svc", "location").setAttribute("operation", "get").setAttribute("id", "1234").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);
    SpanData resultSpanD = result.get(3);
    assertThat(resultSpanA.getName()).isEqualTo("locationget1234");
    assertThat(resultSpanB.getName()).isEqualTo("locationget1234");
    assertThat(resultSpanC.getName()).isEqualTo("svcC");
    assertThat(resultSpanD.getName()).isEqualTo("svcD");
}
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) 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 49 with ProcessorConfig

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

the class ExporterWithSpanProcessorTest method inValidConfigTestWithNoFromOrToAttributesTest.

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

Example 50 with ProcessorConfig

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

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