Glossary · O

Observability as Code

Practice of defining dashboards, alert rules, SLOs and telemetry configuration as versioned code that is reviewed and deployed automatically.

By Obseria TeamUpdated

Definition

Observability as Code is the practice of defining observability configuration, such as dashboards, alert rules, SLOs, instrumentation and telemetry pipelines, in declarative, version-controlled files. Changes go through code review and CI/CD instead of manual clicks in a user interface, so the monitoring setup stays reproducible, auditable and consistent across teams and environments.

What is Observability as Code?

Observability as Code applies the ideas of Infrastructure as Code to monitoring and observability. Instead of building a dashboard by hand, clicking together an alert rule or editing a collector configuration directly on a server, teams describe these objects in text files. The files live in Git next to the application code, are reviewed in pull requests and are rolled out automatically by a pipeline.

The motivation is simple: manually created monitoring drifts. Dashboards are copied and changed per team, alert thresholds are adjusted during an incident and never reset, and nobody knows who changed what. When the configuration is code, the current state is visible in the repository, every change has an author and a reason, and a broken change can be reverted like any other commit.

What belongs in code

Almost every part of an observability setup can be described declaratively:

  • Instrumentation and collection: OpenTelemetry SDK settings, resource attributes and the YAML configuration of the OpenTelemetry Collector with its receivers, processors and exporters.
  • Telemetry pipelines: filters, sampling rules, PII masking and routing, as in a telemetry pipeline.
  • Alert rules: for example Prometheus alerting and recording rules in YAML, including thresholds, durations, labels and runbook links.
  • Dashboards: exported as JSON or generated from code with libraries and templating tools.
  • SLOs: objectives, SLIs and error budget policies, for example in the vendor-neutral OpenSLO format.
  • Routing and on-call: notification channels, escalation policies and maintenance windows.

How it works in practice

A typical workflow looks like this:

  1. An engineer changes an alert rule or adds a dashboard panel in a branch.
  2. CI validates the change: syntax checks, linting, unit tests for alert rules (Prometheus ships promtool test rules for this) and a plan or diff against the live state.
  3. A colleague reviews the pull request, just like application code.
  4. After the merge, the pipeline applies the change through the platform's API, a CLI or a tool such as Terraform.

A minimal Prometheus alert rule as code:

groups:
- name: checkout
  rules:
  - alert: CheckoutHighErrorRate
    expr: sum(rate(http_requests_total{service="checkout",code=~"5.."}[5m]))
          / sum(rate(http_requests_total{service="checkout"}[5m])) > 0.02
    for: 10m
    labels:
      severity: page
    annotations:
      runbook_url: https://wiki.example.com/runbooks/checkout-errors

Common tools and formats

There is no single standard, but a few building blocks are widespread. Terraform and OpenTofu providers exist for many monitoring platforms. Grafana dashboards are JSON documents and can be generated with Jsonnet libraries or SDKs. Prometheus rules are YAML files. The OpenTelemetry Collector is configured entirely in YAML. OpenSLO describes SLOs in a vendor-neutral YAML schema, and Perses, a CNCF project, focuses on dashboards as code. In Kubernetes, many teams manage monitoring objects as custom resources, for example the PrometheusRule and ServiceMonitor resources of the Prometheus Operator, deployed with GitOps tools.

Benefits and pitfalls

The benefits are reproducibility (a new environment receives the same monitoring automatically), traceability (Git history as audit trail), consistency through shared modules and faster onboarding because each service gets a standard set of dashboards and alerts from a template. This makes Observability as Code a natural part of platform engineering.

Typical pitfalls:

  • Drift: if people still edit dashboards in the UI, the code no longer reflects reality. Decide which objects are code-owned and detect drift regularly.
  • Over-templating: generic templates that produce hundreds of alerts nobody needs lead straight to alert fatigue.
  • Secrets: API keys and webhook URLs do not belong in the repository; use a secret manager.
  • Exploration: ad-hoc investigation during an incident should stay possible in the UI. Promote only useful results into code.

Getting started

You do not have to convert everything at once. A pragmatic path is to start with the objects that hurt most when they drift: alert rules and SLOs. Export the existing configuration, commit it to a repository, add validation in CI and make the pipeline the only way to change these objects. Next, create a service template that gives every new service a standard dashboard, a small set of symptom-based alerts on the golden signals and an SLO. Collector configuration and pipeline rules follow naturally, because they are already files. Finally, document ownership: each alert and dashboard should name the team responsible, so code review reaches the right people and orphaned objects can be found and removed.

How Obseria helps

Obseria is OpenTelemetry-native, so collector and SDK configuration stays standard, portable code. Dashboards can be exported and imported as JSON, and dashboards, alert rules and SLOs can be managed through the API, the CLI or Terraform, so they live in the same repository as the service. Alert queries can be written in PromQL, OQL or SQL.

Frequently asked questions

The terms are often used interchangeably. Monitoring as Code usually refers to checks, alerts and dashboards, while Observability as Code also includes instrumentation, telemetry pipelines and SLO definitions.

No. Terraform is common, but any declarative format applied automatically works: YAML rules, JSON dashboards, Kubernetes custom resources with GitOps, or scripts that call a platform API from CI/CD.

Validate syntax in CI, run unit tests with synthetic time series (for Prometheus with promtool), and check that every alert has a severity, an owner and a runbook link before merging.

Core dashboards per service, alerts and SLOs should be code-owned. Personal or exploratory dashboards can stay in the UI, as long as it is clear which objects the repository controls.

Put these concepts into practice

Try Obseria free for 14 days, with OpenTelemetry and no proprietary agents.