public static final TagKey GRPC_CLIENT_METHOD = TagKey.create("grpc_client_method"); public static final MeasureDouble GRPC_CLIENT_RECEIVED_BYTES_PER_METHOD =
    Measure.MeasureDouble.create(
        "grpc.io/client/received_bytes_per_method",
        "Total bytes received per method, recorded real-time as bytes are received.",
        BYTE); public static final MeasureDouble GRPC_CLIENT_RECEIVED_BYTES_PER_RPC =
    Measure.MeasureDouble.create(
        "grpc.io/client/received_bytes_per_rpc",
        "Total bytes received across all response messages per RPC",
        BYTE); public static final MeasureLong GRPC_CLIENT_RECEIVED_MESSAGES_PER_METHOD =
    Measure.MeasureLong.create(
        "grpc.io/client/received_messages_per_method",
        "Total messages received per method.",
        COUNT); public static final MeasureLong GRPC_CLIENT_RECEIVED_MESSAGES_PER_RPC =
    Measure.MeasureLong.create(
        "grpc.io/client/received_messages_per_rpc",
        "Number of response messages received per RPC",
        COUNT); public static final MeasureLong GRPC_CLIENT_RETRIES_PER_CALL =
    Measure.MeasureLong.create(
        "grpc.io/client/retries_per_call", "Number of retries per call", COUNT); public static final MeasureDouble GRPC_CLIENT_RETRY_DELAY_PER_CALL =
    Measure.MeasureDouble.create(
        "grpc.io/client/retry_delay_per_call", "Retry delay per call", MILLISECOND); public static final MeasureDouble GRPC_CLIENT_ROUNDTRIP_LATENCY =
    Measure.MeasureDouble.create(
        "grpc.io/client/roundtrip_latency",
        "Time between first byte of request sent to last byte of response received, "
            + "or terminal error.",
        MILLISECOND); public static final MeasureDouble GRPC_CLIENT_SENT_BYTES_PER_METHOD =
    Measure.MeasureDouble.create(
        "grpc.io/client/sent_bytes_per_method",
        "Total bytes sent per method, recorded real-time as bytes are sent.",
        BYTE); public static final MeasureDouble GRPC_CLIENT_SENT_BYTES_PER_RPC =
    Measure.MeasureDouble.create(
        "grpc.io/client/sent_bytes_per_rpc",
        "Total bytes sent across all request messages per RPC",
        BYTE); public static final MeasureLong GRPC_CLIENT_SENT_MESSAGES_PER_METHOD =
    Measure.MeasureLong.create(
        "grpc.io/client/sent_messages_per_method", "Total messages sent per method.", COUNT); public static final MeasureLong GRPC_CLIENT_SENT_MESSAGES_PER_RPC =
    Measure.MeasureLong.create(
        "grpc.io/client/sent_messages_per_rpc", "Number of messages sent in the RPC", COUNT); public static final MeasureDouble GRPC_CLIENT_SERVER_LATENCY =
    Measure.MeasureDouble.create(
        "grpc.io/client/server_latency", "Server latency in msecs", MILLISECOND); public static final MeasureLong GRPC_CLIENT_STARTED_RPCS =
    Measure.MeasureLong.create(
        "grpc.io/client/started_rpcs", "Number of started client RPCs.", COUNT); public static final TagKey GRPC_CLIENT_STATUS = TagKey.create("grpc_client_status"); public static final MeasureLong GRPC_CLIENT_TRANSPARENT_RETRIES_PER_CALL =
    Measure.MeasureLong.create(
        "grpc.io/client/transparent_retries_per_call", "Transparent retries per call", COUNT); public static final TagKey GRPC_SERVER_METHOD = TagKey.create("grpc_server_method"); public static final MeasureDouble GRPC_SERVER_RECEIVED_BYTES_PER_METHOD =
    Measure.MeasureDouble.create(
        "grpc.io/server/received_bytes_per_method",
        "Total bytes received per method, recorded real-time as bytes are received.",
        BYTE); public static final MeasureDouble GRPC_SERVER_RECEIVED_BYTES_PER_RPC =
    Measure.MeasureDouble.create(
        "grpc.io/server/received_bytes_per_rpc",
        "Total bytes received across all messages per RPC",
        BYTE); public static final MeasureLong GRPC_SERVER_RECEIVED_MESSAGES_PER_METHOD =
    Measure.MeasureLong.create(
        "grpc.io/server/received_messages_per_method",
        "Total messages received per method.",
        COUNT); public static final MeasureLong GRPC_SERVER_RECEIVED_MESSAGES_PER_RPC =
    Measure.MeasureLong.create(
        "grpc.io/server/received_messages_per_rpc",
        "Number of messages received in each RPC",
        COUNT); public static final MeasureDouble GRPC_SERVER_SENT_BYTES_PER_METHOD =
    Measure.MeasureDouble.create(
        "grpc.io/server/sent_bytes_per_method",
        "Total bytes sent per method, recorded real-time as bytes are sent.",
        BYTE); public static final MeasureDouble GRPC_SERVER_SENT_BYTES_PER_RPC =
    Measure.MeasureDouble.create(
        "grpc.io/server/sent_bytes_per_rpc",
        "Total bytes sent across all response messages per RPC",
        BYTE); public static final MeasureLong GRPC_SERVER_SENT_MESSAGES_PER_METHOD =
    Measure.MeasureLong.create(
        "grpc.io/server/sent_messages_per_method", "Total messages sent per method.", COUNT); public static final MeasureLong GRPC_SERVER_SENT_MESSAGES_PER_RPC =
    Measure.MeasureLong.create(
        "grpc.io/server/sent_messages_per_rpc", "Number of messages sent in each RPC", COUNT); public static final MeasureDouble GRPC_SERVER_SERVER_LATENCY =
    Measure.MeasureDouble.create(
        "grpc.io/server/server_latency",
        "Time between first byte of request received to last byte of response sent, "
            + "or terminal error.",
        MILLISECOND); public static final MeasureLong GRPC_SERVER_STARTED_RPCS =
    Measure.MeasureLong.create(
        "grpc.io/server/started_rpcs", "Number of started server RPCs.", COUNT); public static final TagKey GRPC_SERVER_STATUS = TagKey.create("grpc_server_status"); @Deprecated
