use of org.hypertrace.core.datamodel.Attributes in project hypertrace-ingester by hypertrace.
the class DbSemanticConventionUtilsTest method testGetDbTypeForOtelFormat.
@Test
public void testGetDbTypeForOtelFormat() {
Event e = mock(Event.class);
Attributes attributes = SemanticConventionTestUtil.buildAttributes(Map.of(OTelDbSemanticConventions.DB_SYSTEM.getValue(), SemanticConventionTestUtil.buildAttributeValue(OTelDbSemanticConventions.MONGODB_DB_SYSTEM_VALUE.getValue())));
when(e.getAttributes()).thenReturn(attributes);
Optional<String> v = DbSemanticConventionUtils.getDbTypeForOtelFormat(e);
assertEquals(OTelDbSemanticConventions.MONGODB_DB_SYSTEM_VALUE.getValue(), v.get());
attributes = SemanticConventionTestUtil.buildAttributes(Map.of(OTelDbSemanticConventions.DB_SYSTEM.getValue(), SemanticConventionTestUtil.buildAttributeValue(OTelDbSemanticConventions.MONGODB_DB_SYSTEM_VALUE.getValue())));
when(e.getAttributes()).thenReturn(null);
when(e.getEnrichedAttributes()).thenReturn(attributes);
v = DbSemanticConventionUtils.getDbTypeForOtelFormat(e);
assertEquals(OTelDbSemanticConventions.MONGODB_DB_SYSTEM_VALUE.getValue(), v.get());
when(e.getAttributes()).thenReturn(null);
when(e.getEnrichedAttributes()).thenReturn(null);
v = DbSemanticConventionUtils.getDbTypeForOtelFormat(e);
assertTrue(v.isEmpty());
}
use of org.hypertrace.core.datamodel.Attributes in project hypertrace-ingester by hypertrace.
the class DbSemanticConventionUtilsTest method testGetSqlDestination.
@Test
public void testGetSqlDestination() {
Event e = mock(Event.class);
Attributes attributes = SemanticConventionTestUtil.buildAttributes(Map.of(OTelDbSemanticConventions.SQL_TABLE_NAME.getValue(), SemanticConventionTestUtil.buildAttributeValue("payment"), OTelDbSemanticConventions.DB_NAME.getValue(), SemanticConventionTestUtil.buildAttributeValue("customer")));
when(e.getAttributes()).thenReturn(attributes);
Optional<String> v = DbSemanticConventionUtils.getDestinationForJdbc(e);
assertEquals("customer.payment", v.get());
}
use of org.hypertrace.core.datamodel.Attributes in project hypertrace-ingester by hypertrace.
the class DbSemanticConventionUtilsTest method isMongoBackend.
@Test
public void isMongoBackend() {
Event e = mock(Event.class);
// otel format, dbsystem is not mongo
Attributes attributes = SemanticConventionTestUtil.buildAttributes(Map.of(OTelDbSemanticConventions.DB_SYSTEM.getValue(), SemanticConventionTestUtil.buildAttributeValue(OTelDbSemanticConventions.MYSQL_DB_SYSTEM_VALUE.getValue()), OTelDbSemanticConventions.DB_CONNECTION_STRING.getValue(), SemanticConventionTestUtil.buildAttributeValue("mongo:27017")));
when(e.getAttributes()).thenReturn(attributes);
boolean v = DbSemanticConventionUtils.isMongoBackend(e);
assertFalse(v);
attributes = SemanticConventionTestUtil.buildAttributes(Map.of(RawSpanConstants.getValue(Mongo.MONGO_ADDRESS), SemanticConventionTestUtil.buildAttributeValue("mongo:27017")));
when(e.getAttributes()).thenReturn(attributes);
v = DbSemanticConventionUtils.isMongoBackend(e);
assertTrue(v);
attributes = SemanticConventionTestUtil.buildAttributes(Map.of(RawSpanConstants.getValue(Mongo.MONGO_URL), SemanticConventionTestUtil.buildAttributeValue("mongo:27017")));
when(e.getAttributes()).thenReturn(attributes);
v = DbSemanticConventionUtils.isMongoBackend(e);
assertTrue(v);
attributes = SemanticConventionTestUtil.buildAttributes(Map.of("span.kind", SemanticConventionTestUtil.buildAttributeValue("client")));
when(e.getAttributes()).thenReturn(attributes);
v = DbSemanticConventionUtils.isMongoBackend(e);
assertFalse(v);
}
use of org.hypertrace.core.datamodel.Attributes in project hypertrace-ingester by hypertrace.
the class DbSemanticConventionUtilsTest method testGetBackendURIForOtelFormat.
@Test
public void testGetBackendURIForOtelFormat() {
Event e = mock(Event.class);
// only ip is present
Attributes attributes = SemanticConventionTestUtil.buildAttributes(Map.of(OTelSpanSemanticConventions.NET_PEER_IP.getValue(), SemanticConventionTestUtil.buildAttributeValue("127.0.0.1")));
when(e.getAttributes()).thenReturn(attributes);
Optional<String> v = DbSemanticConventionUtils.getBackendURIForOtelFormat(e);
assertEquals("127.0.0.1", v.get());
// ip & host present
attributes = SemanticConventionTestUtil.buildAttributes(Map.of(OTelSpanSemanticConventions.NET_PEER_IP.getValue(), SemanticConventionTestUtil.buildAttributeValue("127.0.0.1"), OTelSpanSemanticConventions.NET_PEER_NAME.getValue(), SemanticConventionTestUtil.buildAttributeValue("mysql.example.com")));
when(e.getAttributes()).thenReturn(attributes);
v = DbSemanticConventionUtils.getBackendURIForOtelFormat(e);
assertEquals("mysql.example.com", v.get());
// host & port present
attributes = SemanticConventionTestUtil.buildAttributes(Map.of(OTelSpanSemanticConventions.NET_PEER_IP.getValue(), SemanticConventionTestUtil.buildAttributeValue("127.0.0.1"), OTelSpanSemanticConventions.NET_PEER_NAME.getValue(), SemanticConventionTestUtil.buildAttributeValue("mysql.example.com"), OTelSpanSemanticConventions.NET_PEER_PORT.getValue(), SemanticConventionTestUtil.buildAttributeValue("3306")));
when(e.getAttributes()).thenReturn(attributes);
v = DbSemanticConventionUtils.getBackendURIForOtelFormat(e);
assertEquals("mysql.example.com:3306", v.get());
}
use of org.hypertrace.core.datamodel.Attributes in project hypertrace-ingester by hypertrace.
the class DbSemanticConventionUtilsTest method testGetRedisOperation.
@Test
public void testGetRedisOperation() {
Event e = mock(Event.class);
Attributes attributes = SemanticConventionTestUtil.buildAttributes(Map.of(RawSpanConstants.getValue(Redis.REDIS_COMMAND), SemanticConventionTestUtil.buildAttributeValue("GET")));
when(e.getAttributes()).thenReturn(attributes);
Optional<String> v = DbSemanticConventionUtils.getDbOperationForRedis(e);
assertEquals("GET", v.get());
}
Aggregations