Search in sources :

Example 86 with Attributes

use of io.opentelemetry.api.common.Attributes in project splunk-otel-android by signalfx.

the class NetworkMonitorTest method networkAvailable_cellular.

@Test
public void networkAvailable_cellular() {
    NetworkMonitor.TracingConnectionStateListener listener = new NetworkMonitor.TracingConnectionStateListener(tracer, new AtomicBoolean(true));
    listener.onAvailable(true, new CurrentNetwork(NetworkState.TRANSPORT_CELLULAR, "LTE"));
    List<SpanData> spans = otelTesting.getSpans();
    assertEquals(1, spans.size());
    SpanData spanData = spans.get(0);
    assertEquals("network.change", spanData.getName());
    Attributes attributes = spanData.getAttributes();
    assertEquals("available", attributes.get(NetworkMonitor.NETWORK_STATUS_KEY));
    assertEquals("cell", attributes.get(NET_HOST_CONNECTION_TYPE));
    assertEquals("LTE", attributes.get(NET_HOST_CONNECTION_SUBTYPE));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SpanData(io.opentelemetry.sdk.trace.data.SpanData) Attributes(io.opentelemetry.api.common.Attributes) Test(org.junit.Test)

Example 87 with Attributes

use of io.opentelemetry.api.common.Attributes in project splunk-otel-android by signalfx.

the class RumAttributeAppenderTest method appendAttributesOnStart.

@Test
public void appendAttributesOnStart() {
    Attributes globalAttributes = Attributes.of(stringKey("cheese"), "Camembert", longKey("size"), 5L);
    Config config = mock(Config.class);
    when(config.getApplicationName()).thenReturn("appName");
    when(config.getGlobalAttributes()).thenReturn(globalAttributes);
    SessionId sessionId = mock(SessionId.class);
    when(sessionId.getSessionId()).thenReturn("rumSessionId");
    when(visibleScreenTracker.getCurrentlyVisibleScreen()).thenReturn("ScreenOne");
    ReadWriteSpan span = mock(ReadWriteSpan.class);
    RumAttributeAppender rumAttributeAppender = new RumAttributeAppender(config, sessionId, "rumVersion", visibleScreenTracker, connectionUtil);
    rumAttributeAppender.onStart(Context.current(), span);
    verify(span).setAttribute(RumAttributeAppender.RUM_VERSION_KEY, "rumVersion");
    verify(span).setAttribute(RumAttributeAppender.APP_NAME_KEY, "appName");
    verify(span).setAttribute(RumAttributeAppender.SESSION_ID_KEY, "rumSessionId");
    verify(span).setAttribute(ResourceAttributes.OS_TYPE, "linux");
    verify(span).setAttribute(ResourceAttributes.OS_NAME, "Android");
    verify(span).setAttribute(SplunkRum.SCREEN_NAME_KEY, "ScreenOne");
    verify(span).setAttribute(SemanticAttributes.NET_HOST_CONNECTION_TYPE, "cell");
    verify(span).setAttribute(SemanticAttributes.NET_HOST_CONNECTION_SUBTYPE, "LTE");
    // these values don't seem to be available in unit tests, so just assert that something was set.
    verify(span).setAttribute(eq(ResourceAttributes.DEVICE_MODEL_IDENTIFIER), any());
    verify(span).setAttribute(eq(ResourceAttributes.DEVICE_MODEL_NAME), any());
    verify(span).setAttribute(eq(ResourceAttributes.OS_VERSION), any());
    verify(span).setAllAttributes(globalAttributes);
}
Also used : ReadWriteSpan(io.opentelemetry.sdk.trace.ReadWriteSpan) SemanticAttributes(io.opentelemetry.semconv.trace.attributes.SemanticAttributes) Attributes(io.opentelemetry.api.common.Attributes) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes) Test(org.junit.Test)

Example 88 with Attributes

use of io.opentelemetry.api.common.Attributes in project splunk-otel-android by signalfx.

the class RumAttributeAppenderTest method updateGlobalAttributes.

@Test
public void updateGlobalAttributes() {
    Attributes initialAttributes = Attributes.of(stringKey("cheese"), "Camembert", longKey("size"), 5L);
    Config config = Config.builder().globalAttributes(initialAttributes).realm("us0").rumAccessToken("123456").applicationName("appName").build();
    RumAttributeAppender rumAttributeAppender = new RumAttributeAppender(config, new SessionId(), "version", visibleScreenTracker, connectionUtil);
    ReadWriteSpan span = mock(ReadWriteSpan.class);
    rumAttributeAppender.onStart(Context.current(), span);
    verify(span).setAllAttributes(initialAttributes);
    config.updateGlobalAttributes(attributesBuilder -> attributesBuilder.put("cheese", "cheddar"));
    span = mock(ReadWriteSpan.class);
    rumAttributeAppender.onStart(Context.current(), span);
    Attributes updatedAttributes = Attributes.of(stringKey("cheese"), "cheddar", longKey("size"), 5L);
    verify(span).setAllAttributes(updatedAttributes);
}
Also used : ReadWriteSpan(io.opentelemetry.sdk.trace.ReadWriteSpan) SemanticAttributes(io.opentelemetry.semconv.trace.attributes.SemanticAttributes) Attributes(io.opentelemetry.api.common.Attributes) ResourceAttributes(io.opentelemetry.semconv.resource.attributes.ResourceAttributes) Test(org.junit.Test)

Example 89 with Attributes

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

the class SamplingOverridesTest method shouldFilterMultiConfigsBothMatch.

@Test
void shouldFilterMultiConfigsBothMatch() {
    // given
    List<SamplingOverride> overrides = Arrays.asList(newOverride(Configuration.SpanKind.SERVER, 0, newStrictAttribute("one", "1")), newOverride(Configuration.SpanKind.SERVER, 0, newRegexpAttribute("two", "2.*")));
    SamplingOverrides sampler = new SamplingOverrides(overrides);
    Attributes attributes = Attributes.of(AttributeKey.stringKey("one"), "1", AttributeKey.stringKey("two"), "22");
    // 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 90 with Attributes

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

the class SamplingOverridesTest method shouldFilterRegexpMatch.

@Test
void shouldFilterRegexpMatch() {
    // given
    List<SamplingOverride> overrides = singletonList(newOverride(Configuration.SpanKind.SERVER, 0, newRegexpAttribute("one", "1.*")));
    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)

Aggregations

Attributes (io.opentelemetry.api.common.Attributes)232 Test (org.junit.jupiter.api.Test)154 ResourceAttributes (io.opentelemetry.semconv.resource.attributes.ResourceAttributes)50 SemanticAttributes (io.opentelemetry.semconv.trace.attributes.SemanticAttributes)43 Resource (io.opentelemetry.sdk.resources.Resource)33 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