Search in sources :

Example 26 with RawSpan

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()));
}
Also used : RawSpan(org.hypertrace.core.datamodel.RawSpan) Span(io.jaegertracing.api_v2.JaegerSpanInternalModel.Span) RawSpan(org.hypertrace.core.datamodel.RawSpan) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 27 with RawSpan

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());
}
Also used : RawSpan(org.hypertrace.core.datamodel.RawSpan) Span(io.jaegertracing.api_v2.JaegerSpanInternalModel.Span) RawSpan(org.hypertrace.core.datamodel.RawSpan) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 28 with RawSpan

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());
}
Also used : RawSpan(org.hypertrace.core.datamodel.RawSpan) Span(io.jaegertracing.api_v2.JaegerSpanInternalModel.Span) RawSpan(org.hypertrace.core.datamodel.RawSpan) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 29 with RawSpan

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());
}
Also used : RawSpan(org.hypertrace.core.datamodel.RawSpan) Span(io.jaegertracing.api_v2.JaegerSpanInternalModel.Span) RawSpan(org.hypertrace.core.datamodel.RawSpan) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 30 with RawSpan

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());
}
Also used : RawSpan(org.hypertrace.core.datamodel.RawSpan) Span(io.jaegertracing.api_v2.JaegerSpanInternalModel.Span) RawSpan(org.hypertrace.core.datamodel.RawSpan) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

RawSpan (org.hypertrace.core.datamodel.RawSpan)43 Span (io.jaegertracing.api_v2.JaegerSpanInternalModel.Span)33 Test (org.junit.jupiter.api.Test)25 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)25 HashMap (java.util.HashMap)14 Config (com.typesafe.config.Config)12 TraceIdentity (org.hypertrace.core.spannormalizer.TraceIdentity)9 MethodSource (org.junit.jupiter.params.provider.MethodSource)9 StructuredTrace (org.hypertrace.core.datamodel.StructuredTrace)6 ByteBuffer (java.nio.ByteBuffer)5 Map (java.util.Map)5 Properties (java.util.Properties)5 StreamsBuilder (org.apache.kafka.streams.StreamsBuilder)5 TestOutputTopic (org.apache.kafka.streams.TestOutputTopic)5 TopologyTestDriver (org.apache.kafka.streams.TopologyTestDriver)5 JaegerSpanSerde (org.hypertrace.core.spannormalizer.jaeger.JaegerSpanSerde)5 SetEnvironmentVariable (org.junitpioneer.jupiter.SetEnvironmentVariable)5 ByteString (com.google.protobuf.ByteString)4 Counter (io.micrometer.core.instrument.Counter)4 Instant (java.time.Instant)4