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

# OpenTelemetry Collector

> LLM Observability with OpenTelemetry Collector and OpenLIT

To send OpenTelemetry metrics and traces generated by OpenLIT from your AI Application to an OpenTelemetry Collector, follow the below steps.

The OpenTelemetry Collector is a vendor-agnostic way to receive, process, and export telemetry data. It can act as an intermediary to route your OpenLIT data to multiple backends or apply processing transformations.

### 1. Deploy OpenTelemetry Collector

**Install the Collector** (choose your preferred method):

<Tabs>
  <Tab title="Docker">
    ```bash theme={null}
    # Run OpenTelemetry Collector with OTLP receivers
    docker run -p 4317:4317 -p 4318:4318 \
      -v $(pwd)/otel-collector-config.yaml:/etc/otelcol-contrib/config.yaml \
      otel/opentelemetry-collector-contrib:latest
    ```
  </Tab>

  <Tab title="Kubernetes">
    ```bash theme={null}
    # Deploy using Helm
    helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts
    helm install my-otel-collector open-telemetry/opentelemetry-collector \
      --set config.receivers.otlp.protocols.grpc.endpoint="0.0.0.0:4317" \
      --set config.receivers.otlp.protocols.http.endpoint="0.0.0.0:4318"
    ```
  </Tab>

  <Tab title="Binary">
    ```bash theme={null}
    # Download and run the collector binary
    curl -LO https://github.com/open-telemetry/opentelemetry-collector-releases/releases/latest/download/otelcol-contrib_linux_amd64.tar.gz
    tar -xzf otelcol-contrib_linux_amd64.tar.gz
    ./otelcol-contrib --config=otel-collector-config.yaml
    ```
  </Tab>
</Tabs>

**Basic Collector Configuration**:
Create an `otel-collector-config.yaml` file:

<Accordion title="Basic OTLP Configuration">
  ```yaml theme={null}
  receivers:
    otlp:
      protocols:
        grpc:
          endpoint: 0.0.0.0:4317
        http:
          endpoint: 0.0.0.0:4318

  processors:
    batch:

  exporters:
    logging:
      loglevel: debug
    # Add your preferred backend exporters here
    # Examples: jaeger, prometheus, otlp, etc.

  service:
    pipelines:
      traces:
        receivers: [otlp]
        processors: [batch]
        exporters: [logging]
      metrics:
        receivers: [otlp]
        processors: [batch]
        exporters: [logging]
  ```
</Accordion>

**Get the Collector Endpoint**:

* **Default HTTP endpoint**: `http://localhost:4318` or `http://your-collector-host:4318`
* **Default gRPC endpoint**: `http://localhost:4317` or `http://your-collector-host:4317`

### 2. Instrument your application

