Search in sources :

Example 1 with AttributeValue

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

the class SpanTypeAttributeEnricher method getGrpcProtocol.

@Nonnull
public static Protocol getGrpcProtocol(Event event) {
    Map<String, AttributeValue> attributeMap = event.getAttributes().getAttributeMap();
    if (RpcSemanticConventionUtils.isRpcTypeGrpcForOTelFormat(event)) {
        return Protocol.PROTOCOL_GRPC;
    }
    if (attributeMap.containsKey(OTEL_SPAN_TAG_RPC_SYSTEM_ATTR)) {
        String rpcSystem = attributeMap.get(OTEL_SPAN_TAG_RPC_SYSTEM_ATTR).getValue();
        if (GRPC_PROTOCOL_VALUE.equalsIgnoreCase(rpcSystem)) {
            return Protocol.PROTOCOL_GRPC;
        }
    }
    // check Open Tracing grpc component value first
    AttributeValue componentAttrValue = attributeMap.get(RawSpanConstants.getValue(OTSpanTag.OT_SPAN_TAG_COMPONENT));
    if (componentAttrValue != null) {
        if (GRPC_PROTOCOL_VALUE.equalsIgnoreCase(componentAttrValue.getValue())) {
            return Protocol.PROTOCOL_GRPC;
        }
    }
    /* This logic is the brute force checking if there's any attribute starts with grpc.
     * Unfortunately, depends on the language, instrumented vs non, we can't count on a set
     * of attributes that can identify the protocol.
     */
    for (String attrKey : attributeMap.keySet()) {
        String upperCaseKey = attrKey.toUpperCase();
        if (upperCaseKey.startsWith(GRPC_PROTOCOL_VALUE.toUpperCase())) {
            return Protocol.PROTOCOL_GRPC;
        }
    }
    // this means, there's no grpc prefix protocol
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Couldn't map the event to any protocol; eventId: {}", event.getEventId());
    }
    return Protocol.PROTOCOL_UNSPECIFIED;
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Nonnull(javax.annotation.Nonnull)

Example 2 with AttributeValue

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

the class UserAgentSpanEnricher method enrichEvent.

@Override
public void enrichEvent(StructuredTrace trace, Event event) {
    if (event.getAttributes() == null) {
        return;
    }
    Map<String, AttributeValue> attributeMap = event.getAttributes().getAttributeMap();
    if (attributeMap == null) {
        return;
    }
    // extract the user-agent header
    Optional<String> mayBeUserAgent = getUserAgent(event);
    if (mayBeUserAgent.isPresent()) {
        String userAgentStr = mayBeUserAgent.get();
        if (userAgentStr.length() > userAgentMaxLength) {
            userAgentStr = userAgentStr.substring(0, userAgentMaxLength);
        }
        ReadableUserAgent userAgent = userAgentCache != null ? userAgentCache.getUnchecked(userAgentStr) : userAgentStringParser.parse(userAgentStr);
        addEnrichedAttribute(event, EnrichedSpanConstants.getValue(UserAgent.USER_AGENT_NAME), AttributeValueCreator.create(userAgent.getName()));
        addEnrichedAttribute(event, EnrichedSpanConstants.getValue(UserAgent.USER_AGENT_TYPE), AttributeValueCreator.create(userAgent.getType().getName()));
        addEnrichedAttribute(event, EnrichedSpanConstants.getValue(UserAgent.USER_AGENT_DEVICE_CATEGORY), AttributeValueCreator.create(userAgent.getDeviceCategory().getName()));
        addEnrichedAttribute(event, EnrichedSpanConstants.getValue(UserAgent.USER_AGENT_OS_NAME), AttributeValueCreator.create(userAgent.getOperatingSystem().getName()));
        addEnrichedAttribute(event, EnrichedSpanConstants.getValue(UserAgent.USER_AGENT_OS_VERSION), AttributeValueCreator.create(userAgent.getOperatingSystem().getVersionNumber().toVersionString()));
        addEnrichedAttribute(event, EnrichedSpanConstants.getValue(UserAgent.USER_AGENT_BROWSER_VERSION), AttributeValueCreator.create(userAgent.getVersionNumber().toVersionString()));
    }
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) ReadableUserAgent(net.sf.uadetector.ReadableUserAgent)

Example 3 with AttributeValue

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

the class EnrichedSpanUtilsTest method testGetEnrichedAttributesForPrefixAttributeKey.

