use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.
the class JdbcBackendProviderTest method testWebgoatUrl.
@Test
public void testWebgoatUrl() {
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("sql.url", AttributeValue.newBuilder().setValue("jdbc:hsqldb:hsql://dbhost:9001/webgoat").build(), "span.kind", AttributeValue.newBuilder().setValue("client").build(), "sql.query", AttributeValue.newBuilder().setValue("insert into audit_message (message, id) values (?, ?)").build(), "db.operation", AttributeValue.newBuilder().setValue("select").build(), "k8s.pod_id", AttributeValue.newBuilder().setValue("55636196-c840-11e9-a417-42010a8a0064").build(), "docker.container_id", AttributeValue.newBuilder().setValue("ee85cf2cfc3b24613a3da411fdbd2f3eabbe729a5c86c5262971c8d8c29dad0f").build(), "FLAGS", AttributeValue.newBuilder().setValue("0").build())).build()).setEventName("jdbc.connection.prepare").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();
BackendInfo backendInfo = backendEntityEnricher.resolve(e, structuredTrace, structuredTraceGraph).get();
final Entity backendEntity = backendInfo.getEntity();
assertEquals("dbhost:9001", backendEntity.getEntityName());
assertEquals(3, backendEntity.getIdentifyingAttributesCount());
Assertions.assertEquals(BackendType.JDBC.name(), backendEntity.getIdentifyingAttributesMap().get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_PROTOCOL)).getValue().getString());
assertEquals("dbhost", backendEntity.getIdentifyingAttributesMap().get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_HOST)).getValue().getString());
assertEquals("9001", backendEntity.getIdentifyingAttributesMap().get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_PORT)).getValue().getString());
assertEquals("hsqldb", backendEntity.getAttributesMap().get(Constants.getRawSpanConstant(Sql.SQL_DB_TYPE)).getValue().getString());
assertEquals("jdbc.connection.prepare", backendEntity.getAttributesMap().get(Constants.getEnrichedSpanConstant(Backend.BACKEND_FROM_EVENT)).getValue().getString());
assertEquals("62646630336466616266356337306638", backendEntity.getAttributesMap().get(Constants.getEnrichedSpanConstant(Backend.BACKEND_FROM_EVENT_ID)).getValue().getString());
assertEquals("/webgoat", backendEntity.getAttributesMap().get(EntityConstants.getValue(BackendAttribute.BACKEND_ATTRIBUTE_PATH)).getValue().getString());
Map<String, AttributeValue> attributes = backendInfo.getAttributes();
assertEquals(Map.of("BACKEND_OPERATION", AttributeValueCreator.create("select")), attributes);
}
use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.
the class JdbcBackendProviderTest method testBackendDestinationWithoutTableName.
@Test
public void testBackendDestinationWithoutTableName() {
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("sql.url", AttributeValue.newBuilder().setValue("jdbc:hsqldb:hsql://dbhost:9001/webgoat").build(), "span.kind", AttributeValue.newBuilder().setValue("client").build(), "db.name", AttributeValue.newBuilder().setValue("customer").build())).build()).setEventName("jdbc.connection.prepare").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();
BackendInfo backendInfo = backendEntityEnricher.resolve(e, structuredTrace, structuredTraceGraph).get();
Map<String, AttributeValue> attributes = backendInfo.getAttributes();
assertEquals(Map.of("BACKEND_DESTINATION", AttributeValueCreator.create("customer")), attributes);
}
use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.
the class KafkaBackendProviderTest method TestOtelBackendDestinationResolution.
@Test
public void TestOtelBackendDestinationResolution() {
String broker = "kafka-test.hypertrace.com:9092";
BackendInfo backendInfo = backendEntityEnricher.resolve(getOtelKafkaBackendEventForDestination(broker), structuredTrace, structuredTraceGraph).get();
Entity entity = backendInfo.getEntity();
Assertions.assertEquals(broker, entity.getEntityName());
Map<String, AttributeValue> attributes = backendInfo.getAttributes();
assertEquals(Map.of("BACKEND_DESTINATION", AttributeValueCreator.create("myGroup.QueueName")), attributes);
}
use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.
the class ErrorsAndExceptionsEnricherTest method errorExists.
@Test
public void errorExists() {
ErrorsAndExceptionsEnricher enricher = new ErrorsAndExceptionsEnricher();
Event e1 = createMockTestEvent();
Map<String, AttributeValue> attributeValueMap = e1.getAttributes().getAttributeMap();
attributeValueMap.put(Constants.getRawSpanConstant(Error.ERROR_ERROR), AttributeValueCreator.create(true));
enricher.enrichEvent(null, e1);
Assertions.assertEquals(1.0d, e1.getMetrics().getMetricMap().get(Constants.getEnrichedSpanConstant(ErrorMetrics.ERROR_METRICS_ERROR_COUNT)).getValue());
Event e2 = createMockTestEvent();
attributeValueMap = e2.getAttributes().getAttributeMap();
attributeValueMap.put(Constants.getRawSpanConstant(Error.ERROR_STACK_TRACE), AttributeValueCreator.create("test stack"));
enricher.enrichEvent(null, e2);
Assertions.assertEquals(1.0d, e2.getMetrics().getMetricMap().get(Constants.getEnrichedSpanConstant(ErrorMetrics.ERROR_METRICS_EXCEPTION_COUNT)).getValue());
Event e3 = createMockTestEvent();
attributeValueMap = e3.getAttributes().getAttributeMap();
attributeValueMap.put(Constants.getRawSpanConstant(Error.ERROR_ERROR).toLowerCase(), AttributeValueCreator.create(true));
enricher.enrichEvent(null, e3);
Assertions.assertEquals(1.0d, e3.getMetrics().getMetricMap().get(Constants.getEnrichedSpanConstant(ErrorMetrics.ERROR_METRICS_ERROR_COUNT)).getValue());
Event e4 = createMockTestEvent();
attributeValueMap = e4.getAttributes().getAttributeMap();
attributeValueMap.put(Constants.getRawSpanConstant(Error.ERROR_ERROR).toLowerCase(), AttributeValueCreator.create(true));
enricher.enrichEvent(null, e4);
Assertions.assertEquals(1.0d, e4.getMetrics().getMetricMap().get(Constants.getEnrichedSpanConstant(ErrorMetrics.ERROR_METRICS_ERROR_COUNT)).getValue());
Event e5 = createMockTestEvent();
attributeValueMap = e5.getAttributes().getAttributeMap();
attributeValueMap.put(OTelErrorSemanticConventions.EXCEPTION_TYPE.getValue().toLowerCase(), AttributeValueCreator.create(true));
enricher.enrichEvent(null, e5);
Assertions.assertEquals(1.0d, e5.getMetrics().getMetricMap().get(Constants.getEnrichedSpanConstant(ErrorMetrics.ERROR_METRICS_ERROR_COUNT)).getValue());
Event e6 = createMockTestEvent();
attributeValueMap = e6.getAttributes().getAttributeMap();
attributeValueMap.put(OTelErrorSemanticConventions.EXCEPTION_STACKTRACE.getValue().toLowerCase(), AttributeValueCreator.create(true));
enricher.enrichEvent(null, e6);
Assertions.assertEquals(1.0d, e6.getMetrics().getMetricMap().get(Constants.getEnrichedSpanConstant(ErrorMetrics.ERROR_METRICS_EXCEPTION_COUNT)).getValue());
StructuredTrace trace = createStructuredTrace("test-id", e1, e2, e3, e4, e5, e6);
enricher.enrichEvent(trace, e1);
enricher.enrichEvent(trace, e2);
enricher.enrichEvent(trace, e3);
enricher.enrichEvent(trace, e4);
enricher.enrichEvent(trace, e5);
enricher.enrichEvent(trace, e6);
trace.setMetrics(Metrics.newBuilder().setMetricMap(new HashMap<>()).build());
Assertions.assertEquals(1.0d, e4.getMetrics().getMetricMap().get(Constants.getEnrichedSpanConstant(ErrorMetrics.ERROR_METRICS_ERROR_COUNT)).getValue());
enricher.enrichTrace(trace);
Assertions.assertEquals(6.0d, trace.getMetrics().getMetricMap().get(Constants.getEnrichedSpanConstant(ErrorMetrics.ERROR_METRICS_TOTAL_SPANS_WITH_ERRORS)).getValue());
Assertions.assertEquals(3.0d, trace.getMetrics().getMetricMap().get(Constants.getEnrichedSpanConstant(ErrorMetrics.ERROR_METRICS_TOTAL_SPANS_WITH_EXCEPTIONS)).getValue());
// Trace itself doesn't have an error since there was no entry span.
Assertions.assertTrue(trace.getAttributes().getAttributeMap().containsKey(Constants.getEnrichedSpanConstant(CommonAttribute.COMMON_ATTRIBUTE_TRANSACTION_HAS_ERROR)));
// Make e1 as ENTRY span so that the error is reflected on the structured trace.
e1.getEnrichedAttributes().getAttributeMap().put(Constants.getEnrichedSpanConstant(CommonAttribute.COMMON_ATTRIBUTE_SPAN_TYPE), AttributeValueCreator.create(Constants.getEnrichedSpanConstant(BoundaryTypeValue.BOUNDARY_TYPE_VALUE_ENTRY)));
enricher.enrichTrace(trace);
Assertions.assertEquals(6.0d, trace.getMetrics().getMetricMap().get(Constants.getEnrichedSpanConstant(ErrorMetrics.ERROR_METRICS_TOTAL_SPANS_WITH_ERRORS)).getValue());
Assertions.assertEquals(3.0d, trace.getMetrics().getMetricMap().get(Constants.getEnrichedSpanConstant(ErrorMetrics.ERROR_METRICS_TOTAL_SPANS_WITH_EXCEPTIONS)).getValue());
Assertions.assertEquals("true", trace.getAttributes().getAttributeMap().get(Constants.getEnrichedSpanConstant(CommonAttribute.COMMON_ATTRIBUTE_TRANSACTION_HAS_ERROR)).getValue());
}
use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.
the class HttpAttributeEnricherTest method testSemicolonInQueryParam.
@Test
public void testSemicolonInQueryParam() {
String query_string = "action=checkout;age=2";
Event e = createMockEvent();
addAttribute(e, RawSpanConstants.getValue(HTTP_PATH), "/users");
addAttribute(e, RawSpanConstants.getValue(HTTP_REQUEST_QUERY_STRING), query_string);
enricher.enrichEvent(mockTrace, e);
AttributeValue actionParam = SpanAttributeUtils.getAttributeValue(e, Constants.getEnrichedSpanConstant(HTTP_REQUEST_QUERY_PARAM) + ".action");
assertEquals("checkout;age=2", actionParam.getValue());
assertEquals(List.of("checkout;age=2"), actionParam.getValueList());
}
Aggregations