Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.hypertrace.traceenricher.enrichment;

import static org.hypertrace.core.serviceframework.metrics.PlatformMetricsRegistry.registerCounter;
import static org.hypertrace.core.serviceframework.metrics.PlatformMetricsRegistry.registerTimer;
import static org.hypertrace.traceenricher.enrichedspan.constants.EnrichedSpanConstants.DROP_TRACE_ATTRIBUTE;

import com.google.common.util.concurrent.ExecutionError;
Expand All @@ -24,6 +23,7 @@
import org.hypertrace.core.datamodel.StructuredTrace;
import org.hypertrace.core.datamodel.shared.DataflowMetricUtils;
import org.hypertrace.core.datamodel.shared.HexUtils;
import org.hypertrace.core.serviceframework.metrics.PlatformMetricsRegistry;
import org.hypertrace.traceenricher.enrichment.clients.ClientRegistry;
import org.hypertrace.traceenricher.util.AvroToJsonLogger;
import org.slf4j.Logger;
Expand All @@ -34,7 +34,7 @@ public class EnrichmentProcessor {
private static final Logger LOG = LoggerFactory.getLogger(EnrichmentProcessor.class);
private static final String ENRICHMENT_ARRIVAL_TIME = "enrichment.arrival.time";
private static final Timer enrichmentArrivalTimer =
registerTimer(DataflowMetricUtils.ARRIVAL_LAG, new HashMap<>());
PlatformMetricsRegistry.registerTimer(DataflowMetricUtils.ARRIVAL_LAG, new HashMap<>());

// Must use linked hashmap
private final Map<String, Enricher> enrichers = new LinkedHashMap<>();
Expand Down Expand Up @@ -75,25 +75,30 @@ public void process(StructuredTrace trace) {
trace, enrichmentArrivalTimer, ENRICHMENT_ARRIVAL_TIME);
AvroToJsonLogger.log(LOG, "Structured Trace before all the enrichment is: {}", trace);
for (Entry<String, Enricher> entry : enrichers.entrySet()) {
String metricKey = String.format("%s/%s", trace.getCustomerId(), entry.getKey());
String enricherName = entry.getKey();
Map<String, String> metricTags = Map.of("enricher", enricherName);
try {
Instant start = Instant.now();
applyEnricher(entry.getValue(), trace);
long timeElapsed = Duration.between(start, Instant.now()).toMillis();

traceCounters
.computeIfAbsent(metricKey, k -> registerCounter(ENRICHED_TRACES_COUNTER, null))
.computeIfAbsent(
enricherName, k -> registerCounter(ENRICHED_TRACES_COUNTER, metricTags))
.increment();
traceTimers
.computeIfAbsent(metricKey, k -> registerTimer(ENRICHED_TRACES_TIMER, null))
.computeIfAbsent(
enricherName,
k -> PlatformMetricsRegistry.registerTimer(ENRICHED_TRACES_TIMER, metricTags))
.record(timeElapsed, TimeUnit.MILLISECONDS);
} catch (Exception | ExecutionError throwable) {
String errorMessage =
String.format(
"Could not apply the enricher: %s to the trace with traceId: %s",
entry.getKey(), HexUtils.getHex(trace.getTraceId()));
traceErrorsCounters
.computeIfAbsent(metricKey, k -> registerCounter(TRACE_ENRICHMENT_ERRORS_COUNTER, null))
.computeIfAbsent(
enricherName, k -> registerCounter(TRACE_ENRICHMENT_ERRORS_COUNTER, metricTags))
.increment();
LOG.error(errorMessage, throwable);
}
Expand Down