Adding LGTM data sources in Grafana connects the UI to the log, trace, and metrics backends that store telemetry. A self-managed stack usually needs a Loki data source for logs, a Tempo data source for traces, and a Prometheus-compatible data source for metrics from Mimir or Prometheus.

Provisioning keeps the data source names, backend URLs, and unique IDs in a version-controlled file instead of relying on manual UI clicks. The URLs must be reachable from the Grafana server or container, so service names such as loki, tempo, and mimir work inside a shared Docker Compose network while localhost usually points back at Grafana itself.

Use fixed data source UIDs when later guides need trace-to-log links, dashboards, alert rules, or panel JSON to reference the same backends. A saved connection should pass Save & test in the UI, and Explore should return one log stream, trace, or metric from each backend before dashboards depend on the stack.

Steps to add LGTM data sources in Grafana:

  1. Create the Grafana provisioning directory in the Compose project.
    $ mkdir -p grafana/provisioning/datasources
  2. Save the LGTM data source provisioning file as lgtm.yaml in that directory.
    lgtm.yaml
    apiVersion: 1
    
    datasources:
      - name: Loki
        uid: loki
        type: loki
        access: proxy
        url: http://loki:3100
        jsonData:
          maxLines: 1000
    
      - name: Tempo
        uid: tempo
        type: tempo
        access: proxy
        url: http://tempo:3200
    
      - name: Mimir
        uid: mimir
        type: prometheus
        access: proxy
        url: http://mimir:9009/prometheus
        jsonData:
          httpMethod: POST

    Mimir exposes a Prometheus-compatible query API, so Grafana uses the Prometheus data source type for it.

  3. Mount the provisioning directory into the Grafana service.
    compose.yaml
    services:
      grafana:
        image: grafana/grafana:latest
        ports:
          - "3000:3000"
        volumes:
          - type: bind
            source: ./grafana/provisioning
            target: /etc/grafana/provisioning
            read_only: true

    Merge this service block with the existing stack definition instead of replacing the backend services.

  4. Recreate the Grafana container so it reads the provisioning file.
    $ docker compose up -d grafana
    Container lgtm-grafana-1  Recreate
    Container lgtm-grafana-1  Started
  5. List the data sources through the Grafana API.
    $ GRAFANA_URL=http://127.0.0.1:3000
    $ curl --silent \
      --user admin:admin \
      "$GRAFANA_URL/api/datasources"
    [
      {
        "id": 1,
        "uid": "loki",
        "name": "Loki",
        "type": "loki",
        "url": "http://loki:3100"
      },
      {
        "id": 2,
        "uid": "tempo",
        "name": "Tempo",
        "type": "tempo",
        "url": "http://tempo:3200"
      },
      {
        "id": 3,
        "uid": "mimir",
        "name": "Mimir",
        "type": "prometheus",
        "url": "http://mimir:9009/prometheus"
      }
    ]

    Replace admin / admin before saving this pattern in shared scripts or CI logs.

  6. Open ConnectionsData sources in Grafana.
  7. Select each LGTM data source and click Save & test.
  8. Open Explore and run one smoke query per backend.

    Use {job=~".+"} for Loki, a recent trace search for Tempo, and up or another known series for Mimir after metrics have been written.