# openinference-instrumentation-llama-index

**Python · Instrumentation**

OpenInference LlamaIndex Instrumentation

- **Module**: `openinference.instrumentation.llama_index`
- **Version**: 4.7.8
- **Python**: >=3.10, <3.16
- **Instruments**: `llama-index-core >= 0.14.19, llama-index-multi-modal-llms-openai >= 0.1.7`

[PyPI](https://pypi.org/project/openinference-instrumentation-llama-index/) · [README](https://github.com/Arize-ai/openinference/blob/main/python/instrumentation/openinference-instrumentation-llama-index/README.md) · [Source](https://github.com/Arize-ai/openinference/tree/main/python/instrumentation/openinference-instrumentation-llama-index)

## Install

```sh
pip install openinference-instrumentation-llama-index
```

## Usage

Instrument once, at startup, before the library is used. The [`LlamaIndexInstrumentor`](https://openinf.dev/python/openinference-instrumentation-llama-index.html.md#openinference.instrumentation.llama_index.LlamaIndexInstrumentor) reference below lists the options.

```python
from opentelemetry.sdk.trace import TracerProvider
from openinference.instrumentation import TraceConfig
from openinference.instrumentation.llama_index import LlamaIndexInstrumentor

tracer_provider = TracerProvider()
# ...add a span processor that exports to Phoenix or any OTLP backend.

LlamaIndexInstrumentor().instrument(
    tracer_provider=tracer_provider,
    config=TraceConfig(hide_inputs=True),  # optional
)
```

## `openinference.instrumentation.llama_index`

### `LlamaIndexInstrumentor`

_class_ · [Source](https://github.com/Arize-ai/openinference/blob/main/python/instrumentation/openinference-instrumentation-llama-index/src/openinference/instrumentation/llama_index/__init__.py#L20-L128)

```python
class LlamaIndexInstrumentor(BaseInstrumentor)
```

An instrumentor for LlamaIndex

#### `instrument`

_method_

```python
def instrument(
    *,
    tracer_provider: Optional[TracerProvider] = None,
    config: Optional[TraceConfig] = None,
    skip_dep_check: bool = False,
) -> None
```

Start tracing `llama-index-core`, `llama-index-multi-modal-llms-openai`: patch it so its calls make OpenInference spans. Calling it again does nothing. Inherited from OpenTelemetry’s [`BaseInstrumentor`](https://opentelemetry-python-contrib.readthedocs.io/en/latest/instrumentation/base/instrumentor.html).

**Parameters**

| Name | Description |
| - | - |
| `tracer_provider` | The tracer provider the spans are made with. Defaults to the global one, `opentelemetry.trace.get_tracer_provider()`. |
| `config` | What the spans record: hide inputs, outputs or messages, or limit image sizes. Defaults to `TraceConfig()`, which reads the `OPENINFERENCE_*` environment variables. See [`TraceConfig`](https://openinf.dev/python/openinference-instrumentation.html.md#openinference.instrumentation.TraceConfig). |
| `skip_dep_check` | Instrument even if the installed version of `llama-index-core`, `llama-index-multi-modal-llms-openai` is outside the supported range. |

#### `uninstrument`

_method_

```python
def uninstrument() -> None
```

Stop tracing: undo the patches `instrument()` made. Inherited from OpenTelemetry’s [`BaseInstrumentor`](https://opentelemetry-python-contrib.readthedocs.io/en/latest/instrumentation/base/instrumentor.html).

#### `instrumentation_dependencies`

_method_ · [Source](https://github.com/Arize-ai/openinference/blob/main/python/instrumentation/openinference-instrumentation-llama-index/src/openinference/instrumentation/llama_index/__init__.py#L33-L34)

```python
def instrumentation_dependencies() -> Collection[str]
```

### `get_current_span`

_function_ · [Source](https://github.com/Arize-ai/openinference/blob/main/python/instrumentation/openinference-instrumentation-llama-index/src/openinference/instrumentation/llama_index/__init__.py#L138-L153)

```python
def get_current_span() -> Optional[Span]
```
