Skip to content

Commit 1711efa

Browse files
committed
expand beyond genai, create common files
1 parent db6291a commit 1711efa

5 files changed

Lines changed: 113 additions & 61 deletions

File tree

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

Lines changed: 17 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,9 @@ applyTo: "instrumentation-genai/**"
44

55
Review rules for PRs touching `instrumentation-genai/**`. Flag violations with a link to the rule.
66

7-
## 0. Reviewer mindset
8-
9-
Review as long-term maintainer.
10-
11-
For new instrumentations, consult upstream library docs and judge:
12-
13-
- Does the library already emit its own telemetry, making this instrumentation redundant?
14-
- Is the library used widely enough to warrant a package in this repo?
15-
- Does it avoid unbounded in-memory accumulation or other side-effects?
16-
- Does the library raise exceptions that would reach user code through our wrapping?
17-
18-
For changes to existing instrumentations: prefer back-compat. Break users only for a real reason;
19-
prefer opt-in or additive. Breaking changes need explicit justification in the PR.
7+
These rules are additive to
8+
[`instrumentation.instructions.md`](instrumentation.instructions.md), which applies to all
9+
instrumentation packages.
2010

2111
## 1. Scope of `instrumentation-genai/`
2212

@@ -29,14 +19,11 @@ Only for:
2919
Database clients (including vector DBs used outside a GenAI-specific client) and CLI libs belong
3020
in `instrumentation/`, not here.
3121

32-
## 2. Component ownership & maintenance commitment
22+
## 2. GenAI component ownership
3323

