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

# Loki

> Configuring the Loki backend (Self-Hosted)

### Getting Started

<img src="https://d15jtxgb40qetw.cloudfront.net/loki.svg" alt="loki" className="not-prose h-20" />

<Note>
  These instructions are for the **self hosted** Loki instance. If you need a managed service, please follow the instructions on the [Grafana Cloud Loki](../backends/grafanacloudloki) page.
</Note>

This destination is for self hosted Loki instances.

**Loki Labels**

Loki labels are used to "index" logs and allow efficient filtering in the Grafana UI. You can read more about them [here](https://grafana.com/docs/loki/latest/get-started/labels/).

You can configure your grafana cloud loki labels in the `Labels` multi-input config option in the destination page in the Odigos UI.

* Labels should be names of OpenTelemetry resource attribute or log record attribute keys that you want to index, for example: `"k8s.namespace.name"`.
* To avoid performance issues, it is recommended to limit the number of labels to a reasonable amount.
* [Use only low cardinality values](https://grafana.com/docs/loki/latest/get-started/labels/#cardinality). e.g. use only OpenTelemetry attributes for which you expect a small number of unique values like `http.response.status_code` but **not** `network.peer.address`.
* If the label is not present in a log record, it will be ignored.
* The default labels if not set are: `k8s.container.name, k8s.pod.name, k8s.namespace.name`

### Configuring Destination Fields

<Accordion title="Supported Signals:">
  ❌ Traces
  ❌ Metrics
  ✅ Logs
  ❌ Profiles
</Accordion>

* **LOKI\_URL** `string` : Endpoint. If scheme is not provided, it defaults to `http`. If port is not provided, it defaults to `3100`. If path is not provided, it defaults to `/otlp`.
  * This field is required
  * Example: `http://<loki-host>:<loki-port>/otlp`
* **LOKI\_SCOPE\_ORG\_ID** `string` : X-Scope-OrgID. use this X-Scope-OrgID if you need to scope the data to a specific org. Multiple orgs can be chained using `|`
  * This field is optional
  * Example: `org1|org2|org3`
* **LOKI\_USERNAME** `string` : Basic Auth Username. username for basic authentication
  * This field is optional
  * Example: `<loki-username>`
* **LOKI\_PASSWORD** `string` : Basic Auth Password. password for basic authentication
  * This field is optional
  * Example: `<loki-password>`
* **LOKI\_LABELS** `string[]` : Labels. use these OpenTelemetry resource attributes as loki labels for each log record
  * This field is required and defaults to `["k8s.container.name", "k8s.pod.name", "k8s.namespace.name"]`

<Info>
  The supported Loki version is V3. Please make sure you are using the correct version, and that you have enabled native OTLP support. As part of this version, the path `/loki/api/v1/push` has been deprecated and replaced with `/otlp`.
</Info>

### Adding Destination to Odigos

There are two primary methods for configuring destinations in Odigos:

##### **Using the UI**

<Steps>
  <Step>
    Use the [Odigos CLI](https://docs.odigos.io/cli/odigos_ui) to access the UI

    ```bash theme={null}
    odigos ui
    ```
  </Step>

  <Step>
    Click on `Add Destination`, select `Loki` and follow the on-screen instructions
  </Step>
</Steps>

##### **Using Kubernetes manifests**

<Steps>
  <Step>
    Save the YAML below to a file (e.g. `loki.yaml`)

    ```yaml theme={null}
    apiVersion: odigos.io/v1alpha1
    kind: Destination
    metadata:
      name: loki-example
      namespace: odigos-system
    spec:
      data:
        LOKI_LABELS: '<Labels (default: ["k8s.container.name", "k8s.pod.name", "k8s.namespace.name"])>'
        LOKI_URL: <Endpoint>
        # Note: The commented fields below are optional.
        # LOKI_SCOPE_ORG_ID: <X-Scope-OrgID>
        # LOKI_USERNAME: <Basic Auth Username>
      destinationName: loki
      # Uncomment the 'secretRef' below if you are using the optional Secret.
      # secretRef:
      #   name: loki-secret
      signals:
      - LOGS
      type: loki

    ---

    # The following Secret is optional. Uncomment the entire block if you need to use it.
    # apiVersion: v1
    # data:
    #   LOKI_PASSWORD: <Base64 Basic Auth Password>
    # kind: Secret
    # metadata:
    #   name: loki-secret
    #   namespace: odigos-system
    # type: Opaque
    ```
  </Step>

  <Step>
    Apply the YAML using `kubectl`

    ```bash theme={null}
    kubectl apply -f loki.yaml
    ```
  </Step>
</Steps>
