OpenInference Instructor Instrumentation

raw JSON →
0.1.14 verified Fri May 01 auth: no python

OpenTelemetry instrumentation for the instructor library (Python), enabling tracing of LLM calls and structured extraction for observability with Phoenix and other OpenInference-compatible backends. Current version: 0.1.14. Release cadence: irregular, part of the openinference monorepo.

pip install openinference-instrumentation-instructor
error ImportError: cannot import name 'InstructorInstrumentor' from 'openinference_instrumentation_instructor'
cause Using hyphens in module path (incorrect import path).
fix
Use: from openinference.instrumentation.instructor import InstructorInstrumentor
error ModuleNotFoundError: No module named 'openinference_instrumentation_instructor'
cause Package not installed or using incorrect import name (should be dotted).
fix
Install: pip install openinference-instrumentation-instructor. Then import: from openinference.instrumentation.instructor import InstructorInstrumentor
error Opentelemetry span not created for instructor calls
cause Instrumentation was called after creating the instructor client, or the OpenTelemetry exporter not configured.
fix
Call InstructorInstrumentor().instrument() before any instructor usage, and configure an OTLP exporter (e.g., phoenix).
gotcha The import path uses dots, not hyphens: 'openinference.instrumentation.instructor' not 'openinference_instrumentation_instructor'. Hyphenated package name on PyPI maps to underscore in import but correct is dotted.
fix Use: from openinference.instrumentation.instructor import InstructorInstrumentor
gotcha Instrumentation must be called before any instructor client usage. If you instrument after creating a client, spans will not be captured.
fix Call InstructorInstrumentor().instrument() at the top of your application, before importing or creating instructor clients.
breaking Breaking change when upgrading from openinference-instrumentation-instructor <0.1.0: The module name changed from openinference_instrumentation_instructor to openinference.instrumentation.instructor.
fix Update import: from openinference.instrumentation.instructor import InstructorInstrumentor

Instrument instructor to trace LLM calls and structured extraction. Ensure instructor and openai are installed.

import instructor
from openinference.instrumentation.instructor import InstructorInstrumentor

# Instrument before using instructor
InstructorInstrumentor().instrument()

# Now use instructor normally
client = instructor.from_openai(openai.OpenAI(api_key=os.environ.get('OPENAI_API_KEY', '')))
# Example: extract structured data
import pydantic
class User(pydantic.BaseModel):
    name: str
    age: int
user = client.chat.completions.create(model="gpt-4o", response_model=User, messages=[{"role": "user", "content": "John Doe is 30"}])
print(user.name, user.age)