private void export() {
    if (exportRpcHandler == null || exportRpcHandler.isCompleted()) {
      return;
    }

    ArrayList<Metric> metricsList = Lists.newArrayList();
    for (MetricProducer metricProducer : metricProducerManager.getAllMetricProducer()) {
      metricsList.addAll(metricProducer.getMetrics());
    }

    List<io.opencensus.proto.metrics.v1.Metric> metricProtos = Lists.newArrayList();
    for (Metric metric : metricsList) {
      // TODO(songya): determine if we should make the optimization on not sending already-existed
      // MetricDescriptors.
      // boolean registered = true;
      // if (!registeredDescriptors.contains(metric.getMetricDescriptor())) {
      //   registered = false;
      //   registeredDescriptors.add(metric.getMetricDescriptor());
      // }
      metricProtos.add(MetricsProtoUtils.toMetricProto(metric, null));
    }

    exportRpcHandler.onExport(
        // For now don't include Resource in the following messages, i.e don't allow Resource to
        // mutate after the initial message.
        ExportMetricsServiceRequest.newBuilder().addAllMetrics(metricProtos).build());
  }
private void export ( ) { if ( exportRpcHandler == null || exportRpcHandler . isCompleted ( ) ) { return ; } ArrayList < Metric > metricsList = Lists . newArrayList ( ) ; for ( MetricProducer metricProducer : metricProducerManager . getAllMetricProducer ( ) ) { metricsList . addAll ( metricProducer . getMetrics ( ) ) ; } List < io . opencensus . proto . metrics . v1 . Metric > metricProtos = Lists . newArrayList ( ) ; for ( Metric metric : metricsList ) { metricProtos . add ( MetricsProtoUtils . toMetricProto ( metric , null ) ) ; } exportRpcHandler . onExport ( ExportMetricsServiceRequest . newBuilder ( ) . addAllMetrics ( metricProtos ) . build ( ) ) ; }
converts them to proto, then exports them to OC-Agent.