34-
- New instrumentations must add an entry under the correct folder in
35-
[`component_owners.yml`](../component_owners.yml) in the same PR. Contributor must commit to
36-
long-term maintenance. See
37-
[Expectations from contributors](../../CONTRIBUTING.md#expectations-from-contributors),
38-
[Guideline for GenAI instrumentations](../../CONTRIBUTING.md#guideline-for-genai-instrumentations),
39-
and the general [instrumentation checklist](../../CONTRIBUTING.md#guideline-for-instrumentations).
24+
See [`CONTRIBUTING.md#guideline-for-genai-instrumentations`](../../CONTRIBUTING.md#guideline-for-genai-instrumentations)
25+
for GenAI-specific maintenance expectations on top of the general
26+
[instrumentation checklist](../../CONTRIBUTING.md#guideline-for-instrumentations).
4027

4128
## 3. Telemetry and configuration via `opentelemetry-util-genai`
4229

@@ -49,44 +36,29 @@ in `instrumentation/`, not here.
4936
- Adding attributes to invocations produced by the util is fine.
5037
- If a capability is missing in `opentelemetry-util-genai`, land it in the util first.
5138

52-
## 4. Semantic conventions
39+
## 4. GenAI semantic conventions
5340

5441
- Attributes, spans, events, and metrics must match the
5542
[GenAI semantic conventions](https://github.com/open-telemetry/semantic-conventions/tree/main/docs/gen-ai).
56-
- If a signal is not in semconv, wait until semconv lands.
57-
- Attribute names must come from the semconv attribute modules, not hardcoded strings:
58-
- `gen_ai.*`: `opentelemetry.semconv._incubating.attributes.gen_ai_attributes`
59-
- `server.*`: `opentelemetry.semconv.attributes.server_attributes`
60-
- `error.*`: `opentelemetry.semconv.attributes.error_attributes`
61-
- other namespaces: corresponding module under `opentelemetry.semconv`
62-
- For attributes with a well-known value set in semconv, use the generated enum from the same
63-
modules (e.g. `GenAiOutputTypeValues` for `gen_ai.output.type`) instead of string literals.
64-
65-
## 5. Exception handling
66-
67-
- No `raise` statements in instrumentation/telemetry code. Validation belongs in tests and
68-
callers.
69-
- When catching library exceptions to record telemetry, re-raise the original exception
70-
unmodified.
43+
- `gen_ai.*` attribute names must come from
44+
`opentelemetry.semconv._incubating.attributes.gen_ai_attributes`.
45+
- For attributes with a well-known value set, use the generated enum from the same module
46+
(e.g. `GenAiOutputTypeValues` for `gen_ai.output.type`) instead of string literals.
7147

72-
## 6. Tests
48+
## 5. Tests
7349

7450
- Use recorded VCR cassettes for provider calls. No live-key-only tests; skipping on missing key
7551
is not acceptable.
76-
- For every public API touched, cover sync/async and streaming/non-streaming variants when both
77-
exist.
78-
- Cover happy path and error scenarios, at minimum: provider error / endpoint unavailable, stream
52+
- Cover streaming and non-streaming variants when both exist.
53+
- For error scenarios, at minimum include: provider error / endpoint unavailable, stream
7954
interrupted by network, stream closed early by the caller.
80-
- Tests must verify exact attribute names **and value types**, checked against the semconv spec.
81-
- Test against oldest and latest supported library versions via `tests/requirements.{oldest,latest}.txt`
82-
and `{oldest,latest}` `tox.ini` factors (see existing GenAI packages).
8355

84-
## 7. Examples
56+
## 6. Examples
8557

8658
New instrumentations must ship a minimal example under the package's `examples/`, with both a
8759
`manual/` and a `zero-code/` (auto-instrumentation) variant.
8860

89-
## 8. PR description
61+
## 7. PR description
9062

9163
- Cover which part of the GenAI semconv the change implements or follows (when applicable) and
9264
how instrumentations should consume it.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
applyTo: "{instrumentation,instrumentation-genai}/**"
3+
---
4+
5+
Review rules for PRs touching `instrumentation/**` and `instrumentation-genai/**`. Flag violations
6+
with a link to the rule.
7+
8+
## 0. Reviewer mindset
9+
10+
Review as long-term maintainer.
11+
12+
For new instrumentations, consult upstream library docs and judge:
13+
14+
- Does the library already emit its own telemetry, making this instrumentation redundant?
15+
- Is the library used widely enough to warrant a package in this repo?
16+
- Does it avoid unbounded in-memory accumulation or other side-effects?
17+
18+
For changes to existing instrumentations: prefer back-compat. Break users only for a real reason;
19+
prefer opt-in or additive. Breaking changes need explicit justification in the PR.
20+
21+
## 1. Component ownership & maintenance commitment
22+
23+
- New instrumentations must add an entry under the correct folder in
24+
[`component_owners.yml`](../component_owners.yml) in the same PR. Contributor must commit to
25+
long-term maintenance. See
26+
[Expectations from contributors](../../CONTRIBUTING.md#expectations-from-contributors) and the
27+
general [instrumentation checklist](../../CONTRIBUTING.md#guideline-for-instrumentations).
28+
29+
## 2. Semantic conventions
30+
31+
- Attribute names must come from the semconv attribute modules, not hardcoded strings. Use the
32+
module matching the namespace under `opentelemetry.semconv` (e.g. `server_attributes`,
33+
`error_attributes`, `http_attributes`, `db_attributes`, …).
34+
- For attributes with a well-known value set in semconv, use the generated enum from the same
35+
modules instead of string literals.
36+
- If a signal is not in semconv, wait until semconv lands.
37+
38+
## 3. Exception handling
39+
40+
- No new `raise` statements in instrumentation/telemetry code.
41+
- When catching library exceptions to record telemetry, re-raise the original exception
42+
unmodified.
43+
44+
## 4. Tests
45+
46+
- For every public API instrumented, cover sync/async variants when both exist.
47+
- Cover happy path and error scenarios.
48+
- Tests must verify exact attribute names **and value types**, checked against the semconv spec.
49+
- Test against oldest and latest supported library versions via `tests/requirements.{oldest,latest}.txt`
50+
and `{oldest,latest}` `tox.ini` factors.
51+
52+
See also [AGENTS.md](../../AGENTS.md) for general repo rules.

AGENTS.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@ Follow the PR scoping guidance in [CONTRIBUTING.md](CONTRIBUTING.md). Keep AI-as
1414
isolated to the requested change and never include unrelated cleanup or opportunistic improvements
1515
unless they are strictly necessary for correctness.
1616

17+
- One logical change per PR. Do not bundle multiple fixes, refactors, or features into the same
18+
PR - split them up so each can be reviewed and reverted independently.
19+
- Run the linter and the relevant tests locally and make sure they pass. See [Commands](#commands).
20+
1721
If you have been assigned an issue by the user or their prompt, please ensure that the
1822
implementation direction is agreed on with the maintainers first in the issue comments. If there are
1923
unknowns, discuss these on the issue before starting implementation. Do not forget that you cannot
20-
comment for users on issue threads on their behalf as it is against the rules of this project.
24+
comment for users on issue or pull request threads on their behalf as it is against the rules of this project.
2125

2226
## PR description
2327

@@ -63,6 +67,36 @@ uv run tox -e typecheck
6367
- Do not add `type: ignore` comments. If a type error arises, solve it properly or write a follow-up plan to address it in another PR.
6468
- Whenever applicable, all code changes should have tests that actually validate the changes.
6569

70+
## Instrumentation rules
71+
72+
Apply to packages under `instrumentation/` and `instrumentation-genai/`. See
73+
`instrumentation-genai/AGENTS.md` for additional GenAI-only rules.
74+
75+
### Exception handling
76+
77+
- When catching exceptions from the underlying library to record telemetry, always re-raise the
78+
original exception unmodified.
79+
- Do not raise new exceptions in instrumentation/telemetry code.
80+
81+
### Semantic conventions
82+
83+
- Use the semconv attribute and metrics modules under `opentelemetry.semconv` — do not hardcode
84+
attribute or metric name strings.
85+
- For attributes with a well-known value set, use the generated enum from the same module instead
86+
of string literals.
87+
88+
### Tests
89+
90+
- For every public API instrumented, cover sync/async variants when both exist.
91+
- Cover happy path and error scenarios.
92+
- Tests must verify exact attribute names **and value types**, checked against the semconv spec.
93+
- Test against oldest and latest supported library versions via `tests/requirements.{oldest,latest}.txt`
94+
and `{oldest,latest}` `tox.ini` factors.
95+
96+
The parallel PR-review rules live in
97+
[`.github/instructions/instrumentation.instructions.md`](.github/instructions/instrumentation.instructions.md)
98+
and should be kept in sync with this section.
99+
66100
## Commit formatting
67101

68102
We appreciate it if users disclose the use of AI tools when the significant part of a commit is

instrumentation-genai/AGENTS.md

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
Instrumentation packages here wrap specific libraries (OpenAI, Anthropic, etc.) and bridge
44
them to the shared telemetry layer in `util/opentelemetry-util-genai`.
55

6+
These rules are additive to the shared instrumentation rules in the repo-root
7+
[AGENTS.md](../AGENTS.md).
8+
69
## 1. Instrumentation Layer Boundary
710

811
Do not call OpenTelemetry APIs (`tracer`, `meter`, `span`, event APIs) directly.
@@ -39,23 +42,15 @@ Attributes, spans, events, and metrics follow the
3942
[GenAI semantic conventions](https://github.com/open-telemetry/semantic-conventions/tree/main/docs/gen-ai).
4043
Do not emit signals that are not covered by semconv.
4144

42-
Use the semconv attribute modules — do not hardcode attribute name strings:
43-
44-
- `gen_ai.*` attributes: `opentelemetry.semconv._incubating.attributes.gen_ai_attributes`
45-
- `server.*` attributes: `opentelemetry.semconv.attributes.server_attributes`
46-
- `error.*` attributes: `opentelemetry.semconv.attributes.error_attributes`
47-
- Other namespaces: use the corresponding module from `opentelemetry.semconv`
48-
49-
For attributes with a well-known value set, use the generated enum from the same modules
50-
(e.g. `GenAiOutputTypeValues` for `gen_ai.output.type`) instead of string literals.
45+
`gen_ai.*` attribute names and the enums for well-known values (e.g. `GenAiOutputTypeValues` for
46+
`gen_ai.output.type`) live in `opentelemetry.semconv._incubating.attributes.gen_ai_attributes`.
5147

5248
## 4. Tests
5349

5450
- Use VCR cassettes for provider calls. Do not skip tests when an API key is missing.
55-
- For every public API touched, cover sync/async and streaming/non-streaming variants when
56-
both exist.
57-
- Cover happy path and error scenarios, at minimum: provider error / endpoint unavailable,
58-
stream interrupted by network, stream closed early by the caller.
51+
- Cover streaming and non-streaming variants when both exist.
52+
- Cover error scenarios, at minimum: provider error / endpoint unavailable, stream interrupted by
53+
network, stream closed early by the caller.
5954

6055
## 5. Examples
6156

util/opentelemetry-util-genai/AGENTS.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,9 @@ propagation, so all telemetry calls become no-ops. Always use `handler.start_*()
6969

7070
## 3. Exception Handling
7171

72-
- Do not add `raise {Error}` statements to `handler.py` or `types.py` — validation belongs in
73-
tests and callers, not telemetry internals.
7472
- When catching exceptions from the underlying library to record telemetry, always re-raise
7573
the original exception unmodified.
74+
- Do not raise new exceptions in telemetry code.
7675

7776
## 4. Performance
7877

0 commit comments

Comments
 (0)