use of org.hypertrace.core.datamodel.Attributes in project hypertrace-ingester by hypertrace.
the class SpanSemanticConventionUtilsTest method testGetURIForOtelFormat.
@Test
public void testGetURIForOtelFormat() {
Event e = mock(Event.class);
// host present
Attributes attributes = SemanticConventionTestUtil.buildAttributes(Map.of(OTelSpanSemanticConventions.NET_PEER_NAME.getValue(), SemanticConventionTestUtil.buildAttributeValue("example.com")));
when(e.getAttributes()).thenReturn(attributes);
Optional<String> v = SpanSemanticConventionUtils.getURIForOtelFormat(e);
assertEquals("example.com", v.get());
// ip present
attributes = SemanticConventionTestUtil.buildAttributes(Map.of(OTelSpanSemanticConventions.NET_PEER_IP.getValue(), SemanticConventionTestUtil.buildAttributeValue("172.0.1.17")));
when(e.getAttributes()).thenReturn(attributes);
v = SpanSemanticConventionUtils.getURIForOtelFormat(e);
assertEquals("172.0.1.17", v.get());
// host & port
attributes = SemanticConventionTestUtil.buildAttributes(Map.of(OTelSpanSemanticConventions.NET_PEER_IP.getValue(), SemanticConventionTestUtil.buildAttributeValue("172.0.1.17"), OTelSpanSemanticConventions.NET_PEER_PORT.getValue(), SemanticConventionTestUtil.buildAttributeValue("2705")));
when(e.getAttributes()).thenReturn(attributes);
v = SpanSemanticConventionUtils.getURIForOtelFormat(e);
assertEquals("172.0.1.17:2705", v.get());
// ip & host both present
attributes = SemanticConventionTestUtil.buildAttributes(Map.of(OTelSpanSemanticConventions.NET_PEER_IP.getValue(), SemanticConventionTestUtil.buildAttributeValue("172.0.1.17"), OTelSpanSemanticConventions.NET_PEER_NAME.getValue(), SemanticConventionTestUtil.buildAttributeValue("example.com"), OTelSpanSemanticConventions.NET_PEER_PORT.getValue(), SemanticConventionTestUtil.buildAttributeValue("2705")));
when(e.getAttributes()).thenReturn(attributes);
v = SpanSemanticConventionUtils.getURIForOtelFormat(e);
assertEquals("example.com:2705", v.get());
// empty host
attributes = SemanticConventionTestUtil.buildAttributes(Map.of(OTelSpanSemanticConventions.NET_PEER_IP.getValue(), SemanticConventionTestUtil.buildAttributeValue(""), OTelSpanSemanticConventions.NET_PEER_PORT.getValue(), SemanticConventionTestUtil.buildAttributeValue("2705")));
when(e.getAttributes()).thenReturn(attributes);
v = SpanSemanticConventionUtils.getURIForOtelFormat(e);
assertFalse(v.isPresent());
}
use of org.hypertrace.core.datamodel.Attributes in project hypertrace-ingester by hypertrace.
the class LogEventViewGenerator method process.
@Override
public List<LogEventView> process(LogEvents logEvents) {
try {
List<LogEventView> list = new ArrayList<>();
for (LogEvent logEventRecord : logEvents.getLogEvents()) {
String attributes = convertAttributes(logEventRecord.getAttributes());
LogEventView logEventView = fastNewBuilder(LogEventView.Builder.class).setSpanId(logEventRecord.getSpanId()).setTraceId(logEventRecord.getTraceId()).setTimestampNanos(logEventRecord.getTimestampNanos()).setTenantId(logEventRecord.getTenantId()).setAttributes(attributes).setSummary(getSummary(logEventRecord.getAttributes())).build();
if (!StringUtils.isEmpty(logEventRecord.getTenantId()) && null != attributes) {
logEventAttributeSizeGauge.computeIfAbsent(logEventRecord.getTenantId(), v -> PlatformMetricsRegistry.registerGauge(LOG_EVENT_ATTRIBUTE_SIZE_METRIC, Map.of("tenantId", logEventRecord.getTenantId()), new AtomicInteger(0))).set(attributes.length());
}
list.add(logEventView);
}
return list;
} catch (Exception e) {
LOG.error("Exception processing log records", e);
return null;
}
}
use of org.hypertrace.core.datamodel.Attributes in project hypertrace-ingester by hypertrace.
the class MessagingSemanticConventionUtilsTest method testGetRabbitmqDestination.
@Test
public void testGetRabbitmqDestination() {
Event e = mock(Event.class);
Attributes attributes = SemanticConventionTestUtil.buildAttributes(Map.of(OtelMessagingSemanticConventions.MESSAGING_DESTINATION.getValue(), SemanticConventionTestUtil.buildAttributeValue("queueName"), OtelMessagingSemanticConventions.RABBITMQ_ROUTING_KEY.getValue(), SemanticConventionTestUtil.buildAttributeValue("test-key")));
when(e.getAttributes()).thenReturn(attributes);
Optional<String> v = MessagingSemanticConventionUtils.getMessagingDestinationForRabbitmq(e);
assertEquals("test-key.queueName", v.get());
}
use of org.hypertrace.core.datamodel.Attributes in project hypertrace-ingester by hypertrace.
the class MessagingSemanticConventionUtilsTest method testGetRabbitMqRoutingKey.
@Test
public void testGetRabbitMqRoutingKey() {
Event e = mock(Event.class);
// otel format
String routingKey = "otelRoutingKey";
Attributes attributes = buildAttributes(Map.of(OtelMessagingSemanticConventions.RABBITMQ_ROUTING_KEY.getValue(), buildAttributeValue(routingKey)));
when(e.getAttributes()).thenReturn(attributes);
Optional<String> v = MessagingSemanticConventionUtils.getRabbitMqRoutingKey(e);
assertEquals(routingKey, v.get());
// other format
routingKey = "otherRoutingKey";
attributes = buildAttributes(Map.of(RawSpanConstants.getValue(RabbitMq.RABBIT_MQ_ROUTING_KEY), buildAttributeValue(routingKey)));
when(e.getAttributes()).thenReturn(attributes);
v = MessagingSemanticConventionUtils.getRabbitMqRoutingKey(e);
assertEquals(routingKey, v.get());
// routing key absent
attributes = buildAttributes(Map.of("span.kind", buildAttributeValue("client")));
when(e.getAttributes()).thenReturn(attributes);
v = MessagingSemanticConventionUtils.getRabbitMqRoutingKey(e);
assertTrue(v.isEmpty());
}
use of org.hypertrace.core.datamodel.Attributes in project hypertrace-ingester by hypertrace.
the class DbSemanticConventionUtilsTest method testGetMongoURI.
@Test
public void testGetMongoURI() {
Event e = mock(Event.class);
// mongo url key is present
Attributes attributes = SemanticConventionTestUtil.buildAttributes(Map.of(RawSpanConstants.getValue(Mongo.MONGO_URL), SemanticConventionTestUtil.buildAttributeValue("mongo:27017")));
when(e.getAttributes()).thenReturn(attributes);
Optional<String> v = DbSemanticConventionUtils.getMongoURI(e);
assertEquals("mongo:27017", v.get());
// mongo address is present
attributes = SemanticConventionTestUtil.buildAttributes(Map.of(RawSpanConstants.getValue(Mongo.MONGO_ADDRESS), SemanticConventionTestUtil.buildAttributeValue("mongo:27017")));
when(e.getAttributes()).thenReturn(attributes);
v = DbSemanticConventionUtils.getMongoURI(e);
assertEquals("mongo:27017", v.get());
}
Aggregations