# 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.

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 |

## 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.