---
# @generated by sylphx-gen 0.1.0 from contracts@e145cc7cf1bc9605f2b27439e5e17ed76a1a2fd7e7021906a013f7565e4a0cd5. Do not edit.
title: "Write spans on a trace"
description: "`observability.traces.write_spans` (POST /v1/{parent}/traces:writeSpans): Ingests a batch of spans atomically; a span's parent and time invariants are validated."
type: reference
product: monitoring
summary: "Ingests a batch of spans atomically; a span's parent and time invariants are validated."
updated: 2026-09-28
nav: false
---

> **This method is not served on the public API.** `api.sylphx.com` does not route this call: its backend is not deployed behind the public API, or does not implement the call. This page documents the contract. It is kept out of the sidebar and of search engines.

Ingests a batch of spans atomically; a span's parent and time invariants are validated. Replay rules are those of WriteLogEntries.

- **Path** `POST https://api.sylphx.com/v1/orgs/acme/projects/shop/envs/production/traces:writeSpans`
- **Scope** `observability:ingest`
- **Effect** `write` — a successful call changes state.
- **Collection** [traces](/docs/api/traces)

## Request

| Field | Type | What it is |
| --- | --- | --- |
| `parent` | `string` | The parent the method acts in. Required. |
| `spans` | `Span[]` | The spans, at most 1000. Required. |

### Span

| Field | Type | What it is |
| --- | --- | --- |
| `trace_id` | `string` | W3C trace id (32 hex). Required. |
| `span_id` | `string` | W3C span id (16 hex). Required. |
| `parent_span_id` | `string` | The parent span id; empty for a root span. |
| `span_name` | `string` | The operation name. Required. |
| `service_name` | `string` | The emitting service. Required. |
| `kind` | `SpanKind` | The span kind. One of `internal`, `server`, `client`, `producer`, `consumer`. |
| `start_time` | `timestamp` | When the span started. Required. |
| `end_time` | `timestamp` | When the span ended; not before `start_time`. Required. |
| `error` | `bool` | Whether the span failed. |
| `error_message` | `string` | The error message, when `error`. |
| `attributes` | `map<string, string>` | Typed attributes, at most 64. |

## Response

| Field | Type | What it is |
| --- | --- | --- |
| `admitted_count` | `int32` | Spans admitted. |

## Errors

- [`UNAUTHENTICATED`](/docs/api/errors/UNAUTHENTICATED) — No valid key or token was presented.
- [`PERMISSION_DENIED`](/docs/api/errors/PERMISSION_DENIED) — The key lacks the method's permission.
- [`INVALID_FIELD`](/docs/api/errors/INVALID_FIELD) — A field failed validation.
- [`IDEMPOTENCY_KEY_REUSED`](/docs/api/errors/IDEMPOTENCY_KEY_REUSED) — An Idempotency-Key was reused with another body.
- [`IDEMPOTENCY_IN_PROGRESS`](/docs/api/errors/IDEMPOTENCY_IN_PROGRESS) — The first call with this Idempotency-Key is still running.
- [`RATE_LIMITED`](/docs/api/errors/RATE_LIMITED) — The rate limit is reached; see Retry-After.
- [`SPEND_LIMIT_REACHED`](/docs/api/errors/SPEND_LIMIT_REACHED) — The org's spend limit is reached.

Every error arrives in the body [Errors](/docs/platform/errors) describes.

## Examples

**cURL**

```curl
curl -X POST "https://api.sylphx.com/v1/orgs/acme/projects/shop/envs/production/traces:writeSpans" \
  -H "Authorization: Bearer $SYLPHX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"spans":[{"end_time":{},"service_name":"…","span_id":"…","span_name":"…","start_time":{},"trace_id":"…"}]}'
```

**TypeScript**

```ts
const response = await sylphx.observability.traces.writeSpans({ parent: 'orgs/acme/projects/shop/envs/production', spans: [{ endTime: {}, serviceName: '…', spanId: '…', spanName: '…', startTime: {}, traceId: '…' }] })
```

**Rust**

```rust
let mut req = sylphx::observability::WriteSpansRequest::default();
req.parent = "orgs/acme/projects/shop/envs/production".to_string();
req.spans = vec![Default::default()];
let response = sx.observability().traces().write_spans(req).await?;
```

**CLI**

```bash
sylphx observability traces write-spans orgs/acme/projects/shop/envs/production
```

**MCP**

```json
{ "method_id": "observability.traces.write_spans", "args": {"parent":"orgs/acme/projects/shop/envs/production","spans":[{"end_time":{},"service_name":"…","span_id":"…","span_name":"…","start_time":{},"trace_id":"…"}]} }
```
