auto_instrument()¶
Automatically patches all installed LLM libraries to emit OpenInference-compatible spans. Libraries that are not installed are silently skipped.
Signature¶
Parameters¶
| Parameter | Type | Default | Description |
|---|---|---|---|
tracer_provider |
TracerProvider \| None |
None |
Custom TracerProvider to use. When None, uses the global provider set by register(). |
suppress_errors |
bool |
True |
When True, instrumentation errors are logged as warnings instead of raising exceptions. |
include_libraries |
list[str] \| None |
None |
If provided, only instrument these libraries (allowlist). Library names must match the names in the Supported Libraries table. |
exclude_libraries |
list[str] \| None |
None |
If provided, skip these libraries (blocklist). |
All parameters are keyword-only (enforced by *).
include_libraries vs exclude_libraries
These parameters are mutually exclusive in practice. If include_libraries is set, libraries not in the list are simply not attempted (they do not appear in the results at all). If exclude_libraries is set, excluded libraries appear in results with status "excluded".
Returns¶
dict[str, str] -- A dictionary mapping each library name to its instrumentation status.
Status Values¶
| Status | Meaning |
|---|---|
"success" |
Library was found and successfully instrumented. |
"not_installed" |
The OpenInference instrumentor package for this library is not installed. |
"already_instrumented" |
Library was already instrumented (e.g., by a previous call). |
"error" |
Instrumentation was attempted but failed. Check logs for details. |
"excluded" |
Library was skipped because it is in exclude_libraries. |
Supported Libraries¶
auto_instrument() supports the following 15 frameworks via OpenInference:
| Library Name | Instrumentor Package | Description |
|---|---|---|
openai |
openinference-instrumentation-openai |
OpenAI SDK |
llamaindex |
openinference-instrumentation-llama-index |
LlamaIndex |
langchain |
openinference-instrumentation-langchain |
LangChain |
google-genai |
openinference-instrumentation-google-generativeai |
Google Generative AI (Gemini) |
vertexai |
openinference-instrumentation-vertexai |
Google Vertex AI |
bedrock |
openinference-instrumentation-bedrock |
AWS Bedrock |
anthropic |
openinference-instrumentation-anthropic |
Anthropic Claude |
mistralai |
openinference-instrumentation-mistralai |
Mistral AI |
groq |
openinference-instrumentation-groq |
Groq |
litellm |
openinference-instrumentation-litellm |
liteLLM |
dspy |
openinference-instrumentation-dspy |
DSPy |
crewai |
openinference-instrumentation-crewai |
CrewAI |
haystack |
openinference-instrumentation-haystack |
Haystack |
instructor |
openinference-instrumentation-instructor |
Instructor |
guardrails |
openinference-instrumentation-guardrails |
Guardrails |
Install Extras¶
The Coalex SDK provides install extras to pull in the correct OpenInference instrumentor packages:
# All supported frameworks
pip install coalex[auto-instrument]
# Individual frameworks
pip install coalex[openai]
pip install coalex[langchain]
pip install coalex[llamaindex]
pip install coalex[google-genai]
pip install coalex[vertexai]
pip install coalex[bedrock]
pip install coalex[anthropic]
# Multiple frameworks
pip install coalex[openai,langchain]
Install the OpenInference instrumentor packages alongside the SDK:
# OpenAI
npm install @coalex-ai/sdk @arizeai/openinference-instrumentation-openai
# LangChain
npm install @coalex-ai/sdk @arizeai/openinference-instrumentation-langchain
# Anthropic
npm install @coalex-ai/sdk @arizeai/openinference-instrumentation-anthropic
# Multiple frameworks
npm install @coalex-ai/sdk \
@arizeai/openinference-instrumentation-openai \
@arizeai/openinference-instrumentation-langchain
Minimal installs for production
In production, prefer installing only the extras you need. The auto-instrument extra pulls in instrumentors for OpenAI, LangChain, LlamaIndex, Vertex AI, Bedrock, and Anthropic -- which may be more than you use.
Examples¶
Instrument everything available¶
import coalex
coalex.register(api_key="your-key")
results = coalex.auto_instrument()
print(results)
# {
# "openai": "success",
# "llamaindex": "not_installed",
# "langchain": "not_installed",
# "vertexai": "not_installed",
# "bedrock": "not_installed",
# "anthropic": "success",
# "mistralai": "not_installed",
# "groq": "not_installed",
# "litellm": "not_installed",
# "dspy": "not_installed",
# "crewai": "not_installed",
# "haystack": "not_installed",
# "instructor": "not_installed",
# "guardrails": "not_installed",
# }
Allowlist specific libraries¶
Exclude a library¶
Custom TracerProvider¶
Convenience Functions¶
For cases where you only want to instrument a single library, the SDK provides convenience functions. Each returns True on success and False on failure.
import coalex
coalex.instrument_openai() # -> bool
coalex.instrument_langchain() # -> bool
coalex.instrument_llamaindex() # -> bool
coalex.instrument_google_genai() # -> bool
coalex.instrument_vertexai() # -> bool
coalex.instrument_bedrock() # -> bool
coalex.instrument_anthropic() # -> bool
All convenience functions accept an optional tracer_provider parameter:
Notes¶
auto_instrument()should be called afterregister()so the globalTracerProvideris already configured. If called withoutregister()and without atracer_providerargument, instrumented libraries use the default no-op provider.- Calling
auto_instrument()multiple times is safe -- already-instrumented libraries return"already_instrumented". - Python: The function is synchronous and returns immediately after patching.
- TypeScript: Use
autoInstrumentAsync()in ESM projects whererequire()is not available. The syncautoInstrument()variant usesrequire()internally and may not work in pure ESM environments. - For custom pipeline steps that are not covered by auto-instrumentation (e.g., custom retrievers, rerankers), use the extension decorators.
API Reference¶
coalex.auto_instrument ¶
Auto-instrumentation for popular LLM frameworks using OpenInference.
Functions¶
auto_instrument ¶
auto_instrument(
tracer_provider: TracerProvider | None = None,
suppress_errors: bool = True,
include_libraries: list[str] | None = None,
exclude_libraries: list[str] | None = None,
) -> dict[str, str]
Automatically instrument all available LLM libraries using OpenInference.
Only libraries actually installed are instrumented — missing libraries are silently skipped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tracer_provider
|
TracerProvider | None
|
TracerProvider to use (defaults to global provider). |
None
|
suppress_errors
|
bool
|
If True, log errors instead of raising (default: True). |
True
|
include_libraries
|
list[str] | None
|
If provided, only instrument these libraries. |
None
|
exclude_libraries
|
list[str] | None
|
If provided, skip these libraries. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Dictionary mapping library name to instrumentation status |
dict[str, str]
|
("success", "not_installed", "already_instrumented", "error", "excluded"). |
Source code in coalex/auto_instrument.py
instrument_openai ¶
instrument_llamaindex ¶
instrument_langchain ¶
instrument_google_genai ¶
Instrument Google GenAI (google-genai SDK) specifically.