use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.
the class HttpAttributeEnricherTest method testDecodeQueryParams.
@Test
public void testDecodeQueryParams() {
String query_string = "action=check%20out&location=hello%3Dworld";
Event e = createMockEvent();
addAttribute(e, RawSpanConstants.getValue(HTTP_PATH), "/users");
addAttribute(e, RawSpanConstants.getValue(HTTP_REQUEST_QUERY_STRING), query_string);
enricher.enrichEvent(mockTrace, e);
AttributeValue actionParam = SpanAttributeUtils.getAttributeValue(e, Constants.getEnrichedSpanConstant(HTTP_REQUEST_QUERY_PARAM) + ".action");
assertEquals("check out", actionParam.getValue());
assertEquals(List.of("check out"), actionParam.getValueList());
AttributeValue locationParam = SpanAttributeUtils.getAttributeValue(e, Constants.getEnrichedSpanConstant(HTTP_REQUEST_QUERY_PARAM) + ".location");
assertEquals("hello=world", locationParam.getValue());
assertEquals(List.of("hello=world"), locationParam.getValueList());
}
use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.
the class HttpAttributeEnricherTest method testMultipleValuedQueryParam.
@Test
public void testMultipleValuedQueryParam() {
String query_string = "action=checkout&action=a&age=2&age=3&location=";
Event e = createMockEvent();
addAttribute(e, RawSpanConstants.getValue(HTTP_PATH), "/users");
addAttribute(e, RawSpanConstants.getValue(HTTP_REQUEST_QUERY_STRING), query_string);
enricher.enrichEvent(mockTrace, e);
String httpPathEnrichedValue = SpanAttributeUtils.getStringAttribute(e, Constants.getEnrichedSpanConstant(HTTP_REQUEST_PATH));
assertEquals("/users", httpPathEnrichedValue);
AttributeValue actionParam = SpanAttributeUtils.getAttributeValue(e, Constants.getEnrichedSpanConstant(HTTP_REQUEST_QUERY_PARAM) + ".action");
assertEquals("checkout", actionParam.getValue());
assertEquals(List.of("checkout", "a"), actionParam.getValueList());
AttributeValue ageParam = SpanAttributeUtils.getAttributeValue(e, Constants.getEnrichedSpanConstant(HTTP_REQUEST_QUERY_PARAM) + ".age");
assertEquals("2", ageParam.getValue());
assertEquals(List.of("2", "3"), ageParam.getValueList());
AttributeValue locationParam = SpanAttributeUtils.getAttributeValue(e, Constants.getEnrichedSpanConstant(HTTP_REQUEST_QUERY_PARAM) + ".location");
assertNull(locationParam);
}
use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.
the class HttpAttributeEnricherTest method testDecodeQueryParamsWithSquareBrackets.
@Test
public void testDecodeQueryParamsWithSquareBrackets() {
// Url with query params not encoded
String query_string = "action[]=checkout&age=2&[]=test";
Event e = createMockEvent();
addAttribute(e, RawSpanConstants.getValue(HTTP_PATH), "/users");
addAttribute(e, RawSpanConstants.getValue(HTTP_REQUEST_QUERY_STRING), query_string);
enricher.enrichEvent(mockTrace, e);
AttributeValue actionParam = SpanAttributeUtils.getAttributeValue(e, Constants.getEnrichedSpanConstant(HTTP_REQUEST_QUERY_PARAM) + ".action");
assertEquals("checkout", actionParam.getValue());
assertEquals(List.of("checkout"), actionParam.getValueList());
AttributeValue ageParam = SpanAttributeUtils.getAttributeValue(e, Constants.getEnrichedSpanConstant(HTTP_REQUEST_QUERY_PARAM) + ".age");
assertEquals("2", ageParam.getValue());
assertEquals(List.of("2"), ageParam.getValueList());
// If seen only bracket, treat the square braces as param key
AttributeValue onlySquareBracketParam = SpanAttributeUtils.getAttributeValue(e, Constants.getEnrichedSpanConstant(HTTP_REQUEST_QUERY_PARAM) + ".[]");
assertEquals("test", onlySquareBracketParam.getValue());
assertEquals(List.of("test"), onlySquareBracketParam.getValueList());
// Create event with URL encoded query params
query_string = "action%5B%5D%3Dcheckout%26age%3D2%26%5B%5D%3Dtest";
e = createMockEvent();
addAttribute(e, RawSpanConstants.getValue(HTTP_PATH), "/users");
addAttribute(e, RawSpanConstants.getValue(HTTP_REQUEST_QUERY_STRING), query_string);
enricher.enrichEvent(mockTrace, e);
assertEquals("checkout", actionParam.getValue());
assertEquals(List.of("checkout"), actionParam.getValueList());
assertEquals("2", ageParam.getValue());
assertEquals(List.of("2"), ageParam.getValueList());
assertEquals("test", onlySquareBracketParam.getValue());
assertEquals(List.of("test"), onlySquareBracketParam.getValueList());
}
use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.
the class SpanTypeAttributeEnricherTest method test_getProtocolName_httpAttributes_shouldReturnHttp.
@Test
public void test_getProtocolName_httpAttributes_shouldReturnHttp() {
Map<String, AttributeValue> map = new HashMap<>();
map.put(Constants.getRawSpanConstant(Http.HTTP_REQUEST_URL), AttributeValue.newBuilder().setValue("http://hypertrace.org").build());
map.put(Constants.getRawSpanConstant(Http.HTTP_REQUEST_METHOD), AttributeValue.newBuilder().setValue("GET").build());
Event e = createEvent(map, new HashMap<>());
Assertions.assertEquals(Protocol.PROTOCOL_HTTP, SpanTypeAttributeEnricher.getProtocolName(e));
}
use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.
the class SpanTypeAttributeEnricherTest method envoySpanCategorization.
@Test
public void envoySpanCategorization() {
SpanTypeAttributeEnricher enricher = new SpanTypeAttributeEnricher();
// No operation name
Event e = createMockEnvoyEvent(null);
enricher.enrichEvent(null, e);
Map<String, AttributeValue> enrichedAttributes = e.getEnrichedAttributes().getAttributeMap();
Assertions.assertEquals(enrichedAttributes.get(Constants.getEnrichedSpanConstant(SPAN_TYPE)).getValue(), Constants.getEnrichedSpanConstant(UNKNOWN));
// Ingress operation should be Entry span.
e = createMockEnvoyEvent(Constants.getRawSpanConstant(Envoy.ENVOY_INGRESS_SPAN));
enricher.enrichEvent(null, e);
enrichedAttributes = e.getEnrichedAttributes().getAttributeMap();
Assertions.assertEquals(enrichedAttributes.get(Constants.getEnrichedSpanConstant(SPAN_TYPE)).getValue(), Constants.getEnrichedSpanConstant(ENTRY));
// Egress operation should be Exit span
e = createMockEnvoyEvent(Constants.getRawSpanConstant(Envoy.ENVOY_EGRESS_SPAN));
enricher.enrichEvent(null, e);
enrichedAttributes = e.getEnrichedAttributes().getAttributeMap();
Assertions.assertEquals(enrichedAttributes.get(Constants.getEnrichedSpanConstant(SPAN_TYPE)).getValue(), Constants.getEnrichedSpanConstant(EXIT));
// Random value is Unknown span
e = createMockEnvoyEvent("Random");
enricher.enrichEvent(null, e);
enrichedAttributes = e.getEnrichedAttributes().getAttributeMap();
Assertions.assertEquals(enrichedAttributes.get(Constants.getEnrichedSpanConstant(SPAN_TYPE)).getValue(), Constants.getEnrichedSpanConstant(UNKNOWN));
}
Aggregations