Search in sources :

Example 91 with Attributes

use of io.opentelemetry.api.common.Attributes in project ApplicationInsights-Java by microsoft.

the class SamplingOverridesTest method shouldFilterStrictMatch.

@Test
void shouldFilterStrictMatch() {
    // given
    List<SamplingOverride> overrides = singletonList(newOverride(Configuration.SpanKind.SERVER, 0, newStrictAttribute("one", "1")));
    SamplingOverrides sampler = new SamplingOverrides(overrides);
    Attributes attributes = Attributes.of(AttributeKey.stringKey("one"), "1");
    // expect
    assertThat(sampler.getOverride(SpanKind.SERVER, attributes).getPercentage()).isEqualTo(0);
}
Also used : SamplingOverride(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.SamplingOverride) Attributes(io.opentelemetry.api.common.Attributes) Test(org.junit.jupiter.api.Test)

Example 92 with Attributes

use of io.opentelemetry.api.common.Attributes in project ApplicationInsights-Java by microsoft.

the class SamplingOverridesTest method shouldFilterKeyOnlyMatch.

@Test
void shouldFilterKeyOnlyMatch() {
    // given
    List<SamplingOverride> overrides = singletonList(newOverride(Configuration.SpanKind.SERVER, 0, newKeyOnlyAttribute("one")));
    SamplingOverrides sampler = new SamplingOverrides(overrides);
    Attributes attributes = Attributes.of(AttributeKey.stringKey("one"), "11");
    // expect
    assertThat(sampler.getOverride(SpanKind.SERVER, attributes).getPercentage()).isEqualTo(0);
}
Also used : SamplingOverride(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.SamplingOverride) Attributes(io.opentelemetry.api.common.Attributes) Test(org.junit.jupiter.api.Test)

Example 93 with Attributes

use of io.opentelemetry.api.common.Attributes in project ApplicationInsights-Java by microsoft.

the class SamplingOverridesTest method shouldNotFilterStrictMatchWithWrongSpanKind.

@Test
void shouldNotFilterStrictMatchWithWrongSpanKind() {
    // given
    List<SamplingOverride> overrides = singletonList(newOverride(Configuration.SpanKind.SERVER, 0, newStrictAttribute("one", "1")));
    SamplingOverrides sampler = new SamplingOverrides(overrides);
    Attributes attributes = Attributes.of(AttributeKey.stringKey("one"), "1");
    // expect
    assertThat(sampler.getOverride(SpanKind.CLIENT, attributes)).isNull();
}
Also used : SamplingOverride(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.SamplingOverride) Attributes(io.opentelemetry.api.common.Attributes) Test(org.junit.jupiter.api.Test)

Example 94 with Attributes

use of io.opentelemetry.api.common.Attributes in project ApplicationInsights-Java by microsoft.

the class SamplingOverridesTest method shouldSampleByDefault.

@Test
void shouldSampleByDefault() {
    // given
    List<SamplingOverride> overrides = new ArrayList<>();
    SamplingOverrides sampler = new SamplingOverrides(overrides);
    Attributes attributes = Attributes.empty();
    // expect
    assertThat(sampler.getOverride(SpanKind.SERVER, attributes)).isNull();
}
Also used : SamplingOverride(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.SamplingOverride) ArrayList(java.util.ArrayList) Attributes(io.opentelemetry.api.common.Attributes) Test(org.junit.jupiter.api.Test)

Example 95 with Attributes

use of io.opentelemetry.api.common.Attributes in project ApplicationInsights-Java by microsoft.

the class SamplingOverridesTest method shouldNotFilterBySpanKind.

@Test
void shouldNotFilterBySpanKind() {
    // given
    List<SamplingOverride> overrides = singletonList(newOverride(Configuration.SpanKind.SERVER, 0));
    SamplingOverrides sampler = new SamplingOverrides(overrides);
    Attributes attributes = Attributes.empty();
    // expect
    assertThat(sampler.getOverride(SpanKind.CLIENT, attributes)).isNull();
}
Also used : SamplingOverride(com.microsoft.applicationinsights.agent.internal.configuration.Configuration.SamplingOverride) Attributes(io.opentelemetry.api.common.Attributes) Test(org.junit.jupiter.api.Test)

Aggregations

Attributes (io.opentelemetry.api.common.Attributes)233 Test (org.junit.jupiter.api.Test)155 ResourceAttributes (io.opentelemetry.semconv.resource.attributes.ResourceAttributes)51 SemanticAttributes (io.opentelemetry.semconv.trace.attributes.SemanticAttributes)43 Resource (io.opentelemetry.sdk.resources.Resource)34 SpanData (io.opentelemetry.sdk.trace.data.SpanData)31 MetricAssertions.assertThat (io.opentelemetry.sdk.testing.assertj.MetricAssertions.assertThat)28 Test (org.junit.Test)28 InstrumentationLibraryInfo (io.opentelemetry.sdk.common.InstrumentationLibraryInfo)27 AttributesBuilder (io.opentelemetry.api.common.AttributesBuilder)25 Context (io.opentelemetry.context.Context)25 InMemoryMetricReader (io.opentelemetry.sdk.testing.exporter.InMemoryMetricReader)24 SpanContext (io.opentelemetry.api.trace.SpanContext)22 Duration (java.time.Duration)21 HashMap (java.util.HashMap)21 OpenTelemetryAssertions.attributeEntry (io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.attributeEntry)20 SamplingOverride (com.microsoft.applicationinsights.agent.internal.configuration.Configuration.SamplingOverride)18 AttributeKey (io.opentelemetry.api.common.AttributeKey)18 ExemplarData (io.opentelemetry.sdk.metrics.data.ExemplarData)18 TestClock (io.opentelemetry.sdk.testing.time.TestClock)18