Skip to main content
Ask AI

Grafana Loki Integration

The Grafana Loki integration brings application log data into the TestRelic session workspace, enabling you to correlate API test failures with the server-side log output that occurred during the test session.

What this integration enables

  • Correlated log view — Application logs from Grafana Loki are displayed inside the API Test Workspace, aligned to the test session time window.
  • Log explorer — A searchable, filterable log viewer scoped to the exact time range of the test run.
  • Log-to-failure correlation — Map Loki log lines to specific test case failures for root-cause analysis.

Connecting Grafana Loki

  1. Navigate to Settings → Integrations.
  2. Click Connect on the Grafana Loki card.
  3. Provide:
    • Loki URL — The base URL of your Grafana Loki instance (e.g. https://loki.yourcompany.com)
    • Authentication — Username and password, or an API key, depending on your Loki configuration
    • Default log labels — Labels used to scope log queries to your application (e.g. app=backend,env=staging)
  4. Click Save to verify the connection.
Grafana Cloud Loki

If you use Grafana Cloud, your Loki URL is in the format https://logs-prod-XXXXX.grafana.net. Use your Grafana Cloud stack username and API key (not your Grafana account credentials) for authentication.

Using Loki logs in the API Workspace

When the integration is connected, the Log Explorer tab in the API Test Workspace fetches log lines from Loki for the time window of the test session:

  • Start time: run.startedAt
  • End time: run.completedAt (or startedAt + duration)

Log lines are displayed in chronological order with:

  • Timestamp — The log line timestamp.
  • Level — Log level (info, warn, error) with color coding.
  • Message — The log message content.
  • Labels — Loki label set for the log line.

Filtering logs

Use the filter bar in the Log Explorer to:

  • Filter by level — Show only errors, warnings, or info logs.
  • Search by keyword — Filter log lines containing a specific string.
  • Filter by label — Narrow to a specific service or component.

How logs are queried

TestRelic queries Loki using LogQL with a label selector based on the default labels you configured, plus a time range filter. The query is proxied through the TestRelic backend — your Loki credentials are never sent to the browser.

Example LogQL query generated:

Example generated LogQL query
{app="backend", env="staging"} | logfmt | level != "debug"