# Monitoring

## OpenTelemetry

When run as a server and configured accordingly, OPA will emit spans to an [OpenTelemetry](https://opentelemetry.io/) collector via gRPC.

Each [REST API](/docs/rest-api) request sent to the server will start a span. If processing the request involves policy evaluation, and that in turn uses [`http.send`](/docs/policy-reference/builtins/http), those HTTP clients will emit descendant spans.

Endpoints that are polled often enough to drown out the interesting traces, such as the health check, can be left out via [`distributed_tracing.exclude_paths`](/docs/configuration#excluding-endpoints-from-tracing).

Furthermore, spans exported for policy evaluation requests will contain an attribute `opa.decision_id` of the evaluation's decision ID _if_ the server has decision logging enabled.

See [the configuration documentation](/docs/configuration#distributed-tracing) for all OpenTelemetry-related configurable options.

## Prometheus

OPA exposes an HTTP endpoint that can be used to collect performance metrics for all API calls. The Prometheus endpoint is enabled by default when you run OPA as a server.

You can enable metric collection from OPA with the following `prometheus.yml` config:

```
global:  scrape_interval: 15sscrape_configs:- job_name: "opa"  metrics_path: "/metrics"  static_configs:  - targets:    - "localhost:8181"
```

The Prometheus endpoint exports Go runtime metrics as well as HTTP request latency metrics for all handlers (e.g., `v1/data`).

| Metric name | Metric type | Description | Status |
| --- | --- | --- | --- |
| go\_gc\_duration\_seconds | summary | A summary of the GC invocation durations. | STABLE |
| go\_goroutines | gauge | Number of goroutines that currently exist. | STABLE |
| go\_info | gauge | Information about the Go environment. | STABLE |
| go\_memstats\_alloc\_bytes | gauge | Number of bytes allocated and still in use. | STABLE |
| go\_memstats\_alloc\_bytes\_total | counter | Total number of bytes allocated, even if freed. | STABLE |
| go\_memstats\_buck\_hash\_sys\_bytes | gauge | Number of bytes used by the profiling bucket hash table. | STABLE |
| go\_memstats\_frees\_total | counter | Total number of frees. | STABLE |
| go\_memstats\_gc\_sys\_bytes | gauge | Number of bytes used for garbage collection system metadata. | STABLE |
| go\_memstats\_heap\_alloc\_bytes | gauge | Number of heap bytes allocated and still in use. | STABLE |
| go\_memstats\_heap\_idle\_bytes | gauge | Number of heap bytes waiting to be used. | STABLE |
| go\_memstats\_heap\_inuse\_bytes | gauge | Number of heap bytes that are in use. | STABLE |
| go\_memstats\_heap\_objects | gauge | Number of allocated objects. | STABLE |
| go\_memstats\_heap\_released\_bytes | gauge | Number of heap bytes released to OS. | STABLE |
| go\_memstats\_heap\_sys\_bytes | gauge | Number of heap bytes obtained from system. | STABLE |
| go\_memstats\_last\_gc\_time\_seconds | gauge | Number of seconds since 1970 of last garbage collection. | STABLE |
| go\_memstats\_lookups\_total | counter | Total number of pointer lookups. | STABLE |
| go\_memstats\_mallocs\_total | counter | Total number of mallocs. | STABLE |
| go\_memstats\_mcache\_inuse\_bytes | gauge | Number of bytes in use by mcache structures. | STABLE |
| go\_memstats\_mcache\_sys\_bytes | gauge | Number of bytes used for mcache structures obtained from system. | STABLE |
| go\_memstats\_mspan\_inuse\_bytes | gauge | Number of bytes in use by mspan structures. | STABLE |
| go\_memstats\_mspan\_sys\_bytes | gauge | Number of bytes used for mspan structures obtained from system. | STABLE |
| go\_memstats\_next\_gc\_bytes | gauge | Number of heap bytes when next garbage collection will take place. | STABLE |
| go\_memstats\_other\_sys\_bytes | gauge | Number of bytes used for other system allocations. | STABLE |
| go\_memstats\_stack\_inuse\_bytes | gauge | Number of bytes in use by the stack allocator. | STABLE |
| go\_memstats\_stack\_sys\_bytes | gauge | Number of bytes obtained from system for stack allocator. | STABLE |
| go\_memstats\_sys\_bytes | gauge | Number of bytes obtained from system. | STABLE |
| go\_threads | gauge | Number of OS threads created. | STABLE |
| http\_request\_duration\_seconds | histogram | A histogram of duration for requests. | STABLE |

### Status Metrics

When Prometheus is enabled in the status plugin (see [Configuration](/docs/configuration#status)), the OPA instance's Prometheus endpoint also exposes these metrics:

| Metric name | Metric type | Description | Status |
| --- | --- | --- | --- |
| opa\_info | gauge | Information about the OPA environment. | STABLE |
| plugin\_status\_gauge | gauge | Number of plugins by name and status. | STABLE |
| bundle\_loaded\_counter | counter | Number of bundles loaded with success. | STABLE |
| bundle\_failed\_load\_counter | counter | Number of bundles that failed to load. | STABLE |
| last\_bundle\_request | gauge | Last bundle request in UNIX nanoseconds. | STABLE |
| last\_success\_bundle\_activation | gauge | Last successful bundle activation in UNIX nanoseconds. | STABLE |
| last\_success\_bundle\_download | gauge | Last successful bundle download in UNIX nanoseconds. | STABLE |
| last\_success\_bundle\_request | gauge | Last successful bundle request in UNIX nanoseconds. | STABLE |
| bundle\_loading\_duration\_ns | histogram | A histogram of duration for bundle loading. | STABLE |
| decision\_logs\_status\_gauge | gauge | Status of the last decision log upload, labeled by `code` and `http_code` (both empty on success). | STABLE |
| decision\_logs\_dropped\_rate\_limit\_exceeded\_total | counter | Incremented when decisions are dropped because `decision_logs.reporting.max_decisions_per_second` was exceeded. | STABLE |
| decision\_logs\_dropped\_buffer\_size\_limit\_exceeded\_total | counter | Incremented when decisions are dropped because the decision log buffer was full. | STABLE |
| decision\_logs\_dropped\_buffer\_size\_limit\_bytes\_exceeded\_total | counter | Incremented when decisions are dropped because `decision_logs.reporting.buffer_size_limit_bytes` was exceeded. | STABLE |
| decision\_logs\_encoding\_failure\_total | counter | Number of decisions dropped because they could not be encoded or did not fit in `upload_size_limit_bytes`. | STABLE |
| decision\_logs\_nd\_builtin\_cache\_dropped\_total | counter | Number of decisions logged without their non-deterministic builtin cache to fit in `upload_size_limit_bytes`. | STABLE |
| enc\_log\_exceeded\_upload\_size\_limit\_bytes\_total | counter | Number of decisions whose encoded size exceeded `decision_logs.reporting.upload_size_limit_bytes`. | STABLE |
| decision\_logs\_chunks\_uploaded\_total | counter | Number of decision log chunks uploaded successfully. | EXPERIMENTAL |
| decision\_logs\_chunks\_upload\_failed\_total | counter | Number of decision log chunk uploads that failed. Failed chunks are requeued and retried. | EXPERIMENTAL |
| decision\_logs\_buffer\_size\_events | gauge | Items waiting in the `event` buffer, limited by `decision_logs.reporting.buffer_size_limit_events`. | EXPERIMENTAL |
| decision\_logs\_buffer\_size\_bytes | gauge | Compressed bytes waiting in the `size` buffer, limited by `decision_logs.reporting.buffer_size_limit_bytes`. | EXPERIMENTAL |

The `decision_logs_*` and `enc_*` counters are updated with each status update and are only exported once the decision logs plugin has reported them. The `decision_logs_buffer_size_*` gauges are read at scrape time, and only the one matching `decision_logs.reporting.buffer_type` is exported.

## Health Checks

OPA exposes a `/health` API endpoint that can be used to perform health checks. See [Health API](/docs/rest-api#health-api) for details.

## Status API

OPA provides a plugin which can push status to a remote service. See [Status API](/docs/management-status) for details.