Search in sources :

Example 11 with RawSpan

use of org.hypertrace.core.datamodel.RawSpan in project hypertrace-ingester by hypertrace.

the class MigrationTestRpc method testRpcFieldsGrpcSystem.

@Test
public void testRpcFieldsGrpcSystem() throws Exception {
    Map<String, String> tagMap = Map.of(OTEL_SPAN_TAG_RPC_SYSTEM.getValue(), "grpc", RPC_REQUEST_METADATA_AUTHORITY.getValue(), "testservice:45", RPC_REQUEST_METADATA_USER_AGENT.getValue(), "grpc-go/1.17.0");
    Span span = createSpanFromTags(tagMap);
    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().getGrpc());
    assertAll(() -> assertEquals("testservice:45", RpcSemanticConventionUtils.getGrpcAuthority(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 12 with RawSpan

use of org.hypertrace.core.datamodel.RawSpan in project hypertrace-ingester by hypertrace.

the class MigrationTestHttp method testPopulateOtherFieldsOTelSpan.

@Test
public void testPopulateOtherFieldsOTelSpan() throws Exception {
    Span span = Span.newBuilder().build();
    RawSpan rawSpan = normalizer.convert("tenant-key", span, buildEvent("tenant-key", span, Optional.empty()));
    assertFalse(HttpSemanticConventionUtils.getHttpUrl(rawSpan.getEvent()).isPresent());
    assertFalse(HttpSemanticConventionUtils.getHttpScheme(rawSpan.getEvent()).isPresent());
    assertFalse(HttpSemanticConventionUtils.getHttpHost(rawSpan.getEvent()).isPresent());
    assertFalse(HttpSemanticConventionUtils.getHttpPath(rawSpan.getEvent()).isPresent());
    assertFalse(HttpSemanticConventionUtils.getHttpQueryString(rawSpan.getEvent()).isPresent());
    span = Span.newBuilder().addTags(KeyValue.newBuilder().setKey(OTelHttpSemanticConventions.HTTP_URL.getValue()).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("example.ai", HttpSemanticConventionUtils.getHttpHost(rawSpan.getEvent()).get());
    assertEquals("a1=v1&a2=v2", HttpSemanticConventionUtils.getHttpQueryString(rawSpan.getEvent()).get());
    assertEquals("/apis/5673/events", HttpSemanticConventionUtils.getHttpPath(rawSpan.getEvent()).get());
    assertEquals("https", HttpSemanticConventionUtils.getHttpScheme(rawSpan.getEvent()).get());
    // Removes the trailing "/" for path
    span = Span.newBuilder().addTags(KeyValue.newBuilder().setKey(OTelHttpSemanticConventions.HTTP_URL.getValue()).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("example.ai", HttpSemanticConventionUtils.getHttpHost(rawSpan.getEvent()).get());
    assertEquals("a1=v1&a2=v2", HttpSemanticConventionUtils.getHttpQueryString(rawSpan.getEvent()).get());
    assertEquals("/apis/5673/events", HttpSemanticConventionUtils.getHttpPath(rawSpan.getEvent()).get());
    assertEquals("https", HttpSemanticConventionUtils.getHttpScheme(rawSpan.getEvent()).get());
    // No query
    span = Span.newBuilder().addTags(KeyValue.newBuilder().setKey(OTelHttpSemanticConventions.HTTP_URL.getValue()).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("example.ai", HttpSemanticConventionUtils.getHttpHost(rawSpan.getEvent()).get());
    assertEquals("/apis/5673/events", HttpSemanticConventionUtils.getHttpPath(rawSpan.getEvent()).get());
    assertEquals("https", HttpSemanticConventionUtils.getHttpScheme(rawSpan.getEvent()).get());
    assertFalse(HttpSemanticConventionUtils.getHttpQueryString(rawSpan.getEvent()).isPresent());
    // No path
    span = Span.newBuilder().addTags(KeyValue.newBuilder().setKey(OTelHttpSemanticConventions.HTTP_URL.getValue()).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("example.ai", HttpSemanticConventionUtils.getHttpHost(rawSpan.getEvent()).get());
    assertEquals("/", HttpSemanticConventionUtils.getHttpPath(rawSpan.getEvent()).get());
    assertEquals("https", HttpSemanticConventionUtils.getHttpScheme(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(OTelHttpSemanticConventions.HTTP_URL.getValue()).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("/apis/5673/events", HttpSemanticConventionUtils.getHttpPath(rawSpan.getEvent()).get());
    assertEquals("a1=v1&a2=v2", HttpSemanticConventionUtils.getHttpQueryString(rawSpan.getEvent()).get());
    // "/" home path, host with port
    span = Span.newBuilder().addTags(KeyValue.newBuilder().setKey(OTelHttpSemanticConventions.HTTP_URL.getValue()).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("example.ai:9000", HttpSemanticConventionUtils.getHttpHost(rawSpan.getEvent()).get());
    assertEquals("/", HttpSemanticConventionUtils.getHttpPath(rawSpan.getEvent()).get());
    assertEquals("http", HttpSemanticConventionUtils.getHttpScheme(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(OTelHttpSemanticConventions.HTTP_URL.getValue()).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(OTelHttpSemanticConventions.HTTP_TARGET.getValue()).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("example.ai:9000", HttpSemanticConventionUtils.getHttpHost(rawSpan.getEvent()).get());
    assertEquals("/some-test-path", HttpSemanticConventionUtils.getHttpPath(rawSpan.getEvent()).get());
    assertEquals("http", HttpSemanticConventionUtils.getHttpScheme(rawSpan.getEvent()).get());
    assertEquals("some-query-str=v1", HttpSemanticConventionUtils.getHttpQueryString(rawSpan.getEvent()).get());
    // originally set url is a relative url, should be overridden
    span = Span.newBuilder().addTags(KeyValue.newBuilder().setKey(OTelHttpSemanticConventions.HTTP_SCHEME.getValue()).setVStr("http")).addTags(KeyValue.newBuilder().setKey(OTelSpanSemanticConventions.SPAN_KIND.getValue()).setVStr("server")).addTags(KeyValue.newBuilder().setKey(OTelHttpSemanticConventions.HTTP_NET_HOST_NAME.getValue()).setVStr("example.internal.com")).addTags(KeyValue.newBuilder().setKey(OTelHttpSemanticConventions.HTTP_NET_HOST_PORT.getValue()).setVStr("50850")).addTags(KeyValue.newBuilder().setKey(OTelHttpSemanticConventions.HTTP_TARGET.getValue()).setVStr("/api/v1/gatekeeper/check?url=%2Fpixel%2Factivities%3Fadvertisable%3DTRHRT&method=GET&service=pixel")).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(HttpSemanticConventionUtils.getHttpUrl(rawSpan.getEvent()).get(), "http://example.internal.com:50850/api/v1/gatekeeper/check?url=%2Fpixel%2Factivities%3Fadvertisable%3DTRHRT&method=GET&service=pixel");
}
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 13 with RawSpan

use of org.hypertrace.core.datamodel.RawSpan in project hypertrace-ingester by hypertrace.

the class MigrationTestHttp method testRequestSizeTagKeysPriority.

@ParameterizedTest
@MethodSource("provideMapForTestingRequestSizeTagKeysPriority")
public void testRequestSizeTagKeysPriority(Map<String, String> tagsMap, int requestSize) 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(requestSize, HttpSemanticConventionUtils.getHttpRequestSize(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 14 with RawSpan

use of org.hypertrace.core.datamodel.RawSpan in project hypertrace-ingester by hypertrace.

the class MigrationTestHttp method testResponseSizeTagKeysPriority.

@ParameterizedTest
@MethodSource("provideMapForTestingResponseSizeTagKeysPriority")
public void testResponseSizeTagKeysPriority(Map<String, String> tagsMap, int responseSize) 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(responseSize, HttpSemanticConventionUtils.getHttpResponseSize(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 15 with RawSpan

use of org.hypertrace.core.datamodel.RawSpan in project hypertrace-ingester by hypertrace.

the class MigrationTestHttp method testRelativeUrlNotSetsUrlField.

@Test
public void testRelativeUrlNotSetsUrlField() throws Exception {
    Span span = createSpanFromTags(Map.of(RawSpanConstants.getValue(HTTP_URL), "/dispatch/test?a=b&k1=v1"));
    RawSpan rawSpan = normalizer.convert("tenant-key", span, buildEvent("tenant-key", span, Optional.empty()));
    assertFalse(HttpSemanticConventionUtils.getHttpUrl(rawSpan.getEvent()).isPresent());
}
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