# OTLP

> The endpoint every server trace arrives at, from Sypnia's server SDKs or from any OpenTelemetry exporter, with its encodings, answers and limits.

Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service).  
Source: https://telemetry.docs.sypnia.com/api/otlp/

For agents: Reference of the OTLP endpoints of the Sypnia HTTP API: parameters, response shapes, examples and errors.

Every server trace reaches Sypnia here, in the OpenTelemetry protocol over HTTP (OTLP/HTTP). The Sypnia
server SDKs ([`@sypnia/telemetry/node`](https://telemetry.docs.sypnia.com/sdks/node), [`@sypnia/telemetry/next`](https://telemetry.docs.sypnia.com/sdks/nextjs)) send to this endpoint in protobuf;
so does the [OpenTelemetry bridge](https://telemetry.docs.sypnia.com/sdks/otel-bridge). Any other OpenTelemetry exporter can send to it too,
from any language: see [OpenTelemetry](https://telemetry.docs.sypnia.com/sdks/opentelemetry). Traces only: OTLP logs and metrics are not
accepted (Sypnia does not collect logs or custom metrics). The browser SDK does not use this
endpoint: it sends its own events to [ingest](https://telemetry.docs.sypnia.com/api/ingest).

## Configure an exporter

A Sypnia SDK needs nothing here: `init` sets it all. For any other OpenTelemetry SDK, set the standard
variables. The exporter adds `/v1/traces` to the endpoint by itself.

`.env`

```bash
OTEL_EXPORTER_OTLP_ENDPOINT=https://telemetry.ingest.sypnia.com/v1/otlp
OTEL_EXPORTER_OTLP_HEADERS=Authorization=Bearer%20spk_7d1f0c9e4b8a2f6d3c5e1a9b0f4d8c2e
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
OTEL_SERVICE_NAME=shop-api
OTEL_RESOURCE_ATTRIBUTES=deployment.environment.name=production,service.version=4f2a91c
```

The space after `Bearer` is written `%20`: the variable uses the W3C Baggage format, which every OpenTelemetry
SDK decodes, and the Python SDK refuses a bare space. Self-hosted: use `<your base URL>/v1/otlp` as the endpoint.

## Encodings

| `Content-Type`           | Body                                                                                                                                 | Answer                                      |
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------- |
| `application/x-protobuf` | An `ExportTraceServiceRequest` in protobuf. What the Sypnia SDKs send, and what we recommend: smaller and faster to encode than JSON | An `ExportTraceServiceResponse` in protobuf |
| `application/json`       | The same message in OTLP's JSON encoding (trace and span ids in hex, times as strings of nanoseconds)                                | The same message in JSON                    |

`Content-Encoding: gzip` is accepted with both, and the Sypnia SDKs use it. gRPC is not accepted.

## How spans become Sypnia data

In short: `service.name`, `deployment.environment.name` and `service.version` give the service, the
environment and the release; a server span with `http.route` is one API call in
[Performance](https://telemetry.docs.sypnia.com/api/performance); a client span is a database call when it has `db.system.name` and a call to
another service when it has `http.request.method`; status `ERROR` or an `exception` event is a failure;
`session.id` joins the trace to a session. Every attribute Sypnia reads, the `sypnia.*` ones included, and
how the engine joins these spans with the browser's events into one trace, are in the
[semantic conventions](https://telemetry.docs.sypnia.com/reference/semantic-conventions).

## When the project reaches a limit

OTLP has no field for it, so the answer carries the header `Sypnia-Slow-Down`, the same decision as
[`slow_down`](https://telemetry.docs.sypnia.com/api/ingest#when-a-limit-is-reached) in a single line:
`send=failures; until=2026-04-01T00:00:00Z`. The Sypnia server SDKs obey it and export only spans that
carry a failure until then. Other exporters ignore the header; the spans the engine does not store are
counted in `partialSuccess`.

At Sypnia Cloud's hard stop on everything received, the answer is `429 limit_reached` instead, with
`Sypnia-Slow-Down: send=none; until=…` and `Retry-After`, and nothing is stored. The Sypnia SDKs stop exporting
until then; other exporters retry after `Retry-After` or drop the request when their own retries run out.

## Export traces

`POST /v1/otlp/v1/traces` \[Engine, Cloud]

The OTLP/HTTP trace endpoint, as the OpenTelemetry specification defines it. The body is an
`ExportTraceServiceRequest`, in protobuf (`application/x-protobuf`, what the Sypnia server SDKs send) or JSON
(`application/json`), optionally with `Content-Encoding: gzip`. The answer is an
`ExportTraceServiceResponse` in the same encoding.

The credential is an ingest key in `Authorization: Bearer spk_…`. The project comes from the key, never from
an attribute.

When some spans are refused, the answer is still `200` and `partialSuccess` says how many and why, as the
protocol requires. An exporter must not retry a partial success. Retry a network failure, `429`, `502`, `503`
and `504`, after `Retry-After` when it is given; OpenTelemetry exporters and the Sypnia SDKs do it by
themselves. A `429 limit_reached` is the exception: the Sypnia SDKs send nothing more before the `until` of
its `Sypnia-Slow-Down` (see [when the project reaches a limit](#when-the-project-reaches-a-limit)). Never retry
another `4xx`. A request that arrives twice is stored once (the engine keys it by the
SHA-256 of its body).

**Authentication:** Ingest key

**Limits**

- Body: 4,000,000 bytes after decompression.
- Spans per request: 2,000. Spans per trace that are kept: 500 (the rest are counted in the trace's `dropped_spans`).
- Attributes per span: 64, values up to 256 characters (exceptions in the semantic conventions).
- The Sypnia server SDKs send at most 512 spans per request, every 2 seconds, and never split one request's spans across two.

**Request:**

```bash
curl -X POST "https://telemetry.ingest.sypnia.com/v1/otlp/v1/traces" \
  -H "Authorization: Bearer spk_7d1f0c9e4b8a2f6d3c5e1a9b0f4d8c2e" \
  -H "Content-Type: application/json" \
  --data @spans.json
```

**Request body:**

```json
{
  "resourceSpans": [
    {
      "resource": {
        "attributes": [
          {
            "key": "service.name",
            "value": {
              "stringValue": "shop-api"
            }
          },
          {
            "key": "service.version",
            "value": {
              "stringValue": "4f2a91c"
            }
          },
          {
            "key": "deployment.environment.name",
            "value": {
              "stringValue": "production"
            }
          }
        ]
      },
      "scopeSpans": [
        {
          "spans": [
            {
              "traceId": "7c2e9a4b1d8f4e6a9b3c5d7e1f2a4b6c",
              "spanId": "a1b2c3d4e5f60718",
              "parentSpanId": "0f1e2d3c4b5a6978",
              "name": "POST /api/checkout",
              "kind": 2,
              "startTimeUnixNano": "1773311503114000000",
              "endTimeUnixNano": "1773311506956000000",
              "attributes": [
                {
                  "key": "http.request.method",
                  "value": {
                    "stringValue": "POST"
                  }
                },
                {
                  "key": "http.route",
                  "value": {
                    "stringValue": "/api/checkout"
                  }
                },
                {
                  "key": "url.path",
                  "value": {
                    "stringValue": "/api/checkout"
                  }
                },
                {
                  "key": "http.response.status_code",
                  "value": {
                    "intValue": "400"
                  }
                },
                {
                  "key": "session.id",
                  "value": {
                    "stringValue": "8f3a6c1e9b2d4f07a5c3e1b8d6f4a2c0"
                  }
                },
                {
                  "key": "user.id",
                  "value": {
                    "stringValue": "u_1042"
                  }
                },
                {
                  "key": "sypnia.account.id",
                  "value": {
                    "stringValue": "acc_77"
                  }
                }
              ]
            },
            {
              "traceId": "7c2e9a4b1d8f4e6a9b3c5d7e1f2a4b6c",
              "spanId": "b2c3d4e5f6071829",
              "parentSpanId": "a1b2c3d4e5f60718",
              "name": "SELECT carts",
              "kind": 3,
              "startTimeUnixNano": "1773311503121000000",
              "endTimeUnixNano": "1773311503133000000",
              "attributes": [
                {
                  "key": "db.system.name",
                  "value": {
                    "stringValue": "postgresql"
                  }
                },
                {
                  "key": "db.operation.name",
                  "value": {
                    "stringValue": "SELECT"
                  }
                },
                {
                  "key": "db.collection.name",
                  "value": {
                    "stringValue": "carts"
                  }
                }
              ]
            },
            {
              "traceId": "7c2e9a4b1d8f4e6a9b3c5d7e1f2a4b6c",
              "spanId": "c3d4e5f60718293a",
              "parentSpanId": "a1b2c3d4e5f60718",
              "name": "POST /v1/payments",
              "kind": 3,
              "startTimeUnixNano": "1773311503146000000",
              "endTimeUnixNano": "1773311506936000000",
              "attributes": [
                {
                  "key": "http.request.method",
                  "value": {
                    "stringValue": "POST"
                  }
                },
                {
                  "key": "server.address",
                  "value": {
                    "stringValue": "api.payments.example"
                  }
                },
                {
                  "key": "url.path",
                  "value": {
                    "stringValue": "/v1/payments"
                  }
                },
                {
                  "key": "http.response.status_code",
                  "value": {
                    "intValue": "400"
                  }
                },
                {
                  "key": "error.type",
                  "value": {
                    "stringValue": "400"
                  }
                }
              ],
              "status": {
                "code": 2,
                "message": "amount is required"
              }
            }
          ]
        }
      ]
    }
  ]
}
```

**Request:**

```bash
curl -X POST "https://telemetry.ingest.sypnia.com/v1/otlp/v1/traces" \
  -H "Authorization: Bearer spk_7d1f0c9e4b8a2f6d3c5e1a9b0f4d8c2e" \
  -H "Content-Type: application/x-protobuf" \
  -H "Content-Encoding: gzip" \
  --data-binary @spans.pb.gz
```

**Response: Every span stored (200):**

```json
{}
```

**Response: Some spans refused (200):**

```json
{
  "partialSuccess": {
    "rejectedSpans": 2,
    "errorMessage": "2 spans dropped: trace id is not 16 bytes"
  }
}
```

**Response: The project reached its events limit (200):**

```json
{
  "partialSuccess": {
    "rejectedSpans": 14,
    "errorMessage": "14 spans dropped: events_limit (failures are still stored)"
  }
}
```

**Errors:**

- `400` `invalid_body`: The body is not a valid `ExportTraceServiceRequest`.
- `401` `unauthorized`: The ingest key is missing, unknown or revoked.
- `403` `wrong_credential`: An API token or the root token was sent. Ingest only takes an ingest key.
- `413` `payload_too_large`: The body is larger than 4,000,000 bytes after decompression.
- `415` `unsupported_media_type`: The content type is neither `application/x-protobuf` nor `application/json`.
- `429` `rate_limited`: Too many requests. OTLP exporters honour `Retry-After` by themselves.
- `429` `limit_reached`: Sypnia Cloud: everything received this month reached its limit. Nothing is stored. The answer carries `Sypnia-Slow-Down: send=none; until=…` and `Retry-After`.
- `503` `unavailable`: Storage is not reachable. OTLP exporters retry `503` by themselves.

The errors every endpoint can answer (`401`, `403`, `429`, `500`, `503`) are on [Errors, limits, pagination](https://telemetry.docs.sypnia.com/api/errors-limits-pagination).
