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