> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vijil.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Observability

> Track Dome Guardrails and Controls with OpenTelemetry, tracing, and logging.

Dome is OpenTelemetry-compliant and integrates with popular observability platforms. This guide covers telemetry setup for [Guardrails](https://docs.vijil.ai/concepts/defense/guardrail.md) and [Controls](https://docs.vijil.ai/developer-guide/protect/control-engine.md).

If you use [Trust Runtime](https://docs.vijil.ai/developer-guide/protect/trust-runtime.md), its structured audit events complement Dome telemetry with Agent identity, tool access, attestation, downgrade, and enforcement-heartbeat decisions. Every event includes the configured `agent_id`; cryptographic identity fields are available only when the runtime is attested.

## Install OpenTelemetry Support

```bash theme={null}
pip install "vijil-dome[opentelemetry]"
```

Add the `google` extra as well when you export to Google Cloud Trace, Monitoring, or Logging.

## Instrument Dome

`instrument_dome()` attaches a logging handler, a tracer, and a meter to an existing [Dome](https://docs.vijil.ai/concepts/platform/dome.md) instance. Every argument is optional, so you can enable only the signals you need:

```python theme={null}
import logging
from opentelemetry import metrics, trace

from vijil_dome import Dome
from vijil_dome.integrations.instrumentation.otel_instrumentation import instrument_dome

dome = Dome()

instrument_dome(
    dome,
    handler=logging.StreamHandler(),
    tracer=trace.get_tracer("my-agent"),
    meter=metrics.get_meter("my-agent"),
)
```

`instrument_dome()` instruments each instance once. Later calls on the same instance do nothing.

> [!NOTE]
>
> Set up your tracer and meter providers, including exporters for Jaeger, Prometheus, or another OpenTelemetry backend, before you call `instrument_dome()`.

## Instrument Controls

Use `instrument_vijil_dome()` to trace policy decisions from a `VijilDome` instance:

```python theme={null}
from opentelemetry import trace

from vijil_dome import VijilDome
from vijil_dome.integrations.instrumentation.otel_instrumentation import (
    instrument_vijil_dome,
)

dome = VijilDome(
    policy="controls.yaml",
    agent_id="agent-123",
    team_id="team-123",
    user_id="user-123",
)

instrument_vijil_dome(dome, tracer=trace.get_tracer("my-agent"))
```

The instrumented engine emits one `dome-control` span for each triggered Control. Controls that do not trigger produce no span. Calling `instrument_vijil_dome()` again on the same instance has no effect.

Each span can include these attributes:

| Attribute | Source |
| - | - |
| `control.name` | Triggered Control name |
| `control.decision` | Control action |
| `detection.confidence` | `ControlMatch.confidence` |
| `agent.id`, `team.id`, `user.id` | Identifiers stored by the `VijilDome` instance |
| `policy.id` | Control annotation named `vijil.ai/source-policy-id` |
| `rule.ids`, `rule.verdicts` | Policy rule Evaluator metadata |
| `rule.type`, `consequence.action`, `consequence.severity` | Highest-severity violated rule |

The policy and rule attributes appear only when their source annotations or Evaluator metadata are present. Other Evaluators still produce a span with the Control attributes.

## LLM Tracing Platforms

Dome exposes `apply_decorator()`, which wraps its scan methods with any decorator. Use it to add Dome activity to platforms that trace through decorators.

### Weights & Biases Weave

[Weave](https://weave-docs.wandb.ai/) is W\&B's toolkit for tracing LLM applications:

```python theme={null}
import weave
from vijil_dome import Dome

dome = Dome()
dome.apply_decorator(weave.op)
```

Calls to `guard_input()`, `guard_output()`, and their asynchronous forms then appear in your Weave dashboard with per-Guard and per-Detector details.

### AgentOps

[AgentOps](https://www.agentops.ai/) provides Agent-focused observability. Install `agentops` separately, then apply its recorder:

```python theme={null}
import os

import agentops
from vijil_dome import Dome

agentops.init(os.getenv("AGENTOPS_API_KEY"))

dome = Dome()
dome.apply_decorator(agentops.record_action())
```

> [!WARNING]
>
> The decorator you pass to `apply_decorator()` must support both synchronous and asynchronous functions, because Dome wraps both scan variants.

## Tracing

When you supply a tracer, Dome creates spans for each [Guard](https://docs.vijil.ai/concepts/defense/guard.md) and [Detector](https://docs.vijil.ai/concepts/defense/detector.md) it runs:

* **Guardrail execution**: top-level span for `guard_input()` and `guard_output()`
* **Guard execution**: nested span for each Guard in the Guardrail
* **Detector execution**: nested span for each Detector in the Guard

Each span carries the input and output of the call, execution time, error information, and the flag decision. Dome also emits one `dome-detection` span per scan, carrying `dome.guardrail`, `detection.label`, `detection.score`, `detection.method`, `dome.guard.enforced`, and the `agent.id`, `team.id`, and `user.id` values you pass to the scan. The [Vijil Console](https://docs.vijil.ai/concepts/platform/console.md) reads these spans and presents them in [Dome metrics](https://docs.vijil.ai/owner-guide/protect-in-production/observability.md).

### Span Hierarchy

```
Dome-Input-Guardrail.scan
├── Dome-Input-Guardrail.security_default.scan
│   ├── Dome-Input-Guardrail.security_default.EncodingHeuristicsDetector.scan
│   └── Dome-Input-Guardrail.security_default.MBertPromptInjectionModel.scan
└── Dome-Input-Guardrail.moderation_default.scan
    └── Dome-Input-Guardrail.moderation_default.KWBanList.scan
```

## Metrics

When you supply a meter, Dome instruments every Guardrail, Guard, and Detector with four instruments:

| Instrument | Suffix | Description |
| - | - | - |
| Requests | `-requests_total` | Requests sent to the component |
| Flagged | `-flagged_total` | Requests the component flagged |
| Errors | `-error_total` | Errors the component raised |
| Latency | `-latency_seconds` | Execution time of the component |

### Metric Naming

Names follow the pattern `[guardrail].[guard].[detector]` plus the instrument suffix. `instrument_dome()` names the two Guardrails `dome-input` and `dome-output`, and characters that OpenTelemetry does not accept in an instrument name become underscores:

* `dome_input-requests_total`
* `dome_input.security_default-flagged_total`
* `dome_input.security_default.MBertPromptInjectionModel-latency_seconds`

## Logging

Dome logs through Python loggers named `vijil.dome`. `instrument_dome()` attaches any handler you pass to those loggers.

| Level | Log Contents |
| - | - |
| `DEBUG` | Initialization of Guardrails, Guards, and Detectors, with their parameters |
| `INFO` | Inputs and outputs of each component, and Detector routing decisions |
| `WARNING` | Missing configuration, context window exceeded, timeouts, Detector errors |
| `ERROR` | Handled exceptions during execution |
| `CRITICAL` | Initialization failures and unhandled exceptions |

Set `VIJIL_LOG_PAYLOADS=1` to add a redacted payload record, which reports the payload type and length rather than its content, at `DEBUG` level for every scan.

## Best Practices

1. **Always instrument in production**: visibility is essential for security.
2. **Set appropriate log levels**: use `INFO` in production and `DEBUG` for troubleshooting.
3. **Track block rates**: sudden increases can signal an attack.
4. **Track latency**: confirm that Guards do not degrade the user experience.
5. **Alert on errors**: a rise in `-error_total` means Detectors are failing, and the `on-error` policy is deciding outcomes instead of the Detectors.

> [card] Work in Progress
>
> The programmatic observability capabilities and integrations are currently in private preview and subject to change.

## Next Steps

> [card] [Trust Runtime](https://docs.vijil.ai/developer-guide/protect/trust-runtime.md)
>
> Capture identity and policy decisions

> [card] [Configure Guardrails](https://docs.vijil.ai/developer-guide/protect/configuring-guardrails.md)
>
> Guard configuration options

> [card] [Use Guardrails](https://docs.vijil.ai/developer-guide/protect/using-guardrails.md)
>
> Runtime integration patterns

> [card] [Custom Detectors](https://docs.vijil.ai/developer-guide/protect/custom-detectors.md)
>
> Build custom detection methods


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.