Search in sources :

Example 6 with NameConfig

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

the class ExporterWithSpanProcessorTest method simpleToAttributesTest.

@Test
void simpleToAttributesTest() {
    MockExporter mockExporter = new MockExporter();
    ProcessorConfig config = new ProcessorConfig();
    config.type = ProcessorType.SPAN;
    config.id = "SimpleToAttributes";
    config.name = new NameConfig();
    ToAttributeConfig toAttributeConfig = new ToAttributeConfig();
    toAttributeConfig.rules = new ArrayList<>();
    toAttributeConfig.rules.add("^/api/v1/document/(?<documentId>.*)/update$");
    config.name.toAttributes = toAttributeConfig;
    SpanExporter exampleExporter = new ExporterWithSpanProcessor(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").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(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)

Example 7 with NameConfig

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

the class ExporterWithSpanProcessorTest method extractAttributesWithIncludeExcludeTest.

@Test
void extractAttributesWithIncludeExcludeTest() {
    MockExporter mockExporter = new MockExporter();
    ProcessorConfig config = new ProcessorConfig();
    config.type = ProcessorType.SPAN;
    config.id = "ExtractAttributesWithIncludeExclude";
    config.name = new NameConfig();
    config.include = new ProcessorIncludeExclude();
    config.include.matchType = MatchType.REGEXP;
    config.include.spanNames = Arrays.asList("^(.*?)/(.*?)$");
    config.exclude = new ProcessorIncludeExclude();
    config.exclude.matchType = MatchType.STRICT;
    config.exclude.spanNames = Arrays.asList("donot/change");
    config.name.toAttributes = new ToAttributeConfig();
    config.name.toAttributes.rules = Arrays.asList("(?<operationwebsite>.*?)$");
    SpanExporter exampleExporter = new ExporterWithSpanProcessor(config, mockExporter);
    Span spanA = tracer.spanBuilder("svcA/test").setAttribute("one", "1").setAttribute("two", 2L).setAttribute("db.svc", "location").setAttribute("operation", "get").setAttribute("id", "1234").startSpan();
    Span spanB = tracer.spanBuilder("svcB/test").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("donot/change").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("{operationwebsite}");
    assertThat(resultSpanA.getAttributes().get(AttributeKey.stringKey("operationwebsite"))).isNotNull();
    assertThat(Objects.requireNonNull(resultSpanA.getAttributes().get(AttributeKey.stringKey("operationwebsite")))).isEqualTo("svcA/test");
    assertThat(resultSpanB.getName()).isEqualTo("{operationwebsite}");
    assertThat(resultSpanB.getAttributes().get(AttributeKey.stringKey("operationwebsite"))).isNotNull();
    assertThat(Objects.requireNonNull(resultSpanB.getAttributes().get(AttributeKey.stringKey("operationwebsite")))).isEqualTo("svcB/test");
    assertThat(resultSpanC.getName()).isEqualTo("svcC");
    assertThat(resultSpanD.getName()).isEqualTo("donot/change");
}
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) ToAttributeConfig(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.ToAttributeConfig) 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 NameConfig

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

the class ExporterWithSpanProcessorTest method simpleRenameSpanWithSeparatorTest.

@Test
void simpleRenameSpanWithSeparatorTest() {
    MockExporter mockExporter = new MockExporter();
    ProcessorConfig config = new ProcessorConfig();
    config.type = ProcessorType.SPAN;
    config.id = "SimpleRenameSpanWithSeparator";
    config.name = new NameConfig();
    config.name.fromAttributes = Arrays.asList("db.svc", "operation", "id");
    config.name.separator = "::";
    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("location::get::1234");
}
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 9 with NameConfig

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

the class ExporterWithLogProcessorTest method inValidConfigTestWithNoFromOrToAttributesTest.

@Test
void inValidConfigTestWithNoFromOrToAttributesTest() {
    MockExporter mockExporter = new MockExporter();
    ProcessorConfig config = new ProcessorConfig();
    config.type = ProcessorType.LOG;
    config.id = "inValidConfigTestWithToAttributesNoRules";
    config.body = new NameConfig();
    assertThatThrownBy(() -> new ExporterWithLogProcessor(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 10 with NameConfig

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

the class ExporterWithLogProcessorTest method inValidConfigTestWithToAttributesNoRulesTest.

@Test
void inValidConfigTestWithToAttributesNoRulesTest() {
    MockExporter mockExporter = new MockExporter();
    ProcessorConfig config = new ProcessorConfig();
    config.type = ProcessorType.LOG;
    config.id = "inValidConfigTestWithToAttributesNoRules";
    config.body = new NameConfig();
    config.body.toAttributes = new 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)

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