Skip to content

Commit f1eb558

Browse files
authored
Add GenAI test util (#11)
* Add genai test utils
1 parent f0bb0bb commit f1eb558

16 files changed

Lines changed: 672 additions & 737 deletions

File tree

.github/instructions/instrumentation-genai.instructions.md

Lines changed: 0 additions & 66 deletions
This file was deleted.

.github/instructions/instrumentation.instructions.md

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,64 @@ prefer opt-in or additive. Breaking changes need explicit justification in the P
2020
## 1. Maintenance commitment
2121

2222
- New instrumentations require contributor commitment to long-term maintenance. See
23-
[Expectations from contributors](../../CONTRIBUTING.md#expectations-from-contributors) and the
24-
general [instrumentation checklist](../../CONTRIBUTING.md#guideline-for-instrumentations).
23+
[Expectations from contributors](../../CONTRIBUTING.md#expectations-from-contributors), the
24+
general [instrumentation checklist](../../CONTRIBUTING.md#guideline-for-instrumentations), and
25+
the GenAI-specific expectations in
26+
[`CONTRIBUTING.md#guideline-for-genai-instrumentations`](../../CONTRIBUTING.md#guideline-for-genai-instrumentations).
2527

26-
## 2. Semantic conventions
28+
## 2. Telemetry and configuration via `opentelemetry-util-genai`
2729

30+
- Spans, logs, metrics, and events must go through `opentelemetry-util-genai`. Direct use of
31+
`Tracer`, `Meter`, `Logger`, or event APIs is not allowed.
32+
- Content capture, hooks, and other cross-cutting configuration are owned by the util.
33+
Instrumentations must not introduce their own env vars, settings, or hook interfaces.
34+
- Message content, prompts, and tool call arguments must only be set through the util's content
35+
capture path — never as unconditional span/log attributes.
36+
- Adding attributes to invocations produced by the util is fine.
37+
- If a capability is missing in `opentelemetry-util-genai`, land it in the util first.
38+
39+
## 3. Semantic conventions
40+
41+
- Attributes, spans, events, and metrics must match the
42+
[GenAI semantic conventions](https://github.com/open-telemetry/semantic-conventions-genai/tree/main/docs/gen-ai).
2843
- Attribute names must come from the semconv attribute modules, not hardcoded strings. Use the
2944
module matching the namespace under `opentelemetry.semconv` (e.g. `server_attributes`,
30-
`error_attributes`, `http_attributes`, `db_attributes`, …).
45+
`error_attributes`, `http_attributes`, `db_attributes`, …). `gen_ai.*` attribute names must
46+
come from `opentelemetry.semconv._incubating.attributes.gen_ai_attributes`.
3147
- For attributes with a well-known value set in semconv, use the generated enum from the same
32-
modules instead of string literals.
48+
module (e.g. `GenAiOutputTypeValues` for `gen_ai.output.type`) instead of string literals.
3349
- If a signal is not in semconv, wait until semconv lands.
3450

35-
## 3. Exception handling
51+
## 4. Exception handling
3652

3753
- When catching exceptions from the underlying library to record telemetry, always re-raise the
3854
original exception unmodified.
3955
- Do not raise **new** exceptions in instrumentation/telemetry code.
4056

41-
## 4. Tests
57+
## 5. Tests
4258

4359
- For every public API instrumented, cover sync/async variants when both exist.
44-
- Cover happy path and error scenarios.
60+
- Cover streaming and non-streaming variants when both exist.
61+
- Cover happy path and error scenarios. For error scenarios, at minimum include: provider error /
62+
endpoint unavailable, stream interrupted by network, stream closed early by the caller.
63+
- Use recorded VCR cassettes for provider calls. No live-key-only tests; skipping on missing key
64+
is not acceptable.
4565
- Tests must verify exact attribute names **and value types**, checked against the semconv spec.
4666
- Test against oldest and latest supported library versions via `tests/requirements.{oldest,latest}.txt`
4767
and `{oldest,latest}` `tox.ini` factors.
68+
- `tests/conftest.py` must consume the shared fixtures from `opentelemetry.test_util_genai`
69+
(`from opentelemetry.test_util_genai.fixtures import *` and
70+
`from opentelemetry.test_util_genai.vcr import fixture_vcr, scrub_response_headers`). Do not
71+
re-implement in-memory provider/exporter setup or the VCR pretty-print serializer locally.
72+
73+
## 6. Examples
74+
75+
New instrumentations must ship a minimal example under the package's `examples/`, with both a
76+
`manual/` and a `zero-code/` (auto-instrumentation) variant.
77+
78+
## 7. PR description
79+
80+
- Cover which part of the GenAI semconv the change implements or follows (when applicable) and
81+
how instrumentations should consume it.
4882

4983
See also [AGENTS.md](../../AGENTS.md) for general repo rules.

.github/instructions/util-genai.instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ commitment — limit public API.
1414
## 1. Semconv first
1515

1616
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/),
17+
[GenAI semconv](https://github.com/open-telemetry/semantic-conventions-genai/blob/main/docs/gen-ai/),
1818
land the semconv change first.
1919

2020
## 2. Semantic conventions

AGENTS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ comment - not in the PR description.
3535

3636
- `instrumentation/` - GenAI instrumentation packages
3737
- `util/opentelemetry-util-genai/` - shared GenAI utilities
38+
- `util/opentelemetry-test-util-genai/` - shared test fixtures and assertion helpers
39+
(workspace-internal, not published)
3840

3941
Instrumentation packages live under `src/opentelemetry/instrumentation/{name}/` with their own
4042
`pyproject.toml` and `tests/`. The util package follows the equivalent layout under
@@ -92,6 +94,10 @@ Apply to packages under `instrumentation/`.
9294
- Tests must verify exact attribute names **and value types**, checked against the semconv spec.
9395
- Test against oldest and latest supported library versions via `tests/requirements.{oldest,latest}.txt`
9496
and `{oldest,latest}` `tox.ini` factors.
97+
- `tests/conftest.py` must consume the shared fixtures from
98+
`opentelemetry.test_util_genai` (`from opentelemetry.test_util_genai.fixtures import *` and
99+
`from opentelemetry.test_util_genai.vcr import fixture_vcr, scrub_response_headers`) rather
100+
than re-implementing provider/exporter/VCR plumbing.
95101

96102
The parallel PR-review rules live in
97103
[`.github/instructions/instrumentation.instructions.md`](.github/instructions/instrumentation.instructions.md)

0 commit comments

Comments
 (0)