use of com.amazon.dataprepper.plugins.processor.oteltracegroup.model.TraceGroup in project data-prepper by opensearch-project.
the class EndToEndRawSpanTest method getExpectedEsDocumentSource.
private Map<String, Object> getExpectedEsDocumentSource(final Span span, final String serviceName) {
final Map<String, Object> esDocSource = new HashMap<>();
final String traceId = Hex.toHexString(span.getTraceId().toByteArray());
esDocSource.put("traceId", traceId);
esDocSource.put("spanId", Hex.toHexString(span.getSpanId().toByteArray()));
esDocSource.put("parentSpanId", Hex.toHexString(span.getParentSpanId().toByteArray()));
esDocSource.put("name", span.getName());
esDocSource.put("kind", span.getKind().name());
esDocSource.put("status.code", span.getStatus().getCodeValue());
esDocSource.put("serviceName", serviceName);
final TraceGroup traceGroup = TEST_TRACEID_TO_TRACE_GROUP.get(traceId);
esDocSource.put(TraceGroup.TRACE_GROUP_NAME_FIELD, traceGroup.getTraceGroup());
esDocSource.put(TraceGroup.TRACE_GROUP_END_TIME_FIELD, traceGroup.getTraceGroupFields().getEndTime());
esDocSource.put(TraceGroup.TRACE_GROUP_DURATION_IN_NANOS_FIELD, traceGroup.getTraceGroupFields().getDurationInNanos());
esDocSource.put(TraceGroup.TRACE_GROUP_STATUS_CODE_FIELD, traceGroup.getTraceGroupFields().getStatusCode());
return esDocSource;
}
use of com.amazon.dataprepper.plugins.processor.oteltracegroup.model.TraceGroup in project data-prepper by opensearch-project.
the class OTelTraceGroupProcessor method doExecute.
@Override
public Collection<Record<Span>> doExecute(final Collection<Record<Span>> rawSpanRecords) {
final List<Record<Span>> recordsOut = new LinkedList<>();
final Set<Record<Span>> recordsMissingTraceGroupInfo = new HashSet<>();
final Set<String> traceIdsToLookUp = new HashSet<>();
for (Record<Span> record : rawSpanRecords) {
final Span span = record.getData();
final String traceGroup = span.getTraceGroup();
final String traceId = span.getTraceId();
if (Strings.isNullOrEmpty(traceGroup)) {
traceIdsToLookUp.add(traceId);
recordsMissingTraceGroupInfo.add(record);
recordsInMissingTraceGroupCounter.increment();
} else {
recordsOut.add(record);
}
}
final Map<String, TraceGroup> traceIdToTraceGroup = searchTraceGroupByTraceIds(traceIdsToLookUp);
for (final Record<Span> record : recordsMissingTraceGroupInfo) {
final Span span = record.getData();
final String traceId = span.getTraceId();
final TraceGroup traceGroup = traceIdToTraceGroup.get(traceId);
if (traceGroup != null) {
try {
fillInTraceGroupInfo(span, traceGroup);
recordsOut.add(record);
recordsOutFixedTraceGroupCounter.increment();
} catch (Exception e) {
recordsOut.add(record);
recordsOutMissingTraceGroupCounter.increment();
LOG.error("Failed to process the span: [{}]", record.getData(), e);
}
} else {
recordsOut.add(record);
recordsOutMissingTraceGroupCounter.increment();
final String spanId = span.getSpanId();
LOG.warn("Failed to find traceGroup for spanId: {} due to traceGroup missing for traceId: {}", spanId, traceId);
}
}
return recordsOut;
}
use of com.amazon.dataprepper.plugins.processor.oteltracegroup.model.TraceGroup in project data-prepper by opensearch-project.
the class OTelTraceGroupProcessor method fromSearchHitToMapEntry.
private Optional<Map.Entry<String, TraceGroup>> fromSearchHitToMapEntry(final SearchHit searchHit) {
final DocumentField traceIdDocField = searchHit.field(OTelTraceGroupProcessorConfig.TRACE_ID_FIELD);
final DocumentField traceGroupNameDocField = searchHit.field(TraceGroup.TRACE_GROUP_NAME_FIELD);
final DocumentField traceGroupEndTimeDocField = searchHit.field(TraceGroup.TRACE_GROUP_END_TIME_FIELD);
final DocumentField traceGroupDurationInNanosDocField = searchHit.field(TraceGroup.TRACE_GROUP_DURATION_IN_NANOS_FIELD);
final DocumentField traceGroupStatusCodeDocField = searchHit.field(TraceGroup.TRACE_GROUP_STATUS_CODE_FIELD);
if (Stream.of(traceIdDocField, traceGroupNameDocField, traceGroupEndTimeDocField, traceGroupDurationInNanosDocField, traceGroupStatusCodeDocField).allMatch(Objects::nonNull)) {
final String traceId = traceIdDocField.getValue();
final String traceGroupName = traceGroupNameDocField.getValue();
final String traceGroupEndTime = normalizeDateTime(traceGroupEndTimeDocField.getValue());
final Number traceGroupDurationInNanos = traceGroupDurationInNanosDocField.getValue();
final Number traceGroupStatusCode = traceGroupStatusCodeDocField.getValue();
final TraceGroupFields traceGroupFields = DefaultTraceGroupFields.builder().withEndTime(traceGroupEndTime).withDurationInNanos(traceGroupDurationInNanos.longValue()).withStatusCode(traceGroupStatusCode.intValue()).build();
final TraceGroup traceGroup = new TraceGroup.TraceGroupBuilder().setTraceGroup(traceGroupName).setTraceGroupFields(traceGroupFields).build();
return Optional.of(new AbstractMap.SimpleEntry<>(traceId, traceGroup));
}
return Optional.empty();
}
use of com.amazon.dataprepper.plugins.processor.oteltracegroup.model.TraceGroup in project data-prepper by opensearch-project.
the class OTelTraceGroupProcessor method searchTraceGroupByTraceIds.
private Map<String, TraceGroup> searchTraceGroupByTraceIds(final Collection<String> traceIds) {
final Map<String, TraceGroup> traceIdToTraceGroup = new HashMap<>();
final SearchRequest searchRequest = createSearchRequest(traceIds);
try {
final SearchResponse searchResponse = restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);
final SearchHit[] searchHits = searchResponse.getHits().getHits();
Arrays.asList(searchHits).forEach(searchHit -> {
final Optional<Map.Entry<String, TraceGroup>> optionalStringTraceGroupEntry = fromSearchHitToMapEntry(searchHit);
optionalStringTraceGroupEntry.ifPresent(entry -> traceIdToTraceGroup.put(entry.getKey(), entry.getValue()));
});
} catch (Exception e) {
// TODO: retry for status code 429 of OpenSearchException?
LOG.error("Search request for traceGroup failed for traceIds: {} due to {}", traceIds, e.getMessage());
}
return traceIdToTraceGroup;
}
Aggregations