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));
}
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);
}
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);
}
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);
}
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);
}
Aggregations