Skip to content

Commit 1a29838

Browse files
update OLTP doc (#555)
* update OLTP doc * docs(swift): clarify OTLP gateway route is the configured endpoint Codex review flagged that OTLPExporter never appends /v1/traces to the endpoint — it POSTs to exactly the URL passed in. Describing the gateway contract as "POST <your-url>/v1/traces" could lead readers to double-append the suffix on their gateway route. Co-authored-by: Corneliu Croitoru <cornelcroi@users.noreply.github.com> --------- Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Corneliu Croitoru <cornelcroi@users.noreply.github.com>
1 parent d9c4dda commit 1a29838

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

docs/src/content/docs/swift/tracing/built-in/otlp-exporter.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,27 @@ let tracer = ProcessingTracer(
123123
)
124124
```
125125

126+
## Routing through your own gateway
127+
128+
If you can't reach a backend directly from the device — or you don't want to ship its API key in the app — point `OTLPExporter` at an endpoint you control and let that server attach the real credentials and forward the traces on. The device holds only your own token; the backend key stays server-side.
129+
130+
```swift
131+
let tracer = ProcessingTracer(
132+
exporter: OTLPExporter(
133+
endpoint: URL(string: "https://telemetry.example.com/v1/traces")!, // your gateway
134+
headers: ["Authorization": "Bearer <app-token>"], // your auth, not the backend's
135+
serviceName: "my-app"
136+
)
137+
)
138+
```
139+
140+
`OTLPExporter` doesn't care whether the URL is a backend or your own proxy — it POSTs the same OTLP/HTTP JSON either way, so no custom `TraceExporter` is needed. What your endpoint receives and how it should behave:
141+
142+
- **`POST` to the configured `endpoint`** (in the example above, `/v1/traces`), `Content-Type: application/json`, body is an OTLP `ExportTraceServiceRequest`. It must return **2xx** or the batch is dropped (there is no retry — see [Error handling](#error-handling)).
143+
- **When it fires:** background, fire-and-forget — a batch is POSTed when `batchSize` spans accumulate or on `flush()`. Spans ship **as each one ends**, so a trace arrives across multiple POSTs and out of causal order (children before their parent root). Stitch by `traceId` + `parentSpanId` and tolerate late/orphan spans.
144+
- **What it can do:** at minimum, forward the body verbatim to the real backend with the backend's auth header added. It may also redact `gen_ai.prompt`/`gen_ai.completion`, route to different projects per user/env, buffer and retry, or fan out to another OTLP backend. An off-the-shelf [OpenTelemetry Collector](https://opentelemetry.io/docs/collector/) does the forward-and-inject case with no custom code.
145+
- **Payload notes (standard OTLP/JSON):** `intValue` fields are strings (`"1200"`), timestamps are string nanoseconds, `parentSpanId` is omitted (not null) on roots, and `status.code` is `0` (unset/ok) or `2` (error).
146+
126147
## Related pages
127148

128149
- [Tracing Overview](/agent-squad/swift/tracing/overview/) — the full pipeline and all protocols.

0 commit comments

Comments
 (0)