llama-index observability integration with OpenTelemetry
Project description
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?")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file llama_index_observability_otel-0.4.1.tar.gz.
File metadata
- Download URL: llama_index_observability_otel-0.4.1.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa8b27b0c56aeade5ce6d0b00f3172fb7b090819591866afaae01e676acb70df
|
|
| MD5 |
0f2b824b21895d269389c4a9b4d917ae
|
|
| BLAKE2b-256 |
a693b1c1e46117b4b702ff3a28a4d0bddfdba973e8849e33db328501d7c78309
|
File details
Details for the file llama_index_observability_otel-0.4.1-py3-none-any.whl.
File metadata
- Download URL: llama_index_observability_otel-0.4.1-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c190be91eb37e39618ab8a9ea603c7d1961b0a3fa3960ed4e3a5560a4e3c875b
|
|
| MD5 |
60faa9be9199bd388825db6211e74809
|
|
| BLAKE2b-256 |
d20eedf480cab2f10bac3bc49067fbe9fbc64b63ecbc35cd53f6f08562821b02
|