<Tabs>
  <Tab title="SDK">
    **For direct integration into your Python applications:**

    <Tabs>
      <Tab title="Function Arguments">
        ```python theme={null}
        import openlit

        openlit.init(
          otlp_endpoint="YOUR_COLLECTOR_ENDPOINT"
        )
        ```

        Replace:

        1. `YOUR_COLLECTOR_ENDPOINT` with your OpenTelemetry Collector endpoint from Step 1.
           * **Local HTTP**: `http://localhost:4318`
           * **Local gRPC**: `http://localhost:4317`
           * **Remote**: `http://your-collector-host:4318`
           * **Kubernetes**: `http://my-otel-collector:4318`
      </Tab>

      <Tab title="Environment Variables">
        ```python theme={null}
        import openlit

        openlit.init()
        ```

        Set these environment variables:

        ```shell theme={null}
        export OTEL_EXPORTER_OTLP_ENDPOINT="YOUR_COLLECTOR_ENDPOINT"
        export OTEL_SERVICE_NAME="my-ai-service"
        export OTEL_DEPLOYMENT_ENVIRONMENT="production"
        ```

        Replace:

        1. `YOUR_COLLECTOR_ENDPOINT` with your OpenTelemetry Collector endpoint from Step 1.
      </Tab>
    </Tabs>

    Refer to the OpenLIT [Python SDK repository](https://github.com/openlit/openlit/tree/main/sdk/python) for more advanced configurations and use cases.
  </Tab>

  <Tab title="CLI">
    **For zero-code auto-instrumentation via command line:**

    <Tabs>
      <Tab title="CLI Arguments">
        ```shell theme={null}
        # Using CLI arguments
        openlit-instrument \
          --otlp-endpoint "YOUR_COLLECTOR_ENDPOINT" \
          --service-name "my-ai-service" \
          --deployment-environment "production" \
          python app.py
        ```

        Replace:

        1. `YOUR_COLLECTOR_ENDPOINT` with your OpenTelemetry Collector endpoint from Step 1.
      </Tab>

      <Tab title="Environment Variables">
        ```shell theme={null}
        # Set environment variables (takes precedence over CLI args)
        export OTEL_EXPORTER_OTLP_ENDPOINT="YOUR_COLLECTOR_ENDPOINT"
        export OTEL_SERVICE_NAME="my-ai-service"
        export OTEL_DEPLOYMENT_ENVIRONMENT="production"

        # Run your application
        openlit-instrument python app.py
        ```

        Replace:

        1. `YOUR_COLLECTOR_ENDPOINT` with your OpenTelemetry Collector endpoint from Step 1.
      </Tab>
    </Tabs>

    Refer to the OpenLIT [Python SDK repository](https://github.com/openlit/openlit/tree/main/sdk/python) for more advanced configurations and use cases.
  </Tab>
</Tabs>

### 3. Configure Collector Exporters

Once your LLM application is sending data to the OpenTelemetry Collector, configure exporters to send data to your preferred observability backends:

**Popular Exporter Configurations**:

<Accordion title="Jaeger (Traces)">
  ```yaml theme={null}
  exporters:
    jaeger:
      endpoint: http://jaeger-collector:14250
      tls:
        insecure: false

  service:
    pipelines:
      traces:
        receivers: [otlp]
        processors: [batch]
        exporters: [jaeger]
  ```
</Accordion>

<Accordion title="Prometheus (Metrics)">
  ```yaml theme={null}
  exporters:
    prometheus:
      endpoint: "0.0.0.0:8889"
      metric_expiration: 180m

  service:
    pipelines:
      metrics:
        receivers: [otlp]
        processors: [batch]
        exporters: [prometheus]
  ```
</Accordion>

<Accordion title="Multiple Backends">
  ```yaml theme={null}
  exporters:
    otlp/backend1:
      endpoint: http://backend1:4317
    otlp/backend2:
      endpoint: http://backend2:4317
    logging:
      loglevel: debug

  service:
    pipelines:
      traces:
        receivers: [otlp]
        processors: [batch]
        exporters: [otlp/backend1, otlp/backend2, logging]
      metrics:
        receivers: [otlp]
        processors: [batch]
        exporters: [otlp/backend1, otlp/backend2]
  ```
</Accordion>

**Monitor Collector Health**:

```bash theme={null}
# Check collector logs
docker logs <collector-container-id>

# Or for Kubernetes
kubectl logs -l app.kubernetes.io/name=opentelemetry-collector

# Health check endpoint (if enabled)
curl http://localhost:13133/
```

**Benefits of Using OpenTelemetry Collector**:

* **Vendor Agnostic**: Route data to multiple backends simultaneously
* **Data Processing**: Apply transformations, filtering, and sampling
* **Protocol Translation**: Convert between different telemetry formats
* **Buffering & Reliability**: Handle network issues and backend outages
* **Cost Optimization**: Sample and filter data to reduce costs
* **Security**: Add authentication, encryption, and data anonymization

Your OpenLIT-instrumented AI applications will send telemetry data to the Collector, which can then process and route it to any number of observability backends, providing flexibility and powerful data processing capabilities for your LLM monitoring infrastructure.
