# Deployment Patterns — OpenTelemetry

Source: https://www.skillbyai.com/en/opentelemetry/c-deploy

> Agents and gateways.

## Agent, gateway or both

In the **agent** pattern, a Collector runs next to applications (a sidecar or a Kubernetes DaemonSet per node), receiving local OTLP traffic and adding host or pod metadata. In the **gateway** pattern, a central, horizontally scaled Collector service receives data from many agents or apps and handles sampling, filtering and export credentials. Many setups combine both. Applications can also export directly to a backend, but a Collector gives retries, batching, central configuration and the freedom to change backends.

## Agent and gateway layout

A common Kubernetes topology.

```text
node 1: [app pods] --OTLP--> [collector agent (DaemonSet)] --+
node 2: [app pods] --OTLP--> [collector agent (DaemonSet)] --+--> [collector gateway (Deployment, 3 replicas)]
                                                               |      tail sampling, redaction,
                                                               |      backend credentials
                                                               +--> backends (traces / metrics / logs)
```

## Use load-balancing exporters for tail sampling

Tail sampling needs all spans of a trace on the same gateway instance; the loadbalancing exporter routes by trace ID.

**Quiz:** Where does an "agent" Collector usually run?

- [x] Close to the application, as a sidecar or one per node
- [ ] Only inside the backend database
- [ ] In the browser
- [ ] On the developer laptop only

*Answer:* Close to the application, as a sidecar or one per node. Gateways are central.
