# Grafana Data Source Provisioning
# Auto-configures Loki as a data source in Grafana

apiVersion: 1

datasources:
  - name: Loki
    type: loki
    access: proxy
    url: http://loki:3100
    isDefault: true
    editable: true
    jsonData:
      maxLines: 1000
      derivedFields:
        # Extract trace ID from logs for distributed tracing
        - datasourceUid: tempo
          matcherRegex: "traceId=(\\w+)"
          name: TraceID
          url: "$${__value.raw}"
        # Extract request ID for correlation
        - matcherRegex: "requestId=(\\w+)"
          name: RequestID
          url: "$${__value.raw}"
    version: 1

  # Optional: Add Prometheus if you have metrics
  # - name: Prometheus
  #   type: prometheus
  #   access: proxy
  #   url: http://prometheus:9090
  #   isDefault: false
  #   editable: true
  #   jsonData:
  #     timeInterval: 15s
  #   version: 1

  # Optional: Add Tempo for distributed tracing
  # - name: Tempo
  #   type: tempo
  #   access: proxy
  #   url: http://tempo:3200
  #   isDefault: false
  #   editable: true
  #   version: 1
