> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lynxops.co/llms.txt
> Use this file to discover all available pages before exploring further.

# 전송과 안정성

> 백그라운드 전송, flush, 타임아웃, 재시도, 서킷 브레이커가 어떻게 동작하는지 설명합니다.

Lynx는 수집 데이터 전송 실패가 AI 서비스를 멈추지 않도록 설계되어 있습니다. 운영 환경에서는 관측 데이터보다 사용자 요청의 흐름이 먼저입니다.

## 운영 기본값

| 옵션                                | 기본값             |
| --------------------------------- | --------------- |
| `delivery.mode`                   | `"BACKGROUND"`  |
| `delivery.timeoutMs`              | `1000`          |
| `delivery.flushOnRunEnd`          | `false`         |
| `delivery.flushIntervalMs`        | `3000`          |
| `delivery.batchSize`              | `50`            |
| `delivery.maxQueueSize`           | `1000`          |
| `delivery.overflowStrategy`       | `"DROP_OLDEST"` |
| `circuitBreaker.enabled`          | `true`          |
| `circuitBreaker.failureThreshold` | `3`             |
| `circuitBreaker.cooldownMs`       | `30000`         |

## 백그라운드 전송

백그라운드 모드에서 `run()`은 이벤트를 로컬에 기록하고 전송을 기다리지 않습니다. SDK는 타이머, 명시적인 `flush()`, 또는 `shutdown()` 시점에 이벤트를 전송합니다.

```ts theme={null}
const lynx = new LynxTracer({
  clientId: "support-api",
  endpoint: "https://lynx.example.com",
  apiKey: process.env.LYNX_API_KEY,
  delivery: {
    mode: "BACKGROUND",
    timeoutMs: 1000,
    flushOnRunEnd: false,
  },
});
```

## Blocking 전송

현재 요청 안에서 전송 시도까지 끝내야 하는 특수한 환경에서만 blocking mode를 사용하세요.

```ts theme={null}
const lynx = new LynxTracer({
  clientId: "worker",
  endpoint: "https://lynx.example.com",
  apiKey: process.env.LYNX_API_KEY,
  delivery: {
    mode: "BLOCKING",
    flushOnRunEnd: true,
    timeoutMs: 1500,
  },
});
```

## Flush와 shutdown

```ts theme={null}
await lynx.flush();
```

프로세스가 종료되기 전에는 `shutdown()`을 사용하세요.

```ts theme={null}
await lynx.shutdown({ timeoutMs: 1000 });
```

## 로컬 상태 확인

```ts theme={null}
const status = lynx.getStatus();

console.log(status.queueSize);
console.log(status.circuitState);
console.log(status.droppedEvents);
```

## Lynx 서버가 내려간 경우

SDK는 네트워크 오류, 타임아웃, 2xx가 아닌 응답을 내부에서 처리합니다. 실패한 batch는 메모리 재시도 큐로 이동합니다. 실패가 반복되면 서킷 브레이커가 열리고, cooldown이 끝날 때까지 전송 시도를 잠시 멈춥니다.

큐가 `maxQueueSize`에 도달하면 SDK는 `overflowStrategy`에 따라 이벤트를 버립니다.
