use of org.hypertrace.core.datamodel.RawSpan in project hypertrace-ingester by hypertrace.
the class ByPassPredicateTest method testByPassPredicateWhenKeyIsNotDefined.
@Test
void testByPassPredicateWhenKeyIsNotDefined() {
Config jobConfig = ConfigFactory.parseMap(Map.of());
ByPassPredicate byPassPredicateUnderTest = new ByPassPredicate(jobConfig);
TraceIdentity traceIdentity = TraceIdentity.newBuilder().setTenantId(CUSTOMER_ID).setTraceId(ByteBuffer.wrap("trace-2".getBytes())).build();
ByteBuffer span1 = ByteBuffer.wrap("span-1".getBytes());
ByteBuffer span2 = ByteBuffer.wrap("span-2".getBytes());
// tags won't matter as bypass.key is not defined
RawSpan rawSpan = RawSpan.newBuilder().setCustomerId(CUSTOMER_ID).setTraceId(traceIdentity.getTraceId()).setEvent(Event.newBuilder().setCustomerId(CUSTOMER_ID).setEventId(span1).setAttributes(Attributes.newBuilder().setAttributeMap(Map.of("test.bypass", AttributeValue.newBuilder().setValue("true").build())).build()).build()).build();
Assertions.assertFalse(byPassPredicateUnderTest.test(traceIdentity, rawSpan));
// tags won't matter as bypass.key is not defined
rawSpan = RawSpan.newBuilder().setCustomerId(CUSTOMER_ID).setTraceId(traceIdentity.getTraceId()).setEvent(Event.newBuilder().setCustomerId(CUSTOMER_ID).setEventId(span2).setAttributes(Attributes.newBuilder().setAttributeMap(Map.of("test.bypass", AttributeValue.newBuilder().setValue("false").build())).build()).build()).build();
Assertions.assertFalse(byPassPredicateUnderTest.test(traceIdentity, rawSpan));
}
use of org.hypertrace.core.datamodel.RawSpan in project hypertrace-ingester by hypertrace.
the class JaegerSpanToAvroRawSpanTransformer method transform.
@Override
public KeyValue<TraceIdentity, RawSpan> transform(byte[] key, PreProcessedSpan preProcessedSpan) {
Span value = preProcessedSpan.getSpan();
String tenantId = preProcessedSpan.getTenantId();
try {
RawSpan rawSpan = converter.convert(tenantId, value, preProcessedSpan.getEvent());
if (null != rawSpan) {
// these are spans per tenant that we were able to parse / convert, and had tenantId.
tenantToSpanReceivedCount.computeIfAbsent(tenantId, tenant -> PlatformMetricsRegistry.registerCounter(VALID_SPAN_RECEIVED_COUNT, Map.of("tenantId", tenantId))).increment();
// we use the (tenant_id, trace_id) as the key so that raw_span_grouper
// job can do a groupByKey without having to create a repartition topic
TraceIdentity traceIdentity = fastNewBuilder(TraceIdentity.Builder.class).setTenantId(tenantId).setTraceId(rawSpan.getTraceId()).build();
return new KeyValue<>(traceIdentity, rawSpan);
}
statusToSpansCounter.computeIfAbsent("dropped", k -> PlatformMetricsRegistry.registerCounter(SPANS_COUNTER, Map.of("result", k))).increment();
return null;
} catch (Exception e) {
LOGGER.error("Error converting spans - ", e);
statusToSpansCounter.computeIfAbsent("error", k -> PlatformMetricsRegistry.registerCounter(SPANS_COUNTER, Map.of("result", k))).increment();
return null;
}
}
use of org.hypertrace.core.datamodel.RawSpan in project hypertrace-ingester by hypertrace.
the class JaegerSpanNormalizerTest method testServiceNameAddedToEvent.
@Test
public void testServiceNameAddedToEvent() throws Exception {
String tenantId = "tenant-" + random.nextLong();
Map<String, Object> configs = new HashMap<>(getCommonConfig());
configs.putAll(Map.of("processor", Map.of("defaultTenantId", tenantId)));
JaegerSpanNormalizer normalizer = JaegerSpanNormalizer.get(ConfigFactory.parseMap(configs));
Process process = Process.newBuilder().setServiceName("testService").build();
Span span = Span.newBuilder().setProcess(process).build();
RawSpan rawSpan = normalizer.convert(tenantId, span, buildEvent(tenantId, span, Optional.empty()));
Assertions.assertEquals("testService", rawSpan.getEvent().getServiceName());
Assertions.assertEquals("testService", rawSpan.getEvent().getAttributes().getAttributeMap().get(RawSpanConstants.getValue(JaegerAttribute.JAEGER_ATTRIBUTE_SERVICE_NAME)).getValue());
/**
* the case when `jaegerSpan.getProcess().getServiceName()` is not populated but serviceName is
* sent for key `jaeger.serviceName`
*/
span = Span.newBuilder().addTags(KeyValue.newBuilder().setKey(JaegerSpanNormalizer.OLD_JAEGER_SERVICENAME_KEY).setVStr("testService")).addTags(KeyValue.newBuilder().setKey(RawSpanConstants.getValue(HTTP_REQUEST_METHOD)).setVStr("GET")).build();
rawSpan = normalizer.convert("tenant-key", span, buildEvent(tenantId, span, Optional.empty()));
Assertions.assertEquals("testService", rawSpan.getEvent().getServiceName());
Assertions.assertEquals("testService", rawSpan.getEvent().getAttributes().getAttributeMap().get(RawSpanConstants.getValue(JaegerAttribute.JAEGER_ATTRIBUTE_SERVICE_NAME)).getValue());
/**
* the case when neither `jaegerSpan.getProcess().getServiceName()` nor `jaeger.serviceName` is
* present in tag map
*/
span = Span.newBuilder().addTags(KeyValue.newBuilder().setKey("someKey").setVStr("someValue")).build();
rawSpan = normalizer.convert("tenant-key", span, buildEvent(tenantId, span, Optional.empty()));
Assertions.assertNull(rawSpan.getEvent().getServiceName());
Assertions.assertNotNull(rawSpan.getEvent().getAttributes().getAttributeMap());
Assertions.assertNull(rawSpan.getEvent().getAttributes().getAttributeMap().get(RawSpanConstants.getValue(JaegerAttribute.JAEGER_ATTRIBUTE_SERVICE_NAME)));
}
Aggregations