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;
}
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()));
}
}
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());
}
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;
}
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;
}
Aggregations