Search in sources :

Example 76 with AttributeValue

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

the class TransactionNameEnricher method enrichTrace.

@Override
public void enrichTrace(StructuredTrace trace) {
    /* possible if the trace is not created from Builder */
    if (trace.getAttributes() == null) {
        return;
    }
    if (trace.getAttributes().getAttributeMap() == null) {
        return;
    }
    Event earliestEvent = getEarliestEvent(trace);
    // assumes unknown if there's no Api Name set for this event
    if (EnrichedSpanUtils.isEntrySpan(earliestEvent)) {
        LOGGER.debug("Found earliest Event in this trace. It is {}", earliestEvent);
        String apiName = EnrichedSpanUtils.getApiName(earliestEvent);
        if (apiName != null) {
            Map<String, AttributeValue> attributes = trace.getAttributes().getAttributeMap();
            attributes.put(EnrichedSpanConstants.getValue(CommonAttribute.COMMON_ATTRIBUTE_TRANSACTION_NAME), AttributeValueCreator.create(apiName));
        }
    }
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Event(org.hypertrace.core.datamodel.Event)

Example 77 with AttributeValue

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

the class EnrichedSpanUtilsTest method testGetAttributesForPrefixAttributeKey.

@Test
public void testGetAttributesForPrefixAttributeKey() {
    Event event = createMockEventWithAttribute("prefix.hello", "world");
    Map<String, AttributeValue> filteredMap = SpanAttributeUtils.getAttributesWithPrefixKey(event, "prefix");
    assertEquals("world", filteredMap.get("prefix.hello").getValue());
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test)

Example 78 with AttributeValue

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

the class AbstractTraceEnricher method addEnrichedAttributeIfNotNull.

protected void addEnrichedAttributeIfNotNull(Event event, String key, String value) {
    if (value != null) {
        AttributeValue attributeValue = fastNewBuilder(AttributeValue.Builder.class).setValue(value).build();
        addEnrichedAttribute(event, key, attributeValue);
    }
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue)

Example 79 with AttributeValue

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

the class AbstractAttributeEnricherTest method getBigTrace.

protected StructuredTrace getBigTrace() {
    /*
     * The graph looks like
     *             0 (proxy/entry)
     *             |
     *             1 (i)
     *           /    \
     *          2 (i)  3 (i)
     *          |
     *          4 (proxy/exit)
     *
     * i -> intermediate span
     */
    // 0th raw span
    Map<String, AttributeValue> entrySpanProxyMap = new HashMap<>();
    entrySpanProxyMap.put(Constants.getEnrichedSpanConstant(SPAN_TYPE), AttributeValue.newBuilder().setValue("ENTRY").build());
    entrySpanProxyMap.put(Constants.getEnrichedSpanConstant(Api.API_BOUNDARY_TYPE), AttributeValue.newBuilder().setValue("ENTRY").build());
    entrySpanProxyMap.put(Constants.getRawSpanConstant(TRACER_TYPE), AttributeValue.newBuilder().setValue(PROXY_TRACER).build());
    entrySpanProxyMap.put(Constants.getRawSpanConstant(Docker.DOCKER_CONTAINER_ID), AttributeValue.newBuilder().setValue("container1").build());
    Map<String, AttributeValue> enrichedEntrySpanProxyMap = new HashMap<>();
    enrichedEntrySpanProxyMap.put(Constants.getEntityConstant(ServiceAttribute.SERVICE_ATTRIBUTE_ID), AttributeValue.newBuilder().setValue(COMMON_ENTITY_ID).build());
    enrichedEntrySpanProxyMap.put(Constants.getEntityConstant(ServiceAttribute.SERVICE_ATTRIBUTE_NAME), AttributeValue.newBuilder().setValue(COMMON_ENTITY_NAME).build());
    Event event0 = Event.newBuilder().setCustomerId(TENANT_ID).setAttributes(org.hypertrace.core.datamodel.Attributes.newBuilder().setAttributeMap(entrySpanProxyMap).build()).setEnrichedAttributes(org.hypertrace.core.datamodel.Attributes.newBuilder().setAttributeMap(enrichedEntrySpanProxyMap).build()).setEventId(createByteBuffer("event0")).build();
    RawSpan rawSpan0 = RawSpan.newBuilder().setCustomerId(TENANT_ID).setEvent(event0).setTraceId(createByteBuffer("trace")).build();
    // 1st raw span CHILD_OF event0
    EventRef eventRef0 = EventRef.newBuilder().setRefType(EventRefType.CHILD_OF).setTraceId(createByteBuffer("trace")).setEventId(createByteBuffer("event0")).build();
    Map<String, AttributeValue> event1EnrichedMap = new HashMap<>();
    event1EnrichedMap.put(Constants.getRawSpanConstant(TRACER_TYPE), AttributeValue.newBuilder().setValue(JAVA_TRACER).build());
    event1EnrichedMap.put(Constants.getEnrichedSpanConstant(SPAN_TYPE), AttributeValue.newBuilder().setValue("ENTRY").build());
    event1EnrichedMap.put(Constants.getRawSpanConstant(Docker.DOCKER_CONTAINER_ID), AttributeValue.newBuilder().setValue("agentContainerId").build());
    Event event1 = Event.newBuilder().setCustomerId(TENANT_ID).setEventId(createByteBuffer("event1")).setEventRefList(Collections.singletonList(eventRef0)).setEnrichedAttributes(org.hypertrace.core.datamodel.Attributes.newBuilder().setAttributeMap(event1EnrichedMap).build()).build();
    RawSpan rawSpan1 = RawSpan.newBuilder().setCustomerId(TENANT_ID).setEvent(event1).setTraceId(createByteBuffer("trace")).build();
    // 2nd raw span CHILD_OF event1
    EventRef eventRef1 = EventRef.newBuilder().setRefType(EventRefType.CHILD_OF).setTraceId(createByteBuffer("trace")).setEventId(createByteBuffer("event1")).build();
    Map<String, AttributeValue> event2EnrichedMap = new HashMap<>();
    event2EnrichedMap.put(Constants.getRawSpanConstant(TRACER_TYPE), AttributeValue.newBuilder().setValue(JAVA_TRACER).build());
    event2EnrichedMap.put(Constants.getEnrichedSpanConstant(SPAN_TYPE), AttributeValue.newBuilder().setValue("EXIT").build());
    event2EnrichedMap.put(Constants.getRawSpanConstant(Docker.DOCKER_CONTAINER_ID), AttributeValue.newBuilder().setValue("agentContainerId").build());
    Event event2 = Event.newBuilder().setCustomerId(TENANT_ID).setEventId(createByteBuffer("event2")).setEnrichedAttributes(org.hypertrace.core.datamodel.Attributes.newBuilder().setAttributeMap(event2EnrichedMap).build()).setEventRefList(Collections.singletonList(eventRef1)).build();
    RawSpan rawSpan2 = RawSpan.newBuilder().setCustomerId(TENANT_ID).setEvent(event2).setTraceId(createByteBuffer("trace")).build();
    // 3nd raw span CHILD_OF event1
    Event event3 = Event.newBuilder().setCustomerId(TENANT_ID).setEventId(createByteBuffer("event3")).setEventRefList(Collections.singletonList(eventRef1)).build();
    RawSpan rawSpan3 = RawSpan.newBuilder().setCustomerId(TENANT_ID).setEvent(event3).setTraceId(createByteBuffer("trace")).build();
    // 4th raw span CHILD_OF event2
    EventRef eventRef2 = EventRef.newBuilder().setRefType(EventRefType.CHILD_OF).setTraceId(createByteBuffer("trace")).setEventId(createByteBuffer("event2")).build();
    Map<String, AttributeValue> exitSpanProxyMap = new HashMap<>();
    exitSpanProxyMap.put(Constants.getRawSpanConstant(TRACER_TYPE), AttributeValue.newBuilder().setValue(PROXY_TRACER).build());
    exitSpanProxyMap.put(Constants.getRawSpanConstant(Docker.DOCKER_CONTAINER_ID), AttributeValue.newBuilder().setValue("container1").build());
    Map<String, AttributeValue> exitSpanProxyEnrichedMap = new HashMap<>();
    exitSpanProxyEnrichedMap.put(Constants.getEnrichedSpanConstant(SPAN_TYPE), AttributeValue.newBuilder().setValue("EXIT").build());
    exitSpanProxyEnrichedMap.put(Constants.getEnrichedSpanConstant(Api.API_BOUNDARY_TYPE), AttributeValue.newBuilder().setValue("EXIT").build());
    exitSpanProxyEnrichedMap.put(Constants.getEntityConstant(ServiceAttribute.SERVICE_ATTRIBUTE_ID), AttributeValue.newBuilder().setValue(COMMON_ENTITY_ID).build());
    exitSpanProxyEnrichedMap.put(Constants.getEntityConstant(ServiceAttribute.SERVICE_ATTRIBUTE_NAME), AttributeValue.newBuilder().setValue(COMMON_ENTITY_NAME).build());
    Event event4 = Event.newBuilder().setCustomerId(TENANT_ID).setEventId(createByteBuffer("event4")).setAttributes(org.hypertrace.core.datamodel.Attributes.newBuilder().setAttributeMap(exitSpanProxyMap).build()).setEnrichedAttributes(org.hypertrace.core.datamodel.Attributes.newBuilder().setAttributeMap(exitSpanProxyEnrichedMap).build()).setEventRefList(Collections.singletonList(eventRef2)).build();
    RawSpan rawSpan4 = RawSpan.newBuilder().setCustomerId(TENANT_ID).setEvent(event4).setTraceId(createByteBuffer("trace")).build();
    return StructuredTraceBuilder.buildStructuredTraceFromRawSpans(List.of(rawSpan0, rawSpan1, rawSpan2, rawSpan3, rawSpan4), createByteBuffer("trace"), TENANT_ID);
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) EventRef(org.hypertrace.core.datamodel.EventRef) HashMap(java.util.HashMap) Event(org.hypertrace.core.datamodel.Event) RawSpan(org.hypertrace.core.datamodel.RawSpan)

Example 80 with AttributeValue

use of org.hypertrace.core.datamodel.AttributeValue 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)

Aggregations

AttributeValue (org.hypertrace.core.datamodel.AttributeValue)84 Test (org.junit.jupiter.api.Test)65 Event (org.hypertrace.core.datamodel.Event)53 BackendInfo (org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo)24 Entity (org.hypertrace.entity.data.service.v1.Entity)22 HashMap (java.util.HashMap)19 TestUtil.buildAttributeValue (org.hypertrace.traceenricher.TestUtil.buildAttributeValue)11 AvroBuilderCache.fastNewBuilder (org.hypertrace.core.datamodel.shared.AvroBuilderCache.fastNewBuilder)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 EventRef (org.hypertrace.core.datamodel.EventRef)3 StructuredTrace (org.hypertrace.core.datamodel.StructuredTrace)3 Attributes (org.hypertrace.core.datamodel.Attributes)2 MetricValue (org.hypertrace.core.datamodel.MetricValue)2 RawSpan (org.hypertrace.core.datamodel.RawSpan)2 SpanEventView (org.hypertrace.viewgenerator.api.SpanEventView)2 ImmutableList (com.google.common.collect.ImmutableList)1 ByteString (com.google.protobuf.ByteString)1 ProtocolStringList (com.google.protobuf.ProtocolStringList)1