# OpenTelemetry

Tailcove accepts OpenTelemetry logs, metrics and [traces](https://tailcove.dev/docs/opentelemetry/traces) over **OTLP/HTTP**, in protobuf
or JSON, with or without gzip. Point any OpenTelemetry SDK or the Collector at
it with your source token.

## Endpoint and authentication

Set the exporter's base endpoint; the SDK appends `/v1/logs`, `/v1/metrics` and `/v1/traces`.

```bash@macOS_/_Linux
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.tailcove.dev/api/v1/otlp
export OTEL_EXPORTER_OTLP_HEADERS="authorization=Bearer YOUR_SOURCE_TOKEN"
```

```powershell@Windows_(PowerShell)
$env:OTEL_EXPORTER_OTLP_PROTOCOL = "http/protobuf"
$env:OTEL_EXPORTER_OTLP_ENDPOINT = "https://ingest.tailcove.dev/api/v1/otlp"
$env:OTEL_EXPORTER_OTLP_HEADERS = "authorization=Bearer YOUR_SOURCE_TOKEN"
```

These last for the current terminal session. To keep them, add the `export` lines to `~/.zshrc` (macOS) or
`~/.bashrc` (Linux), or on Windows run `setx NAME "value"` once per variable and open a new terminal. In production, set
them wherever your app's environment lives: the service unit, container or deploy settings.

| Signal  | URL                                                       |
| ------- | --------------------------------------------------------- |
| Logs    | `POST https://ingest.tailcove.dev/api/v1/otlp/v1/logs`    |
| Metrics | `POST https://ingest.tailcove.dev/api/v1/otlp/v1/metrics` |
| Traces  | `POST https://ingest.tailcove.dev/api/v1/otlp/v1/traces`  |

`Content-Type` must be `application/x-protobuf` or `application/json`; gRPC is
not supported (use the `http/protobuf` or `http/json` protocol).

## Collector

```yaml
exporters:
    otlphttp/tailcove:
        endpoint: https://ingest.tailcove.dev/api/v1/otlp
        headers:
            authorization: Bearer YOUR_SOURCE_TOKEN

service:
    pipelines:
        logs:
            exporters: [otlphttp/tailcove]
        metrics:
            exporters: [otlphttp/tailcove]
```

## How logs are stored

OTLP log records become ordinary log lines, so search, live tail, issues and
alerts work on them unchanged.

| OTLP                                                                                                   | Tailcove                              |
| ------------------------------------------------------------------------------------------------------ | ------------------------------------- |
| `timeUnixNano` (else `observedTimeUnixNano`)                                                           | timestamp                             |
| `severityNumber` (1-8 debug, 9-12 info, 13-16 warning, 17-20 error, 21+ critical; else `severityText`) | level                                 |
| `body`                                                                                                 | message                               |
| `host.name` (else `service.instance.id`) resource attribute                                            | host                                  |
| record attributes                                                                                      | `context.attributes`                  |
| resource attributes                                                                                    | `context.resource`                    |
| `traceId`, `spanId`                                                                                    | `context.trace_id`, `context.span_id` |

Logs count against your log quota like any other line.

## How metrics are stored

- Gauges and sums become one point per data point; cumulative sums are stored
  as sent, not as rates.
- Histograms become `name_count`, `name_sum` and cumulative `name_bucket`
  points with an `le` label (at most 32 bounds plus `+Inf`).
- Exponential histograms and summaries keep `name_count` and `name_sum`.
- Labels are the data point's attributes plus `service` (the resource's
  `service.name`); other resource attributes are not labels.
- Metric names are cleaned to `A-Za-z0-9_.:-` (a `/` becomes `_`).

Points count toward the [metrics limits](https://tailcove.dev/docs/metrics/overview#limits).

## Limits and responses

A request is at most 5 MB (compressed or not), holds at most 5,000 log records
or metric points, and nests at most 32 levels in JSON.

| Status | Meaning                                                               |
| ------ | --------------------------------------------------------------------- |
| `200`  | Accepted (an empty OTLP response)                                     |
| `401`  | Missing or invalid token                                              |
| `413`  | Body too large, compressed or decompressed                            |
| `415`  | Not protobuf or JSON                                                  |
| `422`  | Not valid OTLP, or too many records or points                         |
| `429`  | Over a rate or points limit; the exporter retries after `Retry-After` |
| `503`  | Buffer full; the exporter retries                                     |
