Search in sources :

Example 6 with Attributes

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());
}
Also used : Attributes(org.hypertrace.core.datamodel.Attributes) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 7 with Attributes

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;
    }
}
Also used : Schema(org.apache.avro.Schema) Logger(org.slf4j.Logger) AvroBuilderCache.fastNewBuilder(org.hypertrace.core.datamodel.shared.AvroBuilderCache.fastNewBuilder) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LoggerFactory(org.slf4j.LoggerFactory) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) LogEventView(org.hypertrace.viewgenerator.api.LogEventView) ArrayList(java.util.ArrayList) PlatformMetricsRegistry(org.hypertrace.core.serviceframework.metrics.PlatformMetricsRegistry) LogEvents(org.hypertrace.core.datamodel.LogEvents) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Attributes(org.hypertrace.core.datamodel.Attributes) Optional(java.util.Optional) LogEvent(org.hypertrace.core.datamodel.LogEvent) JavaCodeBasedViewGenerator(org.hypertrace.core.viewgenerator.JavaCodeBasedViewGenerator) LogEvent(org.hypertrace.core.datamodel.LogEvent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AvroBuilderCache.fastNewBuilder(org.hypertrace.core.datamodel.shared.AvroBuilderCache.fastNewBuilder) ArrayList(java.util.ArrayList) LogEventView(org.hypertrace.viewgenerator.api.LogEventView) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 8 with Attributes

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());
}
Also used : SemanticConventionTestUtil.buildAttributes(org.hypertrace.semantic.convention.utils.SemanticConventionTestUtil.buildAttributes) Attributes(org.hypertrace.core.datamodel.Attributes) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 9 with Attributes

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());
}
Also used : SemanticConventionTestUtil.buildAttributes(org.hypertrace.semantic.convention.utils.SemanticConventionTestUtil.buildAttributes) Attributes(org.hypertrace.core.datamodel.Attributes) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 10 with Attributes

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());
}
Also used : Attributes(org.hypertrace.core.datamodel.Attributes) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Aggregations

Attributes (org.hypertrace.core.datamodel.Attributes)45 Event (org.hypertrace.core.datamodel.Event)41 Test (org.junit.jupiter.api.Test)40 SemanticConventionTestUtil.buildAttributes (org.hypertrace.semantic.convention.utils.SemanticConventionTestUtil.buildAttributes)8 AttributeValue (org.hypertrace.core.datamodel.AttributeValue)3 HashMap (java.util.HashMap)2 AvroBuilderCache.fastNewBuilder (org.hypertrace.core.datamodel.shared.AvroBuilderCache.fastNewBuilder)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ProtocolStringList (com.google.protobuf.ProtocolStringList)1 JaegerSpanInternalModel (io.jaegertracing.api_v2.JaegerSpanInternalModel)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Nullable (javax.annotation.Nullable)1 Schema (org.apache.avro.Schema)1