

# Salida de flujos de métricas de CloudWatch en formato OpenTelemetry 0.7.0
<a name="CloudWatch-metric-streams-formats-opentelemetry"></a>

OpenTelemetry es una colección de herramientas, API y SDK. Puede utilizarlo para instrumentar, generar, recopilar y exportar datos telemétricos (métricas, registros y seguimientos) para analizarlos. OpenTelemetry es parte de Cloud Native Computing Foundation. Para obtener más información, consulte [OpenElemetry](https://opentelemetry.io/).

Para obtener información acerca de la especificación completa de OpenTelemetry 0.7.0, consulte [v0.7.0 release](https://github.com/open-telemetry/opentelemetry-proto/releases/tag/v0.7.0) (Versión v0.7.0).

Un registro de Kinesis puede contener una o más estructuras de datos OpenTelemetry `ExportMetricsServiceRequest`. Cada estructura de datos comienza con una cabecera con un `UnsignedVarInt32` que indica la longitud de registro en bytes. Cada `ExportMetricsServiceRequest` puede contener datos de varias métricas a la vez.

A continuación, se muestra una cadena de representación del mensaje de la estructura de datos OpenTelemetry `ExportMetricsServiceRequest`. OpenTelemetry serializa el protocolo binario Google Protocol Buffers y este no es legible para el ser humano.

```
resource_metrics {
  resource {
    attributes {
      key: "cloud.provider"
      value {
        string_value: "aws"
      }
    }
    attributes {
      key: "cloud.account.id"
      value {
        string_value: "2345678901"
      }
    }
    attributes {
      key: "cloud.region"
      value {
        string_value: "us-east-1"
      }
    }
    attributes {
      key: "aws.exporter.arn"
      value {
        string_value: "arn:aws:cloudwatch:us-east-1:123456789012:metric-stream/MyMetricStream"
      }
    }
  }
  instrumentation_library_metrics {
    metrics {
      name: "amazonaws.com/AWS/DynamoDB/ConsumedReadCapacityUnits"
      unit: "1"
      double_summary {
        data_points {
          labels {
            key: "Namespace"
            value: "AWS/DynamoDB"
          }
          labels {
            key: "MetricName"
            value: "ConsumedReadCapacityUnits"
          }
          labels {
            key: "TableName"
            value: "MyTable"
          }
          start_time_unix_nano: 1604948400000000000
          time_unix_nano: 1604948460000000000
          count: 1
          sum: 1.0
          quantile_values {
            quantile: 0.0
            value: 1.0
          }
          quantile_values {
            quantile: 0.95
            value: 1.0
          }          
          quantile_values {
            quantile: 0.99
            value: 1.0
          }
          quantile_values {
            quantile: 1.0
            value: 1.0
          }
        }
        data_points {
          labels {
            key: "Namespace"
            value: "AWS/DynamoDB"
          }
          labels {
            key: "MetricName"
            value: "ConsumedReadCapacityUnits"
          }
          labels {
            key: "TableName"
            value: "MyTable"
          }
          start_time_unix_nano: 1604948460000000000
          time_unix_nano: 1604948520000000000
          count: 2
          sum: 5.0
          quantile_values {
            quantile: 0.0
            value: 2.0
          }
          quantile_values {
            quantile: 1.0
            value: 3.0
          }
        }
      }
    }
  }
}
```

**Objeto de nivel superior para serializar datos de métrica de OpenTelemetry**

`ExportMetricsServiceRequest` es el envoltorio de nivel superior para serializar una carga del exportador de OpenTelemetry. Contiene uno o más `ResourceMetrics`.

```
message ExportMetricsServiceRequest {
  // An array of ResourceMetrics.
  // For data coming from a single resource this array will typically contain one
  // element. Intermediary nodes (such as OpenTelemetry Collector) that receive
  // data from multiple origins typically batch the data before forwarding further and
  // in that case this array will contain multiple elements.
  repeated opentelemetry.proto.metrics.v1.ResourceMetrics resource_metrics = 1;
}
```

`ResourceMetrics` es el objeto de nivel superior para representar objetos MetricData. 

```
// A collection of InstrumentationLibraryMetrics from a Resource.
message ResourceMetrics {
  // The resource for the metrics in this message.
  // If this field is not set then no resource info is known.
  opentelemetry.proto.resource.v1.Resource resource = 1;
  
  // A list of metrics that originate from a resource.
  repeated InstrumentationLibraryMetrics instrumentation_library_metrics = 2;
}
```

**El objeto recurso**

Un objeto `Resource` es un objeto de par de valores que contiene información sobre el recurso que generó las métricas. Para las métricas que AWS crea, la estructura de datos contiene el Nombre de recurso de Amazon (ARN) del recurso relacionado con la métrica, como una instancia EC2 o un bucket de S3.

El objeto `Resource` contiene un atributo llamado `attributes`, que almacena una lista de pares clave-valor.
+ `cloud.account.id` contiene el ID de la cuenta
+ `cloud.region` contiene la Región
+ `aws.exporter.arn` contiene el ARN del flujo métrico
+ `cloud.provider` es siempre `aws`.

```
// Resource information.
message Resource {
  // Set of labels that describe the resource.
  repeated opentelemetry.proto.common.v1.KeyValue attributes = 1;
  
  // dropped_attributes_count is the number of dropped attributes. If the value is 0,
  // no attributes were dropped.
  uint32 dropped_attributes_count = 2;
}
```

**El objeto InstrumentationLibraryMetrics**

El campo instrumentation\_library no se rellenará. Se rellenará sólo el campo de métricas que se está exportando.

```
// A collection of Metrics produced by an InstrumentationLibrary.
message InstrumentationLibraryMetrics {
  // The instrumentation library information for the metrics in this message.
  // If this field is not set then no library info is known.
  opentelemetry.proto.common.v1.InstrumentationLibrary instrumentation_library = 1;
  // A list of metrics that originate from an instrumentation library.
  repeated Metric metrics = 2;
}
```

**El objeto métrica**

El objeto métrica contiene un campo de datos `DoubleSummary` que contiene una lista de `DoubleSummaryDataPoint`.

```
message Metric {
  // name of the metric, including its DNS name prefix. It must be unique.
  string name = 1;

  // description of the metric, which can be used in documentation.
  string description = 2;

  // unit in which the metric value is reported. Follows the format
  // described by http://unitsofmeasure.org/ucum.html.
  string unit = 3;

  oneof data {
    IntGauge int_gauge = 4;
    DoubleGauge double_gauge = 5;
    IntSum int_sum = 6;
    DoubleSum double_sum = 7;
    IntHistogram int_histogram = 8;
    DoubleHistogram double_histogram = 9;
    DoubleSummary double_summary = 11;
  }
}

message DoubleSummary {
  repeated DoubleSummaryDataPoint data_points = 1;
}
```

**El objeto MetricDescriptor**

El objeto MetricDescriptor contiene metadatos. Para obtener más información, consulte [metrics.proto](https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/metrics/v1/metrics.proto#L110) en GitHub.

Para flujos métricos, MetricDescriptor cuenta con el siguiente contenido:
+ `name` será `amazonaws.com/{{metric_namespace}}/{{metric_name}}`
+ `description` estará en blanco.
+ `unit` se rellenará al mapear la unidad del dato métrico a la variante de reconocimiento de mayúsculas y minúsculas del código unificado para unidades de medida. Para obtener más información, consulte [Conversiones con formato OpenTelemetry 0.7.0 en CloudWatch](CloudWatch-metric-streams-formats-opentelemetry-translation.md) y [The Unified Code For Units of Measure](https://ucum.org/ucum.html) (Código unificado para las unidades de medida).
+ `type` será `SUMMARY`.

**El objeto DoubleSummaryDataPoint**

El objeto DoubleSummaryDataPoint contiene el valor de un único punto de datos de una serie temporal en una métrica DoubleSummary.

```
// DoubleSummaryDataPoint is a single data point in a timeseries that describes the
// time-varying values of a Summary metric.
message DoubleSummaryDataPoint {
  // The set of labels that uniquely identify this timeseries.
  repeated opentelemetry.proto.common.v1.StringKeyValue labels = 1;

  // start_time_unix_nano is the last time when the aggregation value was reset
  // to "zero". For some metric types this is ignored, see data types for more
  // details.
  //
  // The aggregation value is over the time interval (start_time_unix_nano,
  // time_unix_nano].
  //
  // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January
  // 1970.
  //
  // Value of 0 indicates that the timestamp is unspecified. In that case the
  // timestamp may be decided by the backend.
  fixed64 start_time_unix_nano = 2;

  // time_unix_nano is the moment when this aggregation value was reported.
  //
  // Value is UNIX Epoch time in nanoseconds since 00:00:00 UTC on 1 January
  // 1970.
  fixed64 time_unix_nano = 3;

  // count is the number of values in the population. Must be non-negative.
  fixed64 count = 4;

  // sum of the values in the population. If count is zero then this field
  // must be zero.
  double sum = 5;

  // Represents the value at a given quantile of a distribution.
  //
  // To record Min and Max values following conventions are used:
  // - The 1.0 quantile is equivalent to the maximum value observed.
  // - The 0.0 quantile is equivalent to the minimum value observed.
  message ValueAtQuantile {
    // The quantile of a distribution. Must be in the interval
    // [0.0, 1.0].
    double quantile = 1;

    // The value at the given quantile of a distribution.
    double value = 2;
  }

  // (Optional) list of values at different quantiles of the distribution calculated
  // from the current snapshot. The quantiles must be strictly increasing.
  repeated ValueAtQuantile quantile_values = 6;
}
```

Para obtener más información, consulte [Conversiones con formato OpenTelemetry 0.7.0 en CloudWatch](CloudWatch-metric-streams-formats-opentelemetry-translation.md).