# Send OpenTelemetry metrics

Point an OpenTelemetry OTLP/HTTP metrics exporter at Monitoring, with the JSON encoding and an access key, and get custom metric series.

Replace _console.example.com_ with the host name of your Deutsche Cloud Console. The OTLP endpoint is
`https://console.example.com/monitoring/api/otlp/v1/metrics`. Each data point is checked like a
datum in [Publish custom metrics](publish-custom-metrics.md), and counts against the same
**Custom metric series** quota and the same 20000 datums a minute; the differences are below.

## Prerequisites

- An access key whose user may `monitoring:PutMetricData` on
  `rn:ews::<organization id>:monitoring:*`.
- An exporter that speaks OTLP/HTTP with the JSON encoding. Protobuf and gRPC are not accepted.

## Configure the exporter

**Console:** not available. The exporter is configured in your application or collector.
**CLI:** not available. The exporter is configured in your application or collector.
**API**
For the OpenTelemetry Collector:

```yaml
exporters:
  otlphttp/ews:
    metrics_endpoint: https://console.example.com/monitoring/api/otlp/v1/metrics
    encoding: json
    headers:
      Authorization: 'EWS-ACCESS-KEY ${env:EWS_ACCESS_KEY_ID}:${env:EWS_SECRET_ACCESS_KEY}'
```

For an SDK without a collector, set `OTEL_EXPORTER_OTLP_METRICS_ENDPOINT` to the same URL,
`OTEL_EXPORTER_OTLP_METRICS_PROTOCOL=http/json`, and the `Authorization` header in
`OTEL_EXPORTER_OTLP_METRICS_HEADERS`. Prefer delta temporality
(`OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE=delta`): a cumulative counter is stored as the
running total it reports.

## How the data is mapped

| OTLP                                       | Custom metric                                                                           |
| ------------------------------------------ | --------------------------------------------------------------------------------------- |
| Resource `service.namespace`               | The namespace; else `service.name`; else `otel`                                         |
| A data point's attributes                  | Dimensions, the first ten by name; `service.name` is added when it is not the namespace |
| Gauge and sum points                       | One value each                                                                          |
| Histogram and exponential histogram points | Their count, sum, minimum and maximum                                                   |
| Summary points                             | Their count and sum                                                                     |
| `timeUnixNano`                             | The timestamp; now when it is missing or 0                                              |

## Result

The answer is an OTLP `ExportMetricsServiceResponse`: empty when everything was stored, with
`partialSuccess` (`rejectedDataPoints` and the first reason) when some points were refused or held
no value. Your exporter logs a partial success. A namespace that `Publish custom metrics` refuses
(starting with `DCLOUD/`, `EWS/` or `AWS/`, or with other characters than letters, digits and
`. _ / # : -`) does not refuse the export: its points are counted in `partialSuccess`.

## When the export is refused

- An export that would take your organization past 20000 datums in a minute is refused with
  `429` "At most 20000 datums a minute per organization; send fewer, or aggregate before sending".
- Any content type other than `application/json` is refused with `415` "Only the JSON encoding of
  OTLP is accepted: set encoding: json on the otlphttp exporter, or
  OTEL_EXPORTER_OTLP_METRICS_PROTOCOL=http/json".
- More than 5000 data points in one export is refused with `413` "At most 5000 data points per
  export".
- A body that is not JSON is refused with `400` "The body is not JSON", and one that is not an
  OTLP metrics export with `400` "Not an OTLP metrics export: …".

## Related

- [Publish custom metrics](publish-custom-metrics.md)
- [Chart custom metrics](chart-custom-metrics.md)
