Skip to content

Tighten _installed_instrumentors typing once OpenInference publishes a common base #605

Description

@Freezaa9

Background

otel_lifecycle.py (PR #601) declares _installed_instrumentors: list[Any] and def attach_instrumentor(instrumentor: Any) -> None. CodeRabbit suggested a Protocol-typed list during review and the orchestrator deferred:

The four OpenInference instrumentors we attach (LangChainInstrumentor, GuardrailsInstrumentor, VertexAIInstrumentor, MCPInstrumentor) come from separate packages with no shared base class — Any is honest about the FFI boundary. A Protocol would add maintenance burden against four packages that may evolve independently.

Trigger

Open this issue when OpenInference publishes a common Instrumentor base class (or a stable Protocol) across its instrumentor packages — at which point this trade-off flips.

Fix when triggered

from typing import Protocol

class Instrumentor(Protocol):
    def instrument(self, tracer_provider: TracerProvider) -> None: ...
    def uninstrument(self) -> None: ...

_installed_instrumentors: list[Instrumentor] = []

def attach_instrumentor(instrumentor: Instrumentor) -> None: ...

Watch out for instrumentor variants that accept **kwargs in instrument(...) — the Protocol may need to be loosened.

References

🤖 Filed during PR #601 wrap-up.

Metadata

Metadata

Assignees

No one assigned

    Labels

    engineEngine specific issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions