diff --git a/data-prepper-plugins/aggregate-processor/src/main/java/org/opensearch/dataprepper/plugins/processor/aggregate/actions/CountAggregateAction.java b/data-prepper-plugins/aggregate-processor/src/main/java/org/opensearch/dataprepper/plugins/processor/aggregate/actions/CountAggregateAction.java index 327d6101ee..382d1cc99b 100644 --- a/data-prepper-plugins/aggregate-processor/src/main/java/org/opensearch/dataprepper/plugins/processor/aggregate/actions/CountAggregateAction.java +++ b/data-prepper-plugins/aggregate-processor/src/main/java/org/opensearch/dataprepper/plugins/processor/aggregate/actions/CountAggregateAction.java @@ -13,6 +13,7 @@ import org.opensearch.dataprepper.plugins.otel.codec.OTelProtoCodec; import org.opensearch.dataprepper.model.event.Event; import org.opensearch.dataprepper.model.event.JacksonEvent; +import org.opensearch.dataprepper.model.trace.Span; import org.opensearch.dataprepper.plugins.processor.aggregate.AggregateAction; import org.opensearch.dataprepper.plugins.processor.aggregate.AggregateActionInput; import org.opensearch.dataprepper.plugins.processor.aggregate.AggregateActionOutput; @@ -64,11 +65,18 @@ private long getTimeNanos(Instant time) { public Exemplar createExemplar(final Event event) { long curTimeNanos = getTimeNanos(Instant.now()); Map attributes = event.toMap(); + String spanId = null; + String traceId = null; + if (event instanceof Span) { + Span span = (Span)event; + spanId = span.getSpanId(); + traceId = span.getTraceId(); + } return new DefaultExemplar( OTelProtoCodec.convertUnixNanosToISO8601(curTimeNanos), 1.0, - event.get("spanId", String.class), // maybe null - event.get("traceId", String.class), // maybe null + spanId, + traceId, attributes); } diff --git a/data-prepper-plugins/aggregate-processor/src/main/java/org/opensearch/dataprepper/plugins/processor/aggregate/actions/HistogramAggregateAction.java b/data-prepper-plugins/aggregate-processor/src/main/java/org/opensearch/dataprepper/plugins/processor/aggregate/actions/HistogramAggregateAction.java index 33cadcc483..6db82130ea 100644 --- a/data-prepper-plugins/aggregate-processor/src/main/java/org/opensearch/dataprepper/plugins/processor/aggregate/actions/HistogramAggregateAction.java +++ b/data-prepper-plugins/aggregate-processor/src/main/java/org/opensearch/dataprepper/plugins/processor/aggregate/actions/HistogramAggregateAction.java @@ -8,6 +8,7 @@ import org.opensearch.dataprepper.model.metric.JacksonHistogram; import org.opensearch.dataprepper.model.metric.Bucket; import org.opensearch.dataprepper.model.metric.Exemplar; +import org.opensearch.dataprepper.model.trace.Span; import org.opensearch.dataprepper.model.metric.DefaultExemplar; import org.opensearch.dataprepper.model.annotations.DataPrepperPlugin; import org.opensearch.dataprepper.model.annotations.DataPrepperPluginConstructor; @@ -114,12 +115,19 @@ public Exemplar createExemplar(final String id, final Event event, double value) long curTimeNanos = getTimeNanos(Instant.now()); Map attributes = event.toMap(); if (Objects.nonNull(id)) { - attributes.put("exemplar_id", id); + attributes.put("exemplarId", id); + } + String spanId = null; + String traceId = null; + if (event instanceof Span) { + Span span = (Span)event; + spanId = span.getSpanId(); + traceId = span.getTraceId(); } return new DefaultExemplar(OTelProtoCodec.convertUnixNanosToISO8601(curTimeNanos), value, - event.get("spanId", String.class), // maybe null - event.get("traceId", String.class), // maybe null + spanId, + traceId, attributes); }