@Test
public void testGetEnrichedAttributesForPrefixAttributeKey() {
    Event event = createMockEventWithEnrichedAttribute("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 4 with AttributeValue

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

the class EnrichedEntityAvroConverter method getAvroAttributeMap.

/**
 * Converts the attributes of the given proto based entity into AVRO attribute map.
 */
public static Map<String, AttributeValue> getAvroAttributeMap(EnrichedEntity entity) {
    Map<String, AttributeValue> attributeMap = new HashMap<>();
    // Convert the proto attributes to Avro based entity attributes.
    for (Map.Entry<String, org.hypertrace.entity.data.service.v1.AttributeValue> entry : entity.getAttributesMap().entrySet()) {
        org.hypertrace.entity.data.service.v1.AttributeValue value = entry.getValue();
        AttributeValue result = null;
        if (value.getTypeCase() == org.hypertrace.entity.data.service.v1.AttributeValue.TypeCase.VALUE) {
            switch(value.getValue().getTypeCase()) {
                case STRING:
                    result = fastNewBuilder(AttributeValue.Builder.class).setValue(value.getValue().getString()).build();
                    break;
                case INT:
                    result = fastNewBuilder(AttributeValue.Builder.class).setValue(String.valueOf(value.getValue().getInt())).build();
                    break;
                case LONG:
                    result = fastNewBuilder(AttributeValue.Builder.class).setValue(String.valueOf(value.getValue().getLong())).build();
                    break;
                case BYTES:
                    result = fastNewBuilder(AttributeValue.Builder.class).setBinaryValue(value.getValue().getBytes().asReadOnlyByteBuffer()).build();
                    break;
                case DOUBLE:
                    result = fastNewBuilder(AttributeValue.Builder.class).setValue(String.valueOf(value.getValue().getDouble())).build();
                    break;
                case FLOAT:
                    result = fastNewBuilder(AttributeValue.Builder.class).setValue(String.valueOf(value.getValue().getFloat())).build();
                    break;
                case TIMESTAMP:
                    result = fastNewBuilder(AttributeValue.Builder.class).setValue(String.valueOf(value.getValue().getTimestamp())).build();
                    break;
                case BOOLEAN:
                    result = fastNewBuilder(AttributeValue.Builder.class).setValue(String.valueOf(value.getValue().getBoolean())).build();
                    break;
                default:
                    LOG.warn("Unhandled entity attribute type: " + value.getValue().getTypeCase());
            }
        } else {
            // Currently we don't copy the list or map types.
            LOG.warn("Unsupported entity attribute type: " + value);
        }
        if (result != null) {
            attributeMap.put(entry.getKey(), result);
        }
    }
    return attributeMap;
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) HashMap(java.util.HashMap) AvroBuilderCache.fastNewBuilder(org.hypertrace.core.datamodel.shared.AvroBuilderCache.fastNewBuilder) Map(java.util.Map) HashMap(java.util.HashMap)

Example 5 with AttributeValue

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

the class EntityAvroConverter method getAvroAttributeMap.

private static Map<String, AttributeValue> getAvroAttributeMap(org.hypertrace.entity.data.service.v1.Entity entity) {
    Map<String, AttributeValue> attributeMap = new HashMap<>();
    // Convert the proto attributes to Avro based entity attributes.
    for (Map.Entry<String, org.hypertrace.entity.data.service.v1.AttributeValue> entry : entity.getAttributesMap().entrySet()) {
        org.hypertrace.entity.data.service.v1.AttributeValue value = entry.getValue();
        AttributeValue result = null;
        if (value.getTypeCase() == org.hypertrace.entity.data.service.v1.AttributeValue.TypeCase.VALUE) {
            if (value.getValue().getTypeCase() == TypeCase.BYTES) {
                result = fastNewBuilder(AttributeValue.Builder.class).setBinaryValue(value.getValue().getBytes().asReadOnlyByteBuffer()).build();
            } else {
                Optional<String> valueStr = convertValueToString(value.getValue());
                if (valueStr.isPresent()) {
                    result = fastNewBuilder(AttributeValue.Builder.class).setValue(valueStr.get()).build();
                }
            }
        } else if (value.getTypeCase() == org.hypertrace.entity.data.service.v1.AttributeValue.TypeCase.VALUE_LIST) {
            org.hypertrace.entity.data.service.v1.AttributeValueList attributeValueList = value.getValueList();
            List<String> avroValuesStringList = new ArrayList<>();
            for (org.hypertrace.entity.data.service.v1.AttributeValue attributeValue : attributeValueList.getValuesList()) {
                if (attributeValue.getTypeCase() == org.hypertrace.entity.data.service.v1.AttributeValue.TypeCase.VALUE) {
                    Optional<String> valueStr = convertValueToString(attributeValue.getValue());
                    valueStr.ifPresent(avroValuesStringList::add);
                } else {
                    LOG.warn("Unsupported entity attribute type of list of lists or list of maps: {}", attributeValue);
                }
            }
            // Only add the list if it's not empty
            if (!avroValuesStringList.isEmpty()) {
                result = fastNewBuilder(AttributeValue.Builder.class).setValueList(avroValuesStringList).build();
            }
        } else {
            // Currently we don't copy the map types.
            LOG.warn("Unsupported entity attribute type: " + value);
        }
        if (result != null) {
            attributeMap.put(entry.getKey(), result);
        }
    }
    return attributeMap;
}
Also used : AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Optional(java.util.Optional) HashMap(java.util.HashMap) AvroBuilderCache.fastNewBuilder(org.hypertrace.core.datamodel.shared.AvroBuilderCache.fastNewBuilder) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

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