

# OpenWatch 0.7.0 형식의 CloudWatch 지표 스트림 출력
<a name="CloudWatch-metric-streams-formats-opentelemetry"></a>

OpenTelemetry는 도구, API 및 SDK 모음입니다. OpenTelemetry를 사용하여 분석을 위한 원격 측정 데이터(지표, 로그, 추적)를 계측하고 생성하며 수집하고 내보낼 수 있습니다. OpenTelemetry는 Cloud Native Computing Foundation(CNCF)의 일부입니다. 자세한 내용은 [OpenTelemetry](https://opentelemetry.io/)를 참조하세요.

전체 OpenTelemetry 0.7.0 사양에 대한 내용은 [v0.7.0 릴리스](https://github.com/open-telemetry/opentelemetry-proto/releases/tag/v0.7.0)를 참조하세요.

Kinesis 레코드에는 하나 이상의 `ExportMetricsServiceRequest` OpenTelemetry 데이터 구조가 포함될 수 있습니다. 각 데이터 구조는 바이트 단위의 레코드 길이를 나타내는 `UnsignedVarInt32`가 있는 헤더로 시작합니다. 각 `ExportMetricsServiceRequest`에는 동시에 여러 지표의 데이터가 포함될 수 있습니다.

다음은 `ExportMetricsServiceRequest` OpenTelemetry 데이터 구조 메시지의 문자열 표현입니다. OpenTelemetry는 Google Protocol Buffers 바이너리 프로토콜을 직렬화하며 이것은 사람이 읽을 수 없습니다.

```
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
          }
        }
      }
    }
  }
}
```

**OpenTelemetry 지표 데이터를 직렬화하는 최상위 객체**

`ExportMetricsServiceRequest`는 OpenTelemetry Exporter 페이로드를 직렬화하는 최상위 래퍼입니다. 여기에는 하나 이상의 `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`는 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;
}
```

**Resource 객체**

`Resource` 객체는 지표를 생성한 리소스에 관한 일부 정보를 포함하는 값 페어 객체입니다. AWS에서 생성한 지표의 경우 데이터 구조에 지표와 관련된 리소스(예: EC2 인스턴스 또는 S3 버킷)의 Amazon 리소스 이름(ARN)이 포함됩니다.

`Resource` 객체에는 키-값 페어 목록을 저장하는 `attributes`라는 속성이 포함되어 있습니다.
+ `cloud.account.id`에는 계정 ID가 포함됩니다.
+ `cloud.region`에는 리전이 포함됩니다.
+ `aws.exporter.arn`에는 지표 스트림 ARN이 포함됩니다.
+ `cloud.provider`은(는) 항상 `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;
}
```

**InstrumentationLibraryMetrics 객체**

instrumentation\_library 필드는 채워지지 않습니다. 내보내는 지표 필드만 채워집니다.

```
// 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;
}
```

**Metric 객체**

Metric 객체에는 `DoubleSummaryDataPoint` 목록을 포함하는 `DoubleSummary` 데이터 필드가 포함되어 있습니다.

```
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;
}
```

**MetricDescriptor 객체**

MetricDescriptor 객체에는 메타데이터가 포함되어 있습니다. 자세한 내용은 GitHub에서 [metrics.proto](https://github.com/open-telemetry/opentelemetry-proto/blob/main/opentelemetry/proto/metrics/v1/metrics.proto#L110)를 참조하세요.

지표 스트림의 경우 MetricDescriptor의 내용은 다음과 같습니다.
+ `name`은 `amazonaws.com/{{metric_namespace}}/{{metric_name}}`이 됩니다.
+ `description`은 비어 있게 됩니다.
+ `unit`은 지표 데이터의 단위를 측정 단위에 대한 통합 코드의 대소문자를 구분하는 변형에 매핑함으로써 채워집니다. 자세한 내용은 [CloudWatch에서 OpenTelemetry 0.7.0 형식으로 번역](CloudWatch-metric-streams-formats-opentelemetry-translation.md) 단원 및 [측정 단위에 대한 통합 코드](https://ucum.org/ucum.html)를 참조하세요.
+ `type`은 `SUMMARY`가 됩니다.

**DoubleSummaryDataPoint 객체**

DoubleSummaryDataPoint 객체에는 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;
}
```

자세한 내용은 [CloudWatch에서 OpenTelemetry 0.7.0 형식으로 번역](CloudWatch-metric-streams-formats-opentelemetry-translation.md) 섹션을 참조하세요.