use of org.hypertrace.core.datamodel.Event in project hypertrace-ingester by hypertrace.
the class DefaultValueResolverTest method resolvesNestedFirstAttribute.
@Test
void resolvesNestedFirstAttribute() {
AttributeMetadata metadata = AttributeMetadata.newBuilder().setScopeString("TEST_SCOPE").setType(AttributeType.ATTRIBUTE).setValueKind(AttributeKind.TYPE_INT64).setDefinition(AttributeDefinition.newBuilder().setFirstValuePresent(AttributeDefinitions.newBuilder().addDefinitions(AttributeDefinition.newBuilder().setSourcePath("non.existent")).addDefinitions(AttributeDefinition.newBuilder().setFirstValuePresent(AttributeDefinitions.newBuilder().addDefinitions(AttributeDefinition.newBuilder().setSourcePath("non.existent.other")).addDefinitions(AttributeDefinition.newBuilder().setSourceField(SourceField.SOURCE_FIELD_START_TIME)))))).build();
Event span = defaultedEventBuilder().setStartTimeMillis(13).build();
assertEquals(longLiteral(13), this.resolver.resolve(ValueSourceFactory.forSpan(this.mockStructuredTrace, span), metadata).blockingGet());
}
use of org.hypertrace.core.datamodel.Event in project hypertrace-ingester by hypertrace.
the class HttpSemanticConventionUtilsTest method testGetHttpRequestSize.
@Test
public void testGetHttpRequestSize() {
Event event = createMockEventWithAttribute(RawSpanConstants.getValue(HTTP_REQUEST_SIZE), "100");
assertEquals(Optional.of(100), HttpSemanticConventionUtils.getHttpRequestSize(event));
event = mock(Event.class);
when(event.getAttributes()).thenReturn(Attributes.newBuilder().setAttributeMap(Map.of(RawSpanConstants.getValue(ENVOY_REQUEST_SIZE), AttributeValue.newBuilder().setValue("100").build(), OTelHttpSemanticConventions.HTTP_REQUEST_SIZE.getValue(), AttributeValue.newBuilder().setValue("150").build(), RawSpanConstants.getValue(HTTP_REQUEST_SIZE), AttributeValue.newBuilder().setValue("200").build(), RawSpanConstants.getValue(HTTP_REQUEST_CONTENT_LENGTH), AttributeValue.newBuilder().setValue("300").build(), RawSpanConstants.getValue(HTTP_HTTP_REQUEST_BODY), AttributeValue.newBuilder().setValue("Hello, there!").build())).build());
assertEquals(Optional.of(100), HttpSemanticConventionUtils.getHttpRequestSize(event));
event = createMockEventWithAttribute(RawSpanConstants.getValue(HTTP_REQUEST_CONTENT_LENGTH), "300");
assertEquals(Optional.of(300), HttpSemanticConventionUtils.getHttpRequestSize(event));
event = createMockEventWithAttribute(RawSpanConstants.getValue(HTTP_HTTP_REQUEST_BODY), "Hello, there!");
assertEquals(Optional.of(13), HttpSemanticConventionUtils.getHttpRequestSize(event));
event = mock(Event.class);
when(event.getAttributes()).thenReturn(Attributes.newBuilder().setAttributeMap(Map.of(RawSpanConstants.getValue(HTTP_HTTP_REQUEST_BODY), AttributeValue.newBuilder().setValue("Hello, there!").build(), RawSpanConstants.getValue(HTTP_REQUEST_BODY_TRUNCATED), AttributeValue.newBuilder().setValue("true").build())).build());
assertEquals(Optional.empty(), HttpSemanticConventionUtils.getHttpRequestSize(event));
}
use of org.hypertrace.core.datamodel.Event in project hypertrace-ingester by hypertrace.
the class HttpSemanticConventionUtilsTest method testGetHttpUserAgent.
@Test
public void testGetHttpUserAgent() {
Event event = createMockEventWithAttribute(RawSpanConstants.getValue(HTTP_USER_DOT_AGENT), "Chrome 1");
assertEquals(Optional.of("Chrome 1"), HttpSemanticConventionUtils.getHttpUserAgent(event));
event = mock(Event.class);
assertTrue(HttpSemanticConventionUtils.getHttpUserAgent(event).isEmpty());
event = createMockEventWithAttribute(RawSpanConstants.getValue(HTTP_USER_DOT_AGENT), "");
assertTrue(HttpSemanticConventionUtils.getHttpUserAgent(event).isEmpty());
event = mock(Event.class);
when(event.getAttributes()).thenReturn(Attributes.newBuilder().setAttributeMap(Map.of(RawSpanConstants.getValue(HTTP_USER_DOT_AGENT), AttributeValue.newBuilder().setValue("Chrome 1").build(), RawSpanConstants.getValue(HTTP_USER_AGENT_WITH_UNDERSCORE), AttributeValue.newBuilder().setValue("Chrome 2").build(), RawSpanConstants.getValue(CENSUS_RESPONSE_CENSUS_STATUS_CODE), AttributeValue.newBuilder().setValue("Chrome 3").build(), RawSpanConstants.getValue(HTTP_USER_AGENT_WITH_DASH), AttributeValue.newBuilder().setValue("Chrome 4").build())).build());
assertEquals(Optional.of("Chrome 1"), HttpSemanticConventionUtils.getHttpUserAgent(event));
}
use of org.hypertrace.core.datamodel.Event in project hypertrace-ingester by hypertrace.
the class HttpSemanticConventionUtilsTest method testGetHttpHost.
@Test
public void testGetHttpHost() {
Event event = createMockEventWithAttribute(RawSpanConstants.getValue(Http.HTTP_HOST), "abc.ai");
assertEquals(Optional.of("abc.ai"), HttpSemanticConventionUtils.getHttpHost(event));
event = mock(Event.class);
assertTrue(HttpSemanticConventionUtils.getHttpHost(event).isEmpty());
}
use of org.hypertrace.core.datamodel.Event in project hypertrace-ingester by hypertrace.
the class HttpSemanticConventionUtilsTest method testGetHttpUrl.
@Test
public void testGetHttpUrl() {
Event event = createMockEventWithAttribute(RawSpanConstants.getValue(Http.HTTP_URL), "https://example.ai/apis/5673/events?a1=v1&a2=v2");
assertEquals(Optional.of("https://example.ai/apis/5673/events?a1=v1&a2=v2"), HttpSemanticConventionUtils.getHttpUrl(event));
event = mock(Event.class);
assertTrue(HttpSemanticConventionUtils.getHttpUrl(event).isEmpty());
event = createMockEventWithAttribute(RawSpanConstants.getValue(Http.HTTP_URL), "");
assertTrue(HttpSemanticConventionUtils.getHttpPath(event).isEmpty());
event = mock(Event.class);
when(event.getAttributes()).thenReturn(Attributes.newBuilder().setAttributeMap(Map.of(RawSpanConstants.getValue(OT_SPAN_TAG_HTTP_URL), AttributeValue.newBuilder().setValue("https://example.ai/apis/5673/events?a1=v1&a2=v2").build(), RawSpanConstants.getValue(HTTP_REQUEST_URL), AttributeValue.newBuilder().setValue("https://example2.ai/apis/5673/events?a1=v1&a2=v2").build(), RawSpanConstants.getValue(Http.HTTP_URL), AttributeValue.newBuilder().setValue("https://example4.ai/apis/5673/events?a1=v1&a2=v2").build())).build());
assertEquals(Optional.of("https://example.ai/apis/5673/events?a1=v1&a2=v2"), HttpSemanticConventionUtils.getHttpUrl(event));
}
Aggregations