use of org.hypertrace.core.datamodel.RawSpan in project hypertrace-ingester by hypertrace.
the class MigrationTestHttp method testAbsoluteUrlNotSetsUrlField.
@Test
public void testAbsoluteUrlNotSetsUrlField() throws Exception {
Span span = createSpanFromTags(Map.of(RawSpanConstants.getValue(HTTP_URL), "http://abc.xyz/dispatch/test?a=b&k1=v1"));
RawSpan rawSpan = normalizer.convert("tenant-key", span, buildEvent("tenant-key", span, Optional.empty()));
// now, we are not populating first class fields. So, it should be null.
assertNull(rawSpan.getEvent().getHttp());
assertAll(() -> assertTrue(HttpSemanticConventionUtils.getHttpUrl(rawSpan.getEvent()).isPresent()), () -> assertEquals("http://abc.xyz/dispatch/test?a=b&k1=v1", HttpSemanticConventionUtils.getHttpUrl(rawSpan.getEvent()).get()));
}
use of org.hypertrace.core.datamodel.RawSpan in project hypertrace-ingester by hypertrace.
the class MigrationTestHttp method testSetPath.
@Test
public void testSetPath() throws Exception {
Span span = createSpanFromTags(Map.of(OTelHttpSemanticConventions.HTTP_TARGET.getValue(), "/api/v1/gatekeeper/check?url=%2Fpixel%2Factivities%3Fadvertisable%3DTRHRT&method=GET&service=pixel"));
RawSpan rawSpan = normalizer.convert("tenant-key", span, buildEvent("tenant-key", span, Optional.empty()));
// now, we are not populating first class fields. So, it should be null.
assertNull(rawSpan.getEvent().getHttp());
assertEquals("/api/v1/gatekeeper/check", HttpSemanticConventionUtils.getHttpPath(rawSpan.getEvent()).get());
}
use of org.hypertrace.core.datamodel.RawSpan in project hypertrace-ingester by hypertrace.
the class MigrationTestHttp method testRequestUserAgentTagKeysPriority.
@ParameterizedTest
@MethodSource("provideMapForTestingRequestUserAgentTagKeysPriority")
public void testRequestUserAgentTagKeysPriority(Map<String, String> tagsMap, String userAgent) throws Exception {
Span span = createSpanFromTags(tagsMap);
RawSpan rawSpan = normalizer.convert("tenant-key", span, buildEvent("tenant-key", span, Optional.empty()));
// now, we are not populating first class fields. So, it should be null.
assertNull(rawSpan.getEvent().getHttp());
assertEquals(userAgent, HttpSemanticConventionUtils.getHttpUserAgent(rawSpan.getEvent()).get());
}
use of org.hypertrace.core.datamodel.RawSpan in project hypertrace-ingester by hypertrace.
the class MigrationTestHttp method testRequestMethodPriority.
@ParameterizedTest
@MethodSource("provideMapForTestingRequestMethodPriority")
public void testRequestMethodPriority(Map<String, String> tagsMap, String expectedMethod) throws Exception {
Span span = createSpanFromTags(tagsMap);
RawSpan rawSpan = normalizer.convert("tenant-key", span, buildEvent("tenant-key", span, Optional.empty()));
// now, we are not populating first class fields. So, it should be null.
assertNull(rawSpan.getEvent().getHttp());
assertEquals(expectedMethod, HttpSemanticConventionUtils.getHttpMethod(rawSpan.getEvent()).get());
}
use of org.hypertrace.core.datamodel.RawSpan in project hypertrace-ingester by hypertrace.
the class MigrationTestHttp method testInvalidUrlRejectedByUrlValidator.
@Test
public void testInvalidUrlRejectedByUrlValidator() throws Exception {
Span span = Span.newBuilder().addTags(KeyValue.newBuilder().setKey(RawSpanConstants.getValue(HTTP_URL)).setVStr("https://example.ai/apis/5673/events?a1=v1&a2=v2")).build();
RawSpan rawSpan = normalizer.convert("tenant-key", span, buildEvent("tenant-key", span, Optional.empty()));
// now, we are not populating first class fields. So, it should be null.
assertNull(rawSpan.getEvent().getHttp());
assertEquals("https", HttpSemanticConventionUtils.getHttpScheme(rawSpan.getEvent()).get());
assertEquals("example.ai", HttpSemanticConventionUtils.getHttpHost(rawSpan.getEvent()).get());
assertEquals("/apis/5673/events", HttpSemanticConventionUtils.getHttpPath(rawSpan.getEvent()).get());
assertEquals("a1=v1&a2=v2", HttpSemanticConventionUtils.getHttpQueryString(rawSpan.getEvent()).get());
// Removes the trailing "/" for path
span = Span.newBuilder().addTags(KeyValue.newBuilder().setKey(RawSpanConstants.getValue(HTTP_URL)).setVStr("https://example.ai/apis/5673/events/?a1=v1&a2=v2")).build();
rawSpan = normalizer.convert("tenant-key", span, buildEvent("tenant-key", span, Optional.empty()));
// now, we are not populating first class fields. So, it should be null.
assertNull(rawSpan.getEvent().getHttp());
assertEquals("https", HttpSemanticConventionUtils.getHttpScheme(rawSpan.getEvent()).get());
assertEquals("example.ai", HttpSemanticConventionUtils.getHttpHost(rawSpan.getEvent()).get());
assertEquals("/apis/5673/events", HttpSemanticConventionUtils.getHttpPath(rawSpan.getEvent()).get());
assertEquals("a1=v1&a2=v2", HttpSemanticConventionUtils.getHttpQueryString(rawSpan.getEvent()).get());
// No query
span = Span.newBuilder().addTags(KeyValue.newBuilder().setKey(RawSpanConstants.getValue(HTTP_URL)).setVStr("https://example.ai/apis/5673/events")).build();
rawSpan = normalizer.convert("tenant-key", span, buildEvent("tenant-key", span, Optional.empty()));
// now, we are not populating first class fields. So, it should be null.
assertNull(rawSpan.getEvent().getHttp());
assertEquals("https", HttpSemanticConventionUtils.getHttpScheme(rawSpan.getEvent()).get());
assertEquals("example.ai", HttpSemanticConventionUtils.getHttpHost(rawSpan.getEvent()).get());
assertEquals("/apis/5673/events", HttpSemanticConventionUtils.getHttpPath(rawSpan.getEvent()).get());
assertFalse(HttpSemanticConventionUtils.getHttpQueryString(rawSpan.getEvent()).isPresent());
// No path
span = Span.newBuilder().addTags(KeyValue.newBuilder().setKey(RawSpanConstants.getValue(HTTP_URL)).setVStr("https://example.ai")).build();
rawSpan = normalizer.convert("tenant-key", span, buildEvent("tenant-key", span, Optional.empty()));
// now, we are not populating first class fields. So, it should be null.
assertNull(rawSpan.getEvent().getHttp());
assertEquals("https", HttpSemanticConventionUtils.getHttpScheme(rawSpan.getEvent()).get());
assertEquals("example.ai", HttpSemanticConventionUtils.getHttpHost(rawSpan.getEvent()).get());
assertEquals("/", HttpSemanticConventionUtils.getHttpPath(rawSpan.getEvent()).get());
assertFalse(HttpSemanticConventionUtils.getHttpQueryString(rawSpan.getEvent()).isPresent());
// Relative URL - should extract path and query string only
span = Span.newBuilder().addTags(KeyValue.newBuilder().setKey(RawSpanConstants.getValue(HTTP_URL)).setVStr("/apis/5673/events?a1=v1&a2=v2")).build();
rawSpan = normalizer.convert("tenant-key", span, buildEvent("tenant-key", span, Optional.empty()));
// now, we are not populating first class fields. So, it should be null.
assertNull(rawSpan.getEvent().getHttp());
assertFalse(HttpSemanticConventionUtils.getHttpUrl(rawSpan.getEvent()).isPresent());
assertFalse(HttpSemanticConventionUtils.getHttpScheme(rawSpan.getEvent()).isPresent());
assertFalse(HttpSemanticConventionUtils.getHttpHost(rawSpan.getEvent()).isPresent());
assertEquals("a1=v1&a2=v2", HttpSemanticConventionUtils.getHttpQueryString(rawSpan.getEvent()).get());
assertEquals("/apis/5673/events", HttpSemanticConventionUtils.getHttpPath(rawSpan.getEvent()).get());
// "/" home path, host with port
span = Span.newBuilder().addTags(KeyValue.newBuilder().setKey(RawSpanConstants.getValue(HTTP_URL)).setVStr("http://example.ai:9000/?a1=v1&a2=v2")).build();
rawSpan = normalizer.convert("tenant-key", span, buildEvent("tenant-key", span, Optional.empty()));
// now, we are not populating first class fields. So, it should be null.
assertNull(rawSpan.getEvent().getHttp());
assertEquals("http", HttpSemanticConventionUtils.getHttpScheme(rawSpan.getEvent()).get());
assertEquals("example.ai:9000", HttpSemanticConventionUtils.getHttpHost(rawSpan.getEvent()).get());
assertEquals("/", HttpSemanticConventionUtils.getHttpPath(rawSpan.getEvent()).get());
assertEquals("a1=v1&a2=v2", HttpSemanticConventionUtils.getHttpQueryString(rawSpan.getEvent()).get());
// Set path and query string before calling populateOtherFields. Simulate case where fields came
// from attributes
span = Span.newBuilder().addTags(KeyValue.newBuilder().setKey(RawSpanConstants.getValue(HTTP_URL)).setVStr("http://example.ai:9000/apis/4533?a1=v1&a2=v2")).addTags(KeyValue.newBuilder().setKey(RawSpanConstants.getValue(HTTP_REQUEST_QUERY_STRING)).setVStr("some-query-str=v1")).addTags(KeyValue.newBuilder().setKey(RawSpanConstants.getValue(HTTP_PATH)).setVStr("/some-test-path")).build();
rawSpan = normalizer.convert("tenant-key", span, buildEvent("tenant-key", span, Optional.empty()));
// now, we are not populating first class fields. So, it should be null.
assertNull(rawSpan.getEvent().getHttp());
assertEquals("http", HttpSemanticConventionUtils.getHttpScheme(rawSpan.getEvent()).get());
assertEquals("example.ai:9000", HttpSemanticConventionUtils.getHttpHost(rawSpan.getEvent()).get());
assertEquals("/some-test-path", HttpSemanticConventionUtils.getHttpPath(rawSpan.getEvent()).get());
assertEquals("some-query-str=v1", HttpSemanticConventionUtils.getHttpQueryString(rawSpan.getEvent()).get());
}
Aggregations