public static final MeasureLong RPC_CLIENT_ERROR_COUNT =
    Measure.MeasureLong.create("grpc.io/client/error_count", "RPC Errors", COUNT); @Deprecated
public static final MeasureLong RPC_CLIENT_FINISHED_COUNT =
    Measure.MeasureLong.create(
        "grpc.io/client/finished_count", "Number of client RPCs (streams) finished", COUNT); @Deprecated
public static final MeasureDouble RPC_CLIENT_UNCOMPRESSED_REQUEST_BYTES =
    Measure.MeasureDouble.create(
        "grpc.io/client/uncompressed_request_bytes", "Uncompressed Request bytes", BYTE); @Deprecated
public static final MeasureDouble RPC_CLIENT_UNCOMPRESSED_RESPONSE_BYTES =
    Measure.MeasureDouble.create(
        "grpc.io/client/uncompressed_response_bytes", "Uncompressed Response bytes", BYTE); @Deprecated public static final TagKey RPC_METHOD = TagKey.create("method"); @Deprecated
public static final MeasureLong RPC_SERVER_ERROR_COUNT =
    Measure.MeasureLong.create("grpc.io/server/error_count", "RPC Errors", COUNT); @Deprecated
public static final MeasureLong RPC_SERVER_FINISHED_COUNT =
    Measure.MeasureLong.create(
        "grpc.io/server/finished_count", "Number of server RPCs (streams) finished", COUNT); @Deprecated
public static final MeasureDouble RPC_SERVER_SERVER_ELAPSED_TIME =
    Measure.MeasureDouble.create(
        "grpc.io/server/server_elapsed_time", "Server elapsed time in msecs", MILLISECOND); @Deprecated
public static final MeasureDouble RPC_SERVER_UNCOMPRESSED_REQUEST_BYTES =
    Measure.MeasureDouble.create(
        "grpc.io/server/uncompressed_request_bytes", "Uncompressed Request bytes", BYTE); @Deprecated
