Create SLOs in Grafana Cloud using Frontend Observability signals
Grafana Cloud

Create SLOs in Grafana Cloud using Frontend Observability signals

This guide describes how to create Service Level Objectives (SLOs), using Time to First Byte (TTFB) being under 800ms as the success criterion.

Transform logs into metrics

Since Frontend Observability signals are stored in Loki as logs, you’ll first transform the logs into metrics using recording rules. After the metrics are available, you can create the SLO using the Grafana Cloud SLO wizard.

Identify relevant logs

Ensure your log entries include fields for TTFB, such as:

  • ttfb_duration (for example, TTFB time in milliseconds)
  • status_code (for example, HTTP response codes)

Define recording rules

To create an SLO, you need the following metrics:

  • ttfb_success: Number of successful TTFB observations (for example, those with TTFB < threshold and a 2xx status).
  • ttfb_total: Total number of TTFB observations.

To create the metrics needed for your SLO, use the following LogQL queries as recording rules in your Prometheus configuration.

Define ttfb_success

Enter the following code to define your recording rule:

logql
sum(count_over_time({kind="measurement",app_id="1129"} | logfmt | ttfb <=800[1m])) by (app, app_id)

where:

  • kind="measurement": Filters logs to include only those marked as measurements
  • app_id="1129": Filters logs for the specific application
  • logfmt: Parses structured log fields
  • ttfb <= 800: Ensures only logs with TTFB less than or equal to 800ms are considered
  • count_over_time: Calculates the count of matching logs over a 1-minute interval
  • sum by (app, app_id): Aggregates the results by application and application ID

A step from the new recording rule wizard showing how to define a recording rule for the success metric

Define ttfb_total

For ttfb_total, count all TTFB observations without filtering for success criteria. Enter the following code to define your recording rule:

logql
sum(count_over_time(({kind="measurement",app_id="1129"} | logfmt | ttfb=``)[1m])) by (app, app_id)

where:

  • kind="measurement": Filters logs to include only those marked as measurements
  • app_id="1129": Filters logs for the specific application
  • logfmt: Parses structured log fields
  • ttfb='': Ensures the TTFB field is present in the log entry
  • count_over_time: Calculates the count of matching logs over a 1-minute interval
  • sum by (app, app_id): Aggregates the results by application and application ID

A step from the new recording rule wizard showing how to define a recording rule for the total metric

Create the SLO in Grafana Cloud

Use the SLO Wizard to create your SLO.

Open the SLO Wizard

  1. In Grafana Cloud, navigate to Alerts & IRM > SLO > Manage SLOs. or search “Manage SLOs in the command palette.”
  2. Click Create SLO to open the wizard.

Define the SLO

  1. Choose the Success and Total Requests (SLI) option.
  2. Select:
    1. Success Metric: ttfb_success
    2. Total Metric: ttfb_total

A step from the create SLO wizard showing how to define the service level indicator the success metric and total metric

Set the SLO target

  1. Define your target percentage for success (for example, 99.5% for SLO compliance).
  2. Specify the time window (for example, 30 days).

Optional configuration

  • Add labels to categorize the SLO (for example, service="frontend").
  • Set custom error budget alerts for proactive monitoring.

Review and Save

  1. Review the SLO definition.
  2. Click Create to save the SLO.

Additional notes

  • Threshold Adjustments: Ensure the ttfb_success threshold aligns with user expectations and SLA requirements.
  • Validation: Use test queries in Grafana Explore to validate the ttfb_success and ttfb_total metrics before creating the SLO.
  • Scaling: For multiple services or endpoints, customize the service or path labels in recording rules.

The above steps show how you can create effective SLOs in Grafana Cloud, ensuring your frontend performance meets user and business expectations.