-
Notifications
You must be signed in to change notification settings - Fork 1k
Deprecate google-genai and vertexai instrumentations, deprecate the genai folder #4918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lmolkova
wants to merge
3
commits into
open-telemetry:main
Choose a base branch
from
lmolkova:deprecate-genai
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,112 +1,12 @@ | ||
| # GenAI Instrumentation — Agent and Contributor Guidelines | ||
|
|
||
| Instrumentation packages here wrap specific libraries (OpenAI, Google GenAI, etc.) and bridge | ||
| them to the shared telemetry layer in `util/opentelemetry-util-genai`. | ||
| **GenAI instrumentations are no longer developed in this repository.** They live in | ||
| [opentelemetry-python-genai](https://github.com/open-telemetry/opentelemetry-python-genai), | ||
| which is where new instrumentations, features, and bug fixes go. | ||
|
|
||
| These rules are additive to the shared instrumentation rules in the repo-root | ||
| [AGENTS.md](../AGENTS.md). | ||
| The packages still present under this directory are deprecated, receive security patches only, | ||
| and will be removed from this repository in the future. | ||
|
|
||
| ## 0. Instrumentations Maintained Elsewhere | ||
|
|
||
| Development and releases for these GenAI instrumentations have moved to the | ||
| [opentelemetry-python-genai](https://github.com/open-telemetry/opentelemetry-python-genai) | ||
| repository. Direct new development and fixes there, not here: | ||
|
|
||
| - `opentelemetry-instrumentation-genai-anthropic` (anthropic) | ||
| - `opentelemetry-instrumentation-genai-claude-agent-sdk` (claude-agent-sdk) | ||
| - `opentelemetry-instrumentation-genai-langchain` (langchain) | ||
| - `opentelemetry-instrumentation-genai-weaviate-client` (weaviate-client) | ||
| - `opentelemetry-instrumentation-genai-openai` (openai; only security patches in this repo, as `opentelemetry-instrumentation-openai-v2`) | ||
| - `opentelemetry-instrumentation-genai-openai-agents` (openai-agents; only security patches in this repo, as `opentelemetry-instrumentation-openai-agents-v2`) | ||
|
|
||
| Do not add, modify, or attempt to fix these instrumentations in this repository beyond security | ||
| patches for the packages that still live here. Direct any other changes to the | ||
| `opentelemetry-python-genai` repo instead. | ||
|
|
||
| ## 1. Instrumentation Layer Boundary | ||
|
|
||
| Do not call OpenTelemetry APIs (`tracer`, `meter`, `span`, event APIs) directly. | ||
| Always go through `TelemetryHandler` and the invocation objects it returns. | ||
|
|
||
| This layer is responsible only for: | ||
|
|
||
| - Patching the library | ||
| - Parsing library-specific input/output into invocation fields | ||
|
|
||
| Everything else (span creation, metric recording, event emission, context propagation) | ||
| belongs in `util/opentelemetry-util-genai`. | ||
|
|
||
| For GenAI streaming wrappers, prefer the shared `SyncStreamWrapper` and `AsyncStreamWrapper` | ||
| helpers from `opentelemetry.util.genai.stream` instead of reimplementing iteration, | ||
| close/context-manager, and finalization behavior in provider packages. | ||
|
|
||
| Put provider-specific chunk parsing and telemetry finalization in private hook methods or a | ||
| narrow mixin. Do not make async stream wrappers inherit from sync stream wrappers. | ||
|
|
||
| ## 2. TelemetryHandler Initialization | ||
|
|
||
| Construct `TelemetryHandler` once inside `_instrument()`, passing all OTel providers and the | ||
| completion hook. Always prefer an explicitly injected hook (`kwargs.get("completion_hook")`) | ||
| over the entry-point hook loaded by `load_completion_hook()`, so test code can override the | ||
| hook without touching the environment. | ||
|
|
||
| ```python | ||
| from opentelemetry.util.genai.completion_hook import load_completion_hook | ||
| from opentelemetry.util.genai.handler import TelemetryHandler | ||
|
|
||
| def _instrument(self, **kwargs): | ||
| tracer_provider = kwargs.get("tracer_provider") | ||
| meter_provider = kwargs.get("meter_provider") | ||
| logger_provider = kwargs.get("logger_provider") | ||
|
|
||
| handler = TelemetryHandler( | ||
| tracer_provider=tracer_provider, | ||
| meter_provider=meter_provider, | ||
| logger_provider=logger_provider, | ||
| completion_hook=kwargs.get("completion_hook") or load_completion_hook(), | ||
| ) | ||
| # pass handler to each patch/wrapper function | ||
| ``` | ||
|
|
||
| ## 3. Invocation Pattern | ||
|
|
||
| Use `start_*()` and control span lifetime manually: | ||
|
|
||
| ```python | ||
| invocation = handler.start_inference(provider, request_model, server_address=..., server_port=...) | ||
| invocation.temperature = ... | ||
| try: | ||
| response = client.call(...) | ||
| invocation.response_model_name = response.model | ||
| invocation.finish_reasons = response.finish_reasons | ||
| invocation.stop() | ||
| except Exception as exc: | ||
| invocation.fail(exc) | ||
| raise | ||
| ``` | ||
|
|
||
| Content capture decisions must come from the shared handler, not from instrumentation-local | ||
| environment checks or duplicated helper logic. Evaluate the handler's content-capture API once | ||
| when creating wrappers (for example, `capture_content = handler.should_capture_content()`) and | ||
| pass that value through invocation/request helpers. | ||
|
|
||
| ## 4. Semantic conventions | ||
|
|
||
| Attributes, spans, events, and metrics follow the | ||
| [GenAI semantic conventions](https://github.com/open-telemetry/semantic-conventions/tree/main/docs/gen-ai). | ||
| Do not emit signals that are not covered by semconv. | ||
|
|
||
| `gen_ai.*` attribute names and the enums for well-known values (e.g. `GenAiOutputTypeValues` for | ||
| `gen_ai.output.type`) live in `opentelemetry.semconv._incubating.attributes.gen_ai_attributes`. | ||
|
|
||
| ## 5. Tests | ||
|
|
||
| - Use VCR cassettes for provider calls. Do not skip tests when an API key is missing. | ||
| - Cover streaming and non-streaming variants when both exist. | ||
| - Cover error scenarios, at minimum: provider error / endpoint unavailable, stream interrupted by | ||
| network, stream closed early by the caller. | ||
|
|
||
| ## 6. Examples | ||
|
|
||
| New instrumentations ship a minimal example under the package's `examples/` directory, with | ||
| both a `manual/` setup and a `zero-code/` (auto-instrumentation) variant. | ||
| Do not add instrumentations here, and do not fix bugs or add features to the ones that remain. | ||
| Send any such change to the `opentelemetry-python-genai` repo instead. Security patches are the | ||
| only changes accepted in this directory. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.