Search in sources :

Example 46 with Event

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());
}
Also used : AttributeMetadata(org.hypertrace.core.attribute.service.v1.AttributeMetadata) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 47 with Event

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));
}
Also used : Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 48 with 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));
}
Also used : Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 49 with 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());
}
Also used : Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 50 with Event

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));
}
Also used : Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Aggregations

Event (org.hypertrace.core.datamodel.Event)304 Test (org.junit.jupiter.api.Test)257 AttributeValue (org.hypertrace.core.datamodel.AttributeValue)54 StructuredTrace (org.hypertrace.core.datamodel.StructuredTrace)54 Attributes (org.hypertrace.core.datamodel.Attributes)41 Entity (org.hypertrace.entity.data.service.v1.Entity)27 HashMap (java.util.HashMap)25 AbstractAttributeEnricherTest (org.hypertrace.traceenricher.enrichment.enrichers.AbstractAttributeEnricherTest)17 ByteBuffer (java.nio.ByteBuffer)13 BackendInfo (org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo)13 StructuredTraceGraph (org.hypertrace.core.datamodel.shared.StructuredTraceGraph)12 TestUtil.buildAttributeValue (org.hypertrace.traceenricher.TestUtil.buildAttributeValue)11 AttributeMetadata (org.hypertrace.core.attribute.service.v1.AttributeMetadata)10 SemanticConventionTestUtil.buildAttributes (org.hypertrace.semantic.convention.utils.SemanticConventionTestUtil.buildAttributes)8 Edge (org.hypertrace.core.datamodel.Edge)7 Entity (org.hypertrace.core.datamodel.Entity)7 HashSet (java.util.HashSet)6 List (java.util.List)6 Map (java.util.Map)6 ArrayList (java.util.ArrayList)5