Files
Stephan Renatus 13e9488921 server+topdown+logs: feed arbitrary extra info from Data API to topdown and back (#8570)
Wrapping projects can now attach custom metadata to Data API requests
and have evaluation produce response metadata.

Introduce two distinct metadata paths:

  - Request (incoming) metadata: parsed from extra top-level keys in the request
body, made available to builtins via `BuiltinContext.RequestMetadata`.
    Logged in the decision log under `Custom["request_metadata"]`.

- Response (outgoing) metadata: a separate map (`BuiltinContext.ResponseMetadata`)
    that builtins can populate during evaluation. Only included in the
    API response and decision log (`Custom["response_metadata"]`)
    if non-empty.

In vanilla OPA, no builtins write response metadata, so responses are
unchanged. The request metadata map is only allocated when the request
carries extra fields; the outgoing map is one empty map per request.

To avoid conflicts with future OPA top-level keys, callers should use a
namespaced key: `{"input": {...}, "com.example.opa/md": {...}}`.

```mermaid
flowchart LR
    req["POST /v1/data\n{input, com.example.opa/md}"]
    parse["readInputPostV1"]
    eval["topdown eval"]
    resp["API response"]
    dl["decision log"]

    req --> parse
    parse -- "reqMetadata" --> eval
    parse -- "reqMetadata" --> dl
    eval -- "respMetadata\n(if non-empty)" --> resp
    eval -- "respMetadata\n(if non-empty)" --> dl
    eval -. "BuiltinContext\n.RequestMetadata\n.ResponseMetadata" .-> eval
```

---------

Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
2026-04-28 12:58:18 +00:00
..