Skip to main content
Send logs to Grafana Loki — self-hosted or Grafana Cloud. Streams are labeled with service_name and level; the log line itself is JSON, ready for LogQL’s | json parser.

Setup

  1. Have a Loki instance (e.g. http://localhost:3100) or a Grafana Cloud stack (find the push URL and credentials under Connections → Loki).
  2. Set the environment variables:
  1. Wire the transport:
  1. Query in Grafana: {service_name="my-api"} | json.

Environment Variables

Options

Plus the shared batching options: maxBatchSize, flushIntervalMs, timeout, retries — see the overview. Keep labels low-cardinality (environment, region) — per-request values like request IDs belong in the log line, where LogQL can still filter them, not in labels, where they explode Loki’s index.

Payload

Each batch groups entries by level into streams:
Query with LogQL, e.g. {service_name="my-api", level="ERROR"} | json | durationMs > 1000.

Troubleshooting

  • 401 — Grafana Cloud needs both LOKI_USERNAME (instance ID) and LOKI_PASSWORD (token with logs:write).
  • 400 “entry too far behind” — Loki rejects out-of-order or too-old timestamps; check the server clock.
  • 429 — per-tenant ingestion limits hit; raise flushIntervalMs/maxBatchSize to send fewer, larger batches, or raise the tenant limits.