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