All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.eg.agent.android.harvest.DataValidator Maven / Gradle / Ivy

The newest version!
package com.eg.agent.android.harvest;


import com.eg.agent.android.metric.MetricData;
import com.eg.agent.android.trace.ActivityTracer;
import com.eg.agent.android.trace.TracerMachine;

import java.util.List;

public class DataValidator extends ReaperAdapter {
    public void onHarvestFinalize() {
        if (DataReaper.isInitialized()) {
            ensureActivityNameMetricsExist();
        }
    }

    public void ensureActivityNameMetricsExist() {
        ReapData harvestData = DataReaper.getInstance().getHarvestData();
        Tracer activityTraces = harvestData.getActivityTraces();
        if (activityTraces != null && activityTraces.count() != 0) {
            Metrics metrics = harvestData.getMetrics();
            if (metrics != null && !metrics.isEmpty()) {
                for (ActivityTracer activityTrace : activityTraces.getActivityTraces()) {
                    String activityName = activityTrace.rootTrace.displayName;
                    int hashIndex = activityName.indexOf("#");
                    if (hashIndex > 0) {
                        activityName = activityName.substring(0, hashIndex);
                    }
                    String activityMetricRoot = TracerMachine.ACTIVITY_METRIC_PREFIX + activityName;
                    boolean foundMetricForActivity = false;
                    List unScopedMetrics = metrics.getMetrics().getAllUnscoped();
                    if (unScopedMetrics != null && unScopedMetrics.size() > 0) {
                        for (MetricData metric : unScopedMetrics) {
                            if (metric.getName().startsWith(activityMetricRoot)) {
                                foundMetricForActivity = true;
                                break;
                            }
                        }
                    }
                    if (!foundMetricForActivity) {
                        metrics.addMetric(new MetricData(activityMetricRoot));
                    }
                }
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy