Search in sources :

Example 21 with Attributes

use of org.hypertrace.core.datamodel.Attributes in project hypertrace-ingester by hypertrace.

the class SpanTypeAttributeEnricherTest method noAttributes.

@Test
public void noAttributes() {
    SpanTypeAttributeEnricher enricher = new SpanTypeAttributeEnricher();
    Event e = mock(Event.class);
    when(e.getAttributes()).thenReturn(null);
    enricher.enrichEvent(null, e);
    when(e.getAttributes()).thenReturn(new Attributes());
    enricher.enrichEvent(null, e);
}
Also used : Attributes(org.hypertrace.core.datamodel.Attributes) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 22 with Attributes

use of org.hypertrace.core.datamodel.Attributes in project hypertrace-ingester by hypertrace.

the class EnricherUtilTest method testSetAttributeForFirstExistingKey.

@Test
public void testSetAttributeForFirstExistingKey() {
    Event e = mock(Event.class);
    Attributes attributes = Attributes.newBuilder().setAttributeMap(Map.of("a", TestUtil.buildAttributeValue("a-value"), "b", TestUtil.buildAttributeValue("b-value"))).build();
    when(e.getAttributes()).thenReturn(attributes);
    Builder entityBuilder = Entity.newBuilder();
    EnricherUtil.setAttributeForFirstExistingKey(e, entityBuilder, Arrays.asList("a", "b", "c"));
    Assertions.assertTrue(entityBuilder.getAttributesMap().containsKey("a"));
}
Also used : Builder(org.hypertrace.entity.data.service.v1.Entity.Builder) Attributes(org.hypertrace.core.datamodel.Attributes) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 23 with Attributes

use of org.hypertrace.core.datamodel.Attributes in project hypertrace-ingester by hypertrace.

the class AbstractTraceEnricher method addEnrichedAttribute.

protected void addEnrichedAttribute(Event event, String key, AttributeValue value) {
    Attributes enrichedAttributes = event.getEnrichedAttributes();
    if (enrichedAttributes == null) {
        enrichedAttributes = fastNewBuilder(Attributes.Builder.class).build();
        event.setEnrichedAttributes(enrichedAttributes);
    }
    enrichedAttributes.getAttributeMap().put(key, value);
}
Also used : Attributes(org.hypertrace.core.datamodel.Attributes)

Example 24 with Attributes

use of org.hypertrace.core.datamodel.Attributes in project hypertrace-ingester by hypertrace.

the class BaseViewGenerator method getTransactionName.

@Nullable
static String getTransactionName(StructuredTrace trace) {
    Attributes attributes = trace.getAttributes();
    if (attributes == null || attributes.getAttributeMap() == null) {
        return null;
    }
    AttributeValue attr = attributes.getAttributeMap().get(EnrichedSpanConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_TRANSACTION_NAME));
    return attr != null ? attr.getValue() : null;
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Attributes(org.hypertrace.core.datamodel.Attributes) Nullable(javax.annotation.Nullable)

Example 25 with Attributes

use of org.hypertrace.core.datamodel.Attributes in project hypertrace-ingester by hypertrace.

the class ErrorSemanticConventionUtilsTest method testCheckForError.

@Test
public void testCheckForError() {
    Event e = mock(Event.class);
    Attributes attributes = SemanticConventionTestUtil.buildAttributes(Map.of(RawSpanConstants.getValue(Error.ERROR_ERROR), SemanticConventionTestUtil.buildAttributeValue("false")));
    when(e.getAttributes()).thenReturn(attributes);
    boolean v = ErrorSemanticConventionUtils.checkForError(e);
    assertFalse(v);
    attributes = SemanticConventionTestUtil.buildAttributes(Map.of(RawSpanConstants.getValue(Error.ERROR_ERROR), SemanticConventionTestUtil.buildAttributeValue("false")));
    when(e.getAttributes()).thenReturn(attributes);
    v = ErrorSemanticConventionUtils.checkForError(e);
    assertFalse(v);
    attributes = SemanticConventionTestUtil.buildAttributes(Map.of(RawSpanConstants.getValue(OTSpanTag.OT_SPAN_TAG_ERROR), SemanticConventionTestUtil.buildAttributeValue("true")));
    when(e.getAttributes()).thenReturn(attributes);
    v = ErrorSemanticConventionUtils.checkForError(e);
    assertTrue(v);
    // check for UNSET, OK
    attributes = SemanticConventionTestUtil.buildAttributes(Map.of(OTelErrorSemanticConventions.STATUS_CODE.getValue(), SemanticConventionTestUtil.buildAttributeValue(OTelErrorSemanticConventions.STATUS_CODE_UNSET_VALUE.getValue())));
    when(e.getAttributes()).thenReturn(attributes);
    v = ErrorSemanticConventionUtils.checkForError(e);
    assertFalse(v);
    attributes = SemanticConventionTestUtil.buildAttributes(Map.of(OTelErrorSemanticConventions.STATUS_CODE.getValue(), SemanticConventionTestUtil.buildAttributeValue(OTelErrorSemanticConventions.STATUS_CODE_OK_VALUE.getValue())));
    when(e.getAttributes()).thenReturn(attributes);
    v = ErrorSemanticConventionUtils.checkForError(e);
    assertFalse(v);
    // check for ERROR
    attributes = SemanticConventionTestUtil.buildAttributes(Map.of(OTelErrorSemanticConventions.STATUS_CODE.getValue(), SemanticConventionTestUtil.buildAttributeValue(OTelErrorSemanticConventions.STATUS_CODE_ERROR_VALUE.getValue())));
    when(e.getAttributes()).thenReturn(attributes);
    v = ErrorSemanticConventionUtils.checkForError(e);
    assertTrue(v);
    // check for both the attributes are empty
    attributes = SemanticConventionTestUtil.buildAttributes(Map.of());
    when(e.getAttributes()).thenReturn(attributes);
    v = ErrorSemanticConventionUtils.checkForError(e);
    assertFalse(v);
}
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