use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.
the class UserAgentSpanEnricherTest method badUserAgent.
@Test
public void badUserAgent() {
String badUserAgent = "I am not a User Agent!";
Event e = createMockEvent();
when(e.getHttp()).thenReturn(Http.newBuilder().setRequest(Request.newBuilder().setHeaders(RequestHeaders.newBuilder().setUserAgent(badUserAgent).build()).setUserAgent(badUserAgent).build()).build());
mockProtocol(e, Protocol.PROTOCOL_HTTP);
addAttribute(e, RawSpanConstants.getValue(HTTP_USER_DOT_AGENT), badUserAgent);
addAttribute(e, RawSpanConstants.getValue(HTTP_USER_AGENT_REQUEST_HEADER), badUserAgent);
enricher.enrichEvent(null, e);
Map<String, AttributeValue> map = e.getEnrichedAttributes().getAttributeMap();
assertEquals(7, map.size());
assertEquals("unknown", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_NAME)).getValue());
assertEquals("", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_BROWSER_VERSION)).getValue());
assertEquals("", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_DEVICE_CATEGORY)).getValue());
assertEquals("unknown", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_OS_NAME)).getValue());
assertEquals("", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_OS_VERSION)).getValue());
assertEquals("", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_BROWSER_VERSION)).getValue());
}
use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.
the class UserAgentSpanEnricherTest method should_preferUserAgent_fromHeaders.
@Test
public void should_preferUserAgent_fromHeaders() {
String userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3)" + " AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36";
Event e = createMockEvent();
when(e.getHttp()).thenReturn(Http.newBuilder().setRequest(Request.newBuilder().setHeaders(RequestHeaders.newBuilder().setUserAgent(userAgent).build()).setUserAgent("I am not a User Agent!").build()).build());
mockProtocol(e, Protocol.PROTOCOL_HTTP);
addAttribute(e, RawSpanConstants.getValue(HTTP_USER_DOT_AGENT), "I am not a User Agent!");
addAttribute(e, RawSpanConstants.getValue(HTTP_USER_AGENT_REQUEST_HEADER), userAgent);
enricher.enrichEvent(null, e);
Map<String, AttributeValue> map = e.getEnrichedAttributes().getAttributeMap();
assertEquals(7, map.size());
assertEquals("Chrome", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_NAME)).getValue());
assertEquals("Browser", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_TYPE)).getValue());
assertEquals("Personal computer", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_DEVICE_CATEGORY)).getValue());
assertEquals("OS X", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_OS_NAME)).getValue());
assertEquals("10.14.3", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_OS_VERSION)).getValue());
assertEquals("73.0.3683.103", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_BROWSER_VERSION)).getValue());
}
use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.
the class UserAgentSpanEnricherTest method should_fallbackToUserAgent_fromRequest.
@Test
public void should_fallbackToUserAgent_fromRequest() {
String userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3)" + " AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36";
Event e = createMockEvent();
when(e.getHttp()).thenReturn(Http.newBuilder().setRequest(Request.newBuilder().setUserAgent(userAgent).build()).build());
mockProtocol(e, Protocol.PROTOCOL_HTTP);
addAttribute(e, RawSpanConstants.getValue(HTTP_USER_DOT_AGENT), userAgent);
enricher.enrichEvent(null, e);
Map<String, AttributeValue> map = e.getEnrichedAttributes().getAttributeMap();
assertEquals(7, map.size());
assertEquals("Chrome", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_NAME)).getValue());
assertEquals("Browser", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_TYPE)).getValue());
assertEquals("Personal computer", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_DEVICE_CATEGORY)).getValue());
assertEquals("OS X", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_OS_NAME)).getValue());
assertEquals("10.14.3", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_OS_VERSION)).getValue());
assertEquals("73.0.3683.103", map.get(Constants.getEnrichedSpanConstant(UserAgent.USER_AGENT_BROWSER_VERSION)).getValue());
}
use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.
the class CassandraBackendProviderTest method testBackendResolutionWithoutConnectionString.
@Test
public void testBackendResolutionWithoutConnectionString() {
BackendInfo backendInfo = backendEntityEnricher.resolve(getCassandraOTelEvent(), structuredTrace, structuredTraceGraph).get();
Entity entity = backendInfo.getEntity();
Assertions.assertEquals("test:9000", entity.getEntityName());
Map<String, AttributeValue> attributes = backendInfo.getAttributes();
assertEquals(Map.of("BACKEND_OPERATION", AttributeValueCreator.create("select"), "BACKEND_DESTINATION", AttributeValueCreator.create("customer.orders")), attributes);
}
use of org.hypertrace.core.datamodel.AttributeValue in project hypertrace-ingester by hypertrace.
the class ElasticsearchBackendProviderTest method testBackendResolution.
@Test
public void testBackendResolution() {
BackendInfo backendInfo = backendEntityEnricher.resolve(getElasticsearchEvent(), structuredTrace, structuredTraceGraph).get();
Entity entity = backendInfo.getEntity();
Assertions.assertEquals("test-index", entity.getEntityName());
Map<String, AttributeValue> attributes = backendInfo.getAttributes();
assertEquals(Map.of("BACKEND_OPERATION", AttributeValueCreator.create("GET"), "BACKEND_DESTINATION", AttributeValueCreator.create("test-index")), attributes);
}
Aggregations