Search in sources :

Example 66 with AttributeValue

use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.

the class ErrorsAndExceptionsEnricherTest method createMockTestEvent.

private Event createMockTestEvent() {
    Map<String, AttributeValue> map = new HashMap<>();
    Map<String, MetricValue> metricMap = new HashMap<>();
    map.put("span.kind", AttributeValue.newBuilder().setValue("server").build());
    map.put("error", AttributeValue.newBuilder().setValue("true").build());
    map.put("SPAN_TYPE", AttributeValue.newBuilder().setValue("ENTRY").build());
    metricMap.put("Duration", MetricValue.newBuilder().setValue(4.0).build());
    Event event = Event.newBuilder().setCustomerId("customer1").setEventId(ByteBuffer.wrap("bdf03dfabf5c70f9".getBytes())).setEntityIdList(Arrays.asList("4bfca8f7-4974-36a4-9385-dd76bf5c8824")).setEnrichedAttributes(Attributes.newBuilder().setAttributeMap(map).build()).setAttributes(Attributes.newBuilder().setAttributeMap(map).build()).setEventName("test-event").setStartTimeMillis(1566869077746L).setEndTimeMillis(1566869077750L).setMetrics(Metrics.newBuilder().setMetricMap(metricMap).build()).setEventRefList(Collections.emptyList()).build();
    return event;
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) MetricValue(org.hypertrace.core.datamodel.MetricValue) HashMap(java.util.HashMap) Event(org.hypertrace.core.datamodel.Event)

Example 67 with AttributeValue

use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.

the class SpanTypeAttributeEnricherTest method test_getProtocolName_grpcAttributes_shouldReturnGrpc.

@Test
public void test_getProtocolName_grpcAttributes_shouldReturnGrpc() {
    Map<String, AttributeValue> map = new HashMap<>();
    map.put(OTEL_SPAN_TAG_RPC_SYSTEM.getValue(), AttributeValue.newBuilder().setValue("grpc").build());
    Event e = createEvent(map, new HashMap<>());
    Assertions.assertEquals(Protocol.PROTOCOL_GRPC, SpanTypeAttributeEnricher.getProtocolName(e));
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) HashMap(java.util.HashMap) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 68 with AttributeValue

use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.

the class SpanTypeAttributeEnricherTest method test_getProtocolName_HttpFromUrl_shouldReturnHttp.

@Test
public void test_getProtocolName_HttpFromUrl_shouldReturnHttp() {
    Map<String, AttributeValue> map = new HashMap<>();
    map.put(Constants.getRawSpanConstant(Http.HTTP_REQUEST_URL), AttributeValue.newBuilder().setValue("http://hypertrace.org").build());
    Event e = createEvent(map, new HashMap<>());
    Assertions.assertEquals(Protocol.PROTOCOL_HTTP, SpanTypeAttributeEnricher.getProtocolName(e));
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) HashMap(java.util.HashMap) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 69 with AttributeValue

use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.

the class SpanTypeAttributeEnricherTest method spanKindExists.

