# Ingesting Open Telemetry Data

{% callout type="tip" %}
Setting up OTEL can be complex. If you have questions, contact the Statsig team on Slack.
{% /callout %}

## How OpenTelemetry integration works

This guide walks you through setting up the OpenTelemetry Collector in your Kubernetes environment and configuring it to send telemetry data to Statsig using the official `otlphttp` exporter.

***

## ✅ Prerequisites

* A running Kubernetes cluster (e.g., GKE, EKS, Minikube, etc.)
* Helm installed, or another mechanism to apply helm charts to your cluster, like ArgoCD
* API Access to a Statsig project with a Server SDK Secret Key
* Optional: `kubectl` configured and connected to the cluster, for validating and debugging setup

***

## 1. Setup OpenTelemetry Collector on Kubernetes

The recommended setup follows the official OpenTelemetry Kubernetes guide to install the OpenTelemetry Collector in both **DaemonSet** and **Deployment** modes using the official Helm chart. Tested `values.yaml` files for both deployment modes are available in Step 3.

**📘 Official Guide:**

[OpenTelemetry Collector for Kubernetes – Getting Started](https://opentelemetry.io/docs/platforms/kubernetes/getting-started/)

### Why both

* **DaemonSet Collector**: Runs one instance per node to collect host-level telemetry (e.g., logs, pod and node metrics).
* **Deployment Collector**: Runs one instance per cluster to gather telemetry related to the cluster as a whole.

Configure at least the receivers below for a useful Statsig-powered observability platform for your Kubernetes workloads. The setup uses [Presets](https://opentelemetry.io/docs/platforms/kubernetes/helm/collector/#presets) from the official chart and customizes some components, as shown in the sample values files in Step 3.

* Minimum for scraping logs:
  * [Filelog Receiver](https://opentelemetry.io/docs/platforms/kubernetes/getting-started/#filelog-receiver)
  * [Kubernetes Attributes Processor](https://opentelemetry.io/docs/platforms/kubernetes/getting-started/#kubernetes-attributes-processor)
* Minimum for scraping kubernetes metrics
  * [KubeletStats Receiver](https://opentelemetry.io/docs/platforms/kubernetes/getting-started/#kubeletstats-receiver)
  * [Kubernetes Cluster Receiver](https://opentelemetry.io/docs/platforms/kubernetes/getting-started/#kubernetes-cluster-receiver)
* Minimum for metrics about Otel Collector itself
  * [OTLP Receiver](https://opentelemetry.io/docs/platforms/kubernetes/getting-started/#otlp-receiver) for [scraping internal metrics](https://opentelemetry.io/docs/collector/internal-telemetry/#configure-internal-metrics) (alternatively scraped through prometheus receiver)

***

## 2. Configure exporting telemetry to Statsig with OTLP HTTP Exporter

Statsig supports receiving OTLP-formatted, JSON-encoded telemetry at the endpoint `https://api.statsig.com/otlp`. The OpenTelemetry Collector supports sending telemetry to the Statsig endpoint using the official `otlphttp` exporter.

### Authentication

Statsig authenticates requests using the request header `statsig-api-key` and a valid SDK Server Secret key generated from [console.statsig.com](http://console.statsig.com) (under *Settings > Keys & Environments*). Keep your secret key secure using a Kubernetes Secret management provider and make it available to the OpenTelemetry collector pod’s environment.

### Example Exporter Config

```yaml
exporters:
  otlphttp:
    endpoint: https://api.statsig.com/otlp
    encoding: json
    headers:
      statsig-api-key: ${env:STATSIG_SERVER_SDK_SECRET}
```

## 3. Example Helm Chart Values for a quick and correct setup

The following two complete and tested `values.yaml` configurations work with the OpenTelemetry Helm charts:

### 🔗 Deployment Collector

👉 [values-gateway.yaml](https://gist.github.com/karan-statsig/d5c70b7fd100ab445985b620dcb7e8c6)

### 🔗 DaemonSet Collector

👉 [values-agent.yaml](https://gist.github.com/karan-statsig/f02ee95fef00aecde402829b5a4c60e8)

Use them with the Helm chart version `0.75.1` like this:

```yaml
helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts
helm repo update

# Install Deployment Collector
helm install otel-deployment open-telemetry/opentelemetry-collector \
  --version 0.75.1 \
  -f values-gateway.yaml -n otel --create-namespace

# Install DaemonSet Collector
helm install otel-daemonset open-telemetry/opentelemetry-collector \
  --version 0.75.1 \
  -f values-agent.yaml -n otel
```

## 4. Verify the Setup

Check that all pods are running:

```bash
kubectl get pods -n otel
```

Check logs for a specific collector pod and confirm no errors appear:

```bash
kubectl logs -n otel $pod_name
```

## 5. Explore

Explore your logs and metrics at [console.statsig.com](http://console.statsig.com) using the Logs Explorer and Metrics Explorer products under *Analytics* in the sidebar.

***

## 🔗 Resources

* [OpenTelemetry Collector Documentation](https://opentelemetry.io/docs/collector/)
* [Important Concepts for Kubernetes](https://opentelemetry.io/docs/platforms/kubernetes/collector/components/)
* [Helm Chart Reference](https://github.com/open-telemetry/opentelemetry-helm-charts)
* [Collector Configuration Reference](https://opentelemetry.io/docs/collector/configuration)
* [OTLP Protocol Specification](https://opentelemetry.io/docs/specs/otlp/)
