LlamaIndex OpenTelemetry Observability Integration
Installation
pip install llama-index-observability-otel
Usage
You can use the default OpenTelemetry observability class as follows:
from llama_index.observability.otel import LlamaIndexOpenTelemetry
from llama_index.core import SimpleDirectoryReader, VectorStoreIndex
from llama_index.core.llms import MockLLM
from llama_index.core.embeddings import MockEmbedding
from llama_index.core import Settings
# initialize the instrumentation object
instrumentor = LlamaIndexOpenTelemetry()
if __name__ == "__main__":
embed_model = MockEmbedding(embed_dim=256)
llm = MockLLM()
Settings.embed_model = embed_model
# start listening!
instrumentor.start_registering()
# register events
documents = SimpleDirectoryReader(
input_dir="./data/paul_graham/"
).load_data()
index = VectorStoreIndex.from_documents(documents)
query_engine = index.as_query_engine(llm=llm)
query_result = query_engine.query("Who is Paul?")
query_result_one = query_engine.query("What did Paul do?")
Or you can add some customization to the LlamaIndexOpenTelemetry class by, for example, set a custom span exporter, a custom service name, activating the debugging, set a custom list of extra span processors...
from llama_index.observability.otel import LlamaIndexOpenTelemetry
from llama_index.core import SimpleDirectoryReader, VectorStoreIndex
from opentelemetry.exporter.otlp.proto.http.trace_exporter import (
OTLPSpanExporter,
)
from opentelemetry.sdk.trace import SpanProcessor
from llama_index.core.llms import MockLLM
from llama_index.core.embeddings import MockEmbedding
from llama_index.core import Settings
class CustomSpanProcessor(SpanProcessor):
# your implementation
...
# define a custom span exporter
span_exporter = OTLPSpanExporter("http://0.0.0.0:4318/v1/traces")
# initialize the instrumentation object
instrumentor = LlamaIndexOpenTelemetry(
service_name_or_resource="my.test.service.1",
span_exporter=span_exporter,
debug=True,
extra_span_processors=[CustomSpanProcessor()],
)
if __name__ == "__main__":
embed_model = MockEmbedding(embed_dim=256)
llm = MockLLM()
Settings.embed_model = embed_model
# start listening!
instrumentor.start_registering()
# register events
documents = SimpleDirectoryReader(
input_dir="./data/paul_graham/"
).load_data()
index = VectorStoreIndex.from_documents(documents)
query_engine = index.as_query_engine(llm=llm)
query_result = query_engine.query("Who is Paul?")
query_result_one = query_engine.query("What did Paul do?")
Metadata
Release files for llama-index-observability-otel 0.7.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| llama_index_observability_otel-0.7.0.tar.gz | 8.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| llama_index_observability_otel-0.7.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.2 kB
Release files / llama_index_observability_otel-0.7.0.tar.gz
| Download URL | llama_index_observability_otel-0.7.0.tar.gz |
|---|---|
| Size | 8.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
20695531d52ec5c47a260bae7940246feb1a96880dff3360af06fa2f560c0dfa
|
|
BLAKE2b-256 checksum How to use checksums |
2b724d33b9e8351b802bb931651fd53bbd34865befd887ea9639166a6d5562cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / llama_index_observability_otel-0.7.0-py3-none-any.whl
| Download URL | llama_index_observability_otel-0.7.0-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
903003788f98a76f2b979d1b22062fd4de35d73d5cfdd8adb430e43764b12890
|
|
BLAKE2b-256 checksum How to use checksums |
efb91ddaf5b73400e4146e16180d7b71e9686c936d422c1fb72d328e68cc2841
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|