@Test
public void spanKindExists() {
    SpanTypeAttributeEnricher enricher = new SpanTypeAttributeEnricher();
    Event e = createMockEvent();
    addAttribute(e, SPAN_KIND_KEY, SERVER_VALUE);
    enricher.enrichEvent(null, e);
    Map<String, AttributeValue> enrichedAttributes = e.getEnrichedAttributes().getAttributeMap();
    Assertions.assertEquals(enrichedAttributes.get(Constants.getEnrichedSpanConstant(SPAN_TYPE)).getValue(), Constants.getEnrichedSpanConstant(ENTRY));
    e = createMockEvent();
    addAttribute(e, OTelSpanSemanticConventions.SPAN_KIND.getValue(), OTelSpanSemanticConventions.SPAN_KIND_SERVER_VALUE.getValue());
    enricher.enrichEvent(null, e);
    enrichedAttributes = e.getEnrichedAttributes().getAttributeMap();
    Assertions.assertEquals(Constants.getEnrichedSpanConstant(ENTRY), enrichedAttributes.get(Constants.getEnrichedSpanConstant(SPAN_TYPE)).getValue());
    e = createMockEvent();
    addAttribute(e, OTelSpanSemanticConventions.SPAN_KIND.getValue(), OtelMessagingSemanticConventions.CONSUMER.getValue());
    enricher.enrichEvent(null, e);
    enrichedAttributes = e.getEnrichedAttributes().getAttributeMap();
    Assertions.assertEquals(Constants.getEnrichedSpanConstant(ENTRY), enrichedAttributes.get(Constants.getEnrichedSpanConstant(SPAN_TYPE)).getValue());
    e = createMockEvent();
    addAttribute(e, SPAN_KIND_KEY, OtelMessagingSemanticConventions.CONSUMER.getValue());
    enricher.enrichEvent(null, e);
    enrichedAttributes = e.getEnrichedAttributes().getAttributeMap();
    Assertions.assertEquals(Constants.getEnrichedSpanConstant(ENTRY), enrichedAttributes.get(Constants.getEnrichedSpanConstant(SPAN_TYPE)).getValue());
    e = createMockEvent();
    addAttribute(e, SPAN_KIND_KEY, CLIENT_VALUE);
    enricher.enrichEvent(null, e);
    enrichedAttributes = e.getEnrichedAttributes().getAttributeMap();
    Assertions.assertEquals(enrichedAttributes.get(Constants.getEnrichedSpanConstant(SPAN_TYPE)).getValue(), Constants.getEnrichedSpanConstant(EXIT));
    e = createMockEvent();
    addAttribute(e, OTelSpanSemanticConventions.SPAN_KIND.getValue(), OTelSpanSemanticConventions.SPAN_KIND_CLIENT_VALUE.getValue());
    enricher.enrichEvent(null, e);
    enrichedAttributes = e.getEnrichedAttributes().getAttributeMap();
    Assertions.assertEquals(enrichedAttributes.get(Constants.getEnrichedSpanConstant(SPAN_TYPE)).getValue(), Constants.getEnrichedSpanConstant(EXIT));
    e = createMockEvent();
    addAttribute(e, OTelSpanSemanticConventions.SPAN_KIND.getValue(), OtelMessagingSemanticConventions.PRODUCER.getValue());
    enricher.enrichEvent(null, e);
    enrichedAttributes = e.getEnrichedAttributes().getAttributeMap();
    Assertions.assertEquals(enrichedAttributes.get(Constants.getEnrichedSpanConstant(SPAN_TYPE)).getValue(), Constants.getEnrichedSpanConstant(EXIT));
    e = createMockEvent();
    addAttribute(e, SPAN_KIND_KEY, OtelMessagingSemanticConventions.PRODUCER.getValue());
    enricher.enrichEvent(null, e);
    enrichedAttributes = e.getEnrichedAttributes().getAttributeMap();
    Assertions.assertEquals(enrichedAttributes.get(Constants.getEnrichedSpanConstant(SPAN_TYPE)).getValue(), Constants.getEnrichedSpanConstant(EXIT));
    e = createMockEvent();
    addAttribute(e, SPAN_KIND_KEY, "unknown");
    enricher.enrichEvent(null, e);
    enrichedAttributes = e.getEnrichedAttributes().getAttributeMap();
    Assertions.assertEquals(enrichedAttributes.get(Constants.getEnrichedSpanConstant(SPAN_TYPE)).getValue(), Constants.getEnrichedSpanConstant(UNKNOWN));
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 70 with AttributeValue

use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.

the class MongoBackendProviderTest method checkBackendEntityGeneratedFromInstrumentedMongoEventOtelFormat.

@Test
public void checkBackendEntityGeneratedFromInstrumentedMongoEventOtelFormat() {
    Event e = Event.newBuilder().setCustomerId("__default").setEventId(ByteBuffer.wrap("bdf03dfabf5c70f8".getBytes())).setEntityIdList(Arrays.asList("4bfca8f7-4974-36a4-9385-dd76bf5c8824")).setEnrichedAttributes(Attributes.newBuilder().setAttributeMap(Map.of("SPAN_TYPE", AttributeValue.newBuilder().setValue("EXIT").build())).build()).setAttributes(Attributes.newBuilder().setAttributeMap(Map.of(OTelDbSemanticConventions.DB_SYSTEM.getValue(), buildAttributeValue(OTelDbSemanticConventions.MONGODB_DB_SYSTEM_VALUE.getValue()), OTelSpanSemanticConventions.NET_PEER_NAME.getValue(), buildAttributeValue("mongodb0"), OTelDbSemanticConventions.MONGODB_COLLECTION.getValue(), buildAttributeValue("sampleshop.userReview"), "span.kind", buildAttributeValue("client"), OTelDbSemanticConventions.DB_OPERATION.getValue(), buildAttributeValue("FindOperation"), OTelDbSemanticConventions.DB_NAME.getValue(), buildAttributeValue("customers"), OTelSpanSemanticConventions.NET_PEER_PORT.getValue(), buildAttributeValue("27017"))).build()).setEventName("mongo.async.exit").setStartTimeMillis(1566869077746L).setEndTimeMillis(1566869077750L).setMetrics(Metrics.newBuilder().setMetricMap(Map.of("Duration", MetricValue.newBuilder().setValue(4.0).build())).build()).setEventRefList(Arrays.asList(EventRef.newBuilder().setTraceId(ByteBuffer.wrap("random_trace_id".getBytes())).setEventId(ByteBuffer.wrap("random_event_id".getBytes())).setRefType(EventRefType.CHILD_OF).build())).build();
    final BackendInfo backendInfo = backendEntityEnricher.resolve(e, structuredTrace, structuredTraceGraph).get();
    final Entity backendEntity = backendInfo.getEntity();
    assertEquals("mongodb0:27017", backendEntity.getEntityName());
    assertEquals(3, backendEntity.getIdentifyingAttributesCount());
    assertEquals(backendEntity.getIdentifyingAttributesMap().get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_PROTOCOL)).getValue().getString(), "MONGO");
    assertEquals("mongodb0", backendEntity.getIdentifyingAttributesMap().get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_HOST)).getValue().getString());
    assertEquals(backendEntity.getIdentifyingAttributesMap().get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_PORT)).getValue().getString(), "27017");
    assertEquals(backendEntity.getAttributesMap().get(OTelDbSemanticConventions.MONGODB_COLLECTION.getValue()).getValue().getString(), "sampleshop.userReview");
    assertEquals(backendEntity.getAttributesMap().get(OTelDbSemanticConventions.DB_OPERATION.getValue()).getValue().getString(), "FindOperation");
    assertEquals(backendEntity.getAttributesMap().get(Constants.getEnrichedSpanConstant(Backend.BACKEND_FROM_EVENT)).getValue().getString(), "mongo.async.exit");
    assertEquals(backendEntity.getAttributesMap().get(Constants.getEnrichedSpanConstant(Backend.BACKEND_FROM_EVENT_ID)).getValue().getString(), "62646630336466616266356337306638");
    Map<String, AttributeValue> attributes = backendInfo.getAttributes();
    assertEquals(Map.of("BACKEND_DESTINATION", AttributeValueCreator.create("customers.sampleshop.userReview"), "BACKEND_OPERATION", AttributeValueCreator.create("FindOperation")), attributes);
}
Also used : Entity(org.hypertrace.entity.data.service.v1.Entity) TestUtil.buildAttributeValue(org.hypertrace.traceenricher.TestUtil.buildAttributeValue) AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Event(org.hypertrace.core.datamodel.Event) BackendInfo(org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo) Test(org.junit.jupiter.api.Test)

Aggregations

AttributeValue (org.hypertrace.core.datamodel.AttributeValue)84 Test (org.junit.jupiter.api.Test)65 Event (org.hypertrace.core.datamodel.Event)53 BackendInfo (org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo)24 Entity (org.hypertrace.entity.data.service.v1.Entity)22 HashMap (java.util.HashMap)19 TestUtil.buildAttributeValue (org.hypertrace.traceenricher.TestUtil.buildAttributeValue)11 AvroBuilderCache.fastNewBuilder (org.hypertrace.core.datamodel.shared.AvroBuilderCache.fastNewBuilder)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 EventRef (org.hypertrace.core.datamodel.EventRef)3 StructuredTrace (org.hypertrace.core.datamodel.StructuredTrace)3 Attributes (org.hypertrace.core.datamodel.Attributes)2 MetricValue (org.hypertrace.core.datamodel.MetricValue)2 RawSpan (org.hypertrace.core.datamodel.RawSpan)2 SpanEventView (org.hypertrace.viewgenerator.api.SpanEventView)2 ImmutableList (com.google.common.collect.ImmutableList)1 ByteString (com.google.protobuf.ByteString)1 ProtocolStringList (com.google.protobuf.ProtocolStringList)1