|
| 1 | +--- |
| 2 | +applyTo: "util/opentelemetry-util-genai/**" |
| 3 | +--- |
| 4 | + |
| 5 | +Review rules for PRs touching `util/opentelemetry-util-genai/**`. Flag violations with a link to |
| 6 | +the rule. |
| 7 | + |
| 8 | +## 0. Reviewer mindset |
| 9 | + |
| 10 | +Review as long-term maintainer. Every GenAI instrumentation in the repo depends on this package; |
| 11 | +churn breaks them. Default to back-compat changes. Every public addition is a long-term |
| 12 | +commitment — limit public API. |
| 13 | + |
| 14 | +## 1. Semconv first |
| 15 | + |
| 16 | +No code without semconv. If a signal, attribute, or operation is not in the |
| 17 | +[GenAI semconv](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/gen-ai/), |
| 18 | +land the semconv change first. |
| 19 | + |
| 20 | +## 2. Semantic conventions |
| 21 | + |
| 22 | +- Names (attributes, operations, spans) must match semconv exactly. |
| 23 | +- Use matching `opentelemetry.semconv` modules per namespace (`gen_ai`, `server`, `error`, …). |
| 24 | + Do not hardcode name strings if a constant exists. |
| 25 | +- Shared attributes must behave consistently across invocation types (same conditions, same |
| 26 | + defaults). If semconv marks an attribute for multiple invocations, set it on all. |
| 27 | + |
| 28 | +## 3. API backwards compatibility |
| 29 | + |
| 30 | +- Do not remove or rename public objects. Deprecate first via a docstring note pointing to the |
| 31 | + replacement (not `@deprecated` — unreliable). |
| 32 | +- Private modules and module-private objects start with `_`. |
| 33 | +- Default to internal (`_`-prefixed) unless instrumentations need it public. |
| 34 | + |
| 35 | +## 4. Invocation shape |
| 36 | + |
| 37 | +- `start_*()` factories must accept all sampling-relevant semconv attributes as parameters. |
| 38 | + Attributes also marked required by semconv must be required parameters (no default value). |
| 39 | +- `start_*()` factories must map 1:1 to distinct semconv operation types (inference, embeddings, |
| 40 | + tool execution, agent invocation, workflow invocation). Names must match the operation |
| 41 | + unambiguously — e.g., `create_agent` vs `invoke_agent` are distinct ops; `start_agent()` alone |
| 42 | + is ambiguous. |
| 43 | +- Each operation exposes both a factory (`start_inference(...)`) and a context-manager |
| 44 | + (`inference(...)`) form. |
| 45 | +- Never construct invocation types directly (`InferenceInvocation(...)`) — skips span creation, |
| 46 | + silent no-ops. Always use `handler.start_*()` or the context manager. |
| 47 | + |
| 48 | +## 5. Exception handling |
| 49 | + |
| 50 | +- When catching exceptions from the underlying library to record telemetry, always re-raise the |
| 51 | + original exception unmodified. |
| 52 | +- Do not raise **new** exceptions in utils code. |
| 53 | + |
| 54 | +## 6. Performance |
| 55 | + |
| 56 | +Keep the hot path tight: |
| 57 | + |
| 58 | +- Avoid per-invocation allocations; do not accumulate state unboundedly. |
| 59 | +- Skip content capture when content capture is disabled. |
| 60 | +- Skip setting span attributes when the span is not recording. |
| 61 | +- Still record attributes that feed metrics — metric recording is independent of span sampling. |
| 62 | + |
| 63 | +## 7. DRY |
| 64 | + |
| 65 | +Do not copy-paste logic across invocation types. Extract shared helpers. |
| 66 | + |
| 67 | +## 8. Tests |
| 68 | + |
| 69 | +- Every new operation type or attribute change needs tests asserting exact attribute names **and |
| 70 | + value types**, checked against semconv. |
| 71 | +- Cover success (`invocation.stop()`), failure (`invocation.fail(exc)`), and conditional |
| 72 | + attribute logic. |
| 73 | +- Prefer public API in tests. |
| 74 | + |
| 75 | +## 9. Documentation |
| 76 | + |
| 77 | +- Docstrings for invocation types and span/event helpers must link to the corresponding semconv |
| 78 | + op. |
| 79 | +- When adding/changing attributes, update the docstring with what is set and when. |
| 80 | + |
| 81 | +## 10. PR description |
| 82 | + |
| 83 | +- Cover which part of the GenAI semconv the change implements or follows (when applicable) and |
| 84 | + how instrumentations should consume it. |
| 85 | + |
| 86 | +See also [AGENTS.md](../../AGENTS.md) for general repo rules. |
0 commit comments