public static final MeasureDouble RPC_SERVER_UNCOMPRESSED_RESPONSE_BYTES =
    Measure.MeasureDouble.create(
        "grpc.io/server/uncompressed_response_bytes", "Uncompressed Response bytes", BYTE); @Deprecated public static final TagKey RPC_STATUS = TagKey.create("canonical_status");
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.GRPC_CLIENT_METHOD;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.GRPC_CLIENT_RECEIVED_BYTES_PER_METHOD;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.GRPC_CLIENT_RECEIVED_BYTES_PER_RPC;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.GRPC_CLIENT_RECEIVED_MESSAGES_PER_METHOD;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.GRPC_CLIENT_RECEIVED_MESSAGES_PER_RPC;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.GRPC_CLIENT_RETRIES_PER_CALL;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.GRPC_CLIENT_RETRY_DELAY_PER_CALL;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.GRPC_CLIENT_ROUNDTRIP_LATENCY;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.GRPC_CLIENT_SENT_BYTES_PER_METHOD;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.GRPC_CLIENT_SENT_BYTES_PER_RPC;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.GRPC_CLIENT_SENT_MESSAGES_PER_METHOD;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.GRPC_CLIENT_SENT_MESSAGES_PER_RPC;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.GRPC_CLIENT_SERVER_LATENCY;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.GRPC_CLIENT_STARTED_RPCS;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.GRPC_CLIENT_STATUS;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.GRPC_CLIENT_TRANSPARENT_RETRIES_PER_CALL;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.GRPC_SERVER_METHOD;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.GRPC_SERVER_RECEIVED_BYTES_PER_METHOD;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.GRPC_SERVER_RECEIVED_BYTES_PER_RPC;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.GRPC_SERVER_RECEIVED_MESSAGES_PER_METHOD;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.GRPC_SERVER_RECEIVED_MESSAGES_PER_RPC;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.GRPC_SERVER_SENT_BYTES_PER_METHOD;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.GRPC_SERVER_SENT_BYTES_PER_RPC;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.GRPC_SERVER_SENT_MESSAGES_PER_METHOD;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.GRPC_SERVER_SENT_MESSAGES_PER_RPC;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.GRPC_SERVER_SERVER_LATENCY;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.GRPC_SERVER_STARTED_RPCS;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.GRPC_SERVER_STATUS;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.RPC_CLIENT_ERROR_COUNT;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.RPC_CLIENT_FINISHED_COUNT;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.RPC_CLIENT_REQUEST_BYTES;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.RPC_CLIENT_REQUEST_COUNT;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.RPC_CLIENT_RESPONSE_BYTES;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.RPC_CLIENT_RESPONSE_COUNT;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.RPC_CLIENT_ROUNDTRIP_LATENCY;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.RPC_CLIENT_SERVER_ELAPSED_TIME;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.RPC_CLIENT_STARTED_COUNT;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.RPC_CLIENT_UNCOMPRESSED_REQUEST_BYTES;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.RPC_CLIENT_UNCOMPRESSED_RESPONSE_BYTES;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.RPC_METHOD;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.RPC_SERVER_ERROR_COUNT;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.RPC_SERVER_FINISHED_COUNT;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.RPC_SERVER_REQUEST_BYTES;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.RPC_SERVER_REQUEST_COUNT;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.RPC_SERVER_RESPONSE_BYTES;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.RPC_SERVER_RESPONSE_COUNT;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.RPC_SERVER_SERVER_ELAPSED_TIME;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.RPC_SERVER_SERVER_LATENCY;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.RPC_SERVER_STARTED_COUNT;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.RPC_SERVER_UNCOMPRESSED_REQUEST_BYTES;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.RPC_SERVER_UNCOMPRESSED_RESPONSE_BYTES;
import static io.opencensus.contrib.grpc.metrics.RpcMeasureConstants.RPC_STATUS;
import com.google.common.annotations.VisibleForTesting;
import io.opencensus.common.Duration;
import io.opencensus.stats.Aggregation;
import io.opencensus.stats.Aggregation.Count;
import io.opencensus.stats.Aggregation.Distribution;
import io.opencensus.stats.Aggregation.Sum;
import io.opencensus.stats.BucketBoundaries;
import io.opencensus.stats.View;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
          RPC_CLIENT_UNCOMPRESSED_REQUEST_BYTES,
          AGGREGATION_WITH_BYTES_HISTOGRAM,
          Arrays.asList(RPC_METHOD),
          CUMULATIVE);

  /**
   * Cumulative {@link View} for client uncompressed response bytes.
   *
   * @since 0.8
   * @deprecated in favor of {@link #GRPC_CLIENT_RECEIVED_BYTES_PER_RPC_VIEW}.
   */
  @Deprecated
  public static final View RPC_CLIENT_UNCOMPRESSED_RESPONSE_BYTES_VIEW =
      View.create(
          View.Name.create("grpc.io/client/uncompressed_response_bytes/cumulative"),
          "Uncompressed Response bytes",
          RPC_CLIENT_UNCOMPRESSED_RESPONSE_BYTES,
          AGGREGATION_WITH_BYTES_HISTOGRAM,
          Arrays.asList(RPC_METHOD),
          CUMULATIVE);

  /**
   * Cumulative {@link View} for client request message counts.
   *
   * @since 0.8
   * @deprecated in favor of {@link #GRPC_CLIENT_SENT_MESSAGES_PER_RPC_VIEW}.
   */
  @Deprecated
  public static final View RPC_CLIENT_REQUEST_COUNT_VIEW =
      View.create(
          View.Name.create("grpc.io/client/request_count/cumulative"),
          "Count of request messages per client RPC",
          RPC_CLIENT_REQUEST_COUNT,
          AGGREGATION_WITH_COUNT_HISTOGRAM,
          Arrays.asList(RPC_METHOD),
          CUMULATIVE);

  /**
   * Cumulative {@link View} for client response message counts.
   *
   * @since 0.8
   * @deprecated in favor of {@link #GRPC_CLIENT_RECEIVED_MESSAGES_PER_RPC_VIEW}.
   */
  @Deprecated
  public static final View RPC_CLIENT_RESPONSE_COUNT_VIEW =
      View.create(
          View.Name.create("grpc.io/client/response_count/cumulative"),
          "Count of response messages per client RPC",
          RPC_CLIENT_RESPONSE_COUNT,
          AGGREGATION_WITH_COUNT_HISTOGRAM,
          Arrays.asList(RPC_METHOD),
          CUMULATIVE);

  /**
   * Cumulative {@link View} for started client RPCs.
   *
   * @since 0.12
   * @deprecated in favor of {@link #GRPC_CLIENT_STARTED_RPC_VIEW}.
   */
  @Deprecated
  public static final View RPC_CLIENT_STARTED_COUNT_CUMULATIVE_VIEW =
      View.create(
          View.Name.create("grpc.io/client/started_count/cumulative"),
          "Number of started client RPCs",
          RPC_CLIENT_STARTED_COUNT,
          COUNT,
          Arrays.asList(RPC_METHOD),
          CUMULATIVE);

  /**
   * Cumulative {@link View} for finished client RPCs.
   *
   * @since 0.12
   * @deprecated in favor of {@link #GRPC_CLIENT_COMPLETED_RPC_VIEW}.
   */
  @Deprecated
  public static final View RPC_CLIENT_FINISHED_COUNT_CUMULATIVE_VIEW =
      View.create(
          View.Name.create("grpc.io/client/finished_count/cumulative"),
          "Number of finished client RPCs",
          RPC_CLIENT_FINISHED_COUNT,
          COUNT,
          Arrays.asList(RPC_METHOD),
          CUMULATIVE);

  /**
   * {@link View} for client roundtrip latency in milliseconds.
   *
   * @since 0.13
   */
  public static final View GRPC_CLIENT_ROUNDTRIP_LATENCY_VIEW =
      View.create(
          View.Name.create("grpc.io/client/roundtrip_latency"),
          "Latency in msecs",
          GRPC_CLIENT_ROUNDTRIP_LATENCY,
          AGGREGATION_WITH_MILLIS_HISTOGRAM,
          Arrays.asList(GRPC_CLIENT_METHOD));

  /**
   * {@link View} for client server latency in milliseconds.
   *
   * @since 0.13
   */
  public static final View GRPC_CLIENT_SERVER_LATENCY_VIEW =
      View.create(
          View.Name.create("grpc.io/client/server_latency"),
          "Server latency in msecs",
          GRPC_CLIENT_SERVER_LATENCY,
          AGGREGATION_WITH_MILLIS_HISTOGRAM,
          Arrays.asList(GRPC_CLIENT_METHOD));

  /**
   * {@link View} for client sent bytes per RPC.
   *
   * @since 0.13
   */
  public static final View GRPC_CLIENT_SENT_BYTES_PER_RPC_VIEW =
      View.create(
          View.Name.create("grpc.io/client/sent_bytes_per_rpc"),
          "Sent bytes per RPC",
          GRPC_CLIENT_SENT_BYTES_PER_RPC,