# Tracing

`GenerationResult.trace` exposes a `dryv.trace/v1alpha1` graph, and artifacts keep compact `TraceReference` links into it.

## Separate graphs

Semantic, selection/partition, artifact, requirement, resolution, render and write/tooling traces are separate graphs. They link through stable structured identities (semantic id, selection key, partition key, template key, invocation id, file id, template and requirement digests, provider identity). They never use memory addresses, random ids or list positions. Transport correlation ids can be ephemeral.

## A full file explanation

```text
file         src/users/user.entity.ts
pack         example.typescript
selection    storageSchemas · subject schema · matched users.User · reason facet=storage
partition    scope each · key schema:users.User
template     entity · templates/src/{entity}/$(name).entity.ts.hbs
output       name user · path users · symbol UserEntity
requirements file.symbol, schema.fields[].name.camel, …
renderer     provider + version
result       output digest
```

Symbols, dependencies, exports, context values, requirement sources and subtree fallbacks can each be explained the same way. Failure traces keep every stage that succeeded before the failure.

## Provenance classes

| Class              | Source                                                 |
| ------------------ | ------------------------------------------------------ |
| `semantic`         | canonical meaning                                      |
| `semantic-derived` | deterministic derivation (name variant, resolved path) |
| `planning`         | file, path, symbol, dependency or export facts         |
| `scope-metadata`   | application, group or feature metadata                 |

Traces store references and digests, not snapshots of values.

## Determinism contract

With the same IR, pack, templates, usage and provider versions, all of these must be identical: selections, partitions, file identities, paths, symbols, edges, export streams, requirements, materialised context, render requests, rendered bytes and the write plan. Replay digests cover the plan, the template closure, the requirements, the projected context and the rendered bytes.

## Cache rules

A cache hit changes cost, not meaning, and the trace still shows the source. Safe keys include `(renderer version, template closure, vocabulary version) → requirements`, `(canonical id, naming variant) → name`, and `(artifact, producer) → relative path`. Never cache recursively expanded graphs.

## Metrics

Workspace and plan size, context demand versus materialisation, projection cache activity, context bytes and elapsed time.

## Privacy

Traces never store credentials or environment variable values (they record that `VIRTUAL_ENV` was required, not its value). Semantic values in traces are summarised or digested.
