Skip to main content

OpenTelemetry instrumentation for Haystack

Project description

Haystack OpenTelemetry Integration

Overview

This integration provides support for using OpenTelemetry with the Haystack framework. It enables tracing and monitoring of applications built with Haystack.

Installation

  1. Install traceAI Haystack
pip install traceAI-haystack

Set Environment Variables

Set up your environment variables to authenticate with FutureAGI

import os

os.environ["FI_API_KEY"] = FI_API_KEY
os.environ["FI_SECRET_KEY"] = FI_SECRET_KEY

Quickstart

Register Tracer Provider

Set up the trace provider to establish the observability pipeline. The trace provider:

from fi_instrumentation import register
from fi_instrumentation.fi_types import ProjectType

trace_provider = register(
    project_type=ProjectType.OBSERVE,
    project_name="haystack_app"
)

Configure Haystack Instrumentation

Instrument the Haystack client to enable telemetry collection. This step ensures that all interactions with the Haystack SDK are tracked and monitored.

from traceai_haystack import HaystackInstrumentor

HaystackInstrumentor().instrument(tracer_provider=trace_provider)

Create Haystack Components

from haystack import Document, Pipeline
from haystack.components.builders import PromptBuilder
from haystack.components.embedders import (
    SentenceTransformersDocumentEmbedder,
    SentenceTransformersTextEmbedder,
)
from haystack.components.generators import OpenAIGenerator
from haystack.components.retrievers.in_memory import InMemoryEmbeddingRetriever
from haystack.document_stores.in_memory import InMemoryDocumentStore
from datasets import load_dataset

document_store = InMemoryDocumentStore()

dataset = load_dataset("bilgeyucel/seven-wonders", split="train")
docs = [Document(content=doc["content"], meta=doc["meta"]) for doc in dataset]

doc_embedder = SentenceTransformersDocumentEmbedder(
    model="sentence-transformers/all-MiniLM-L6-v2"
)
doc_embedder.warm_up()

docs_with_embeddings = doc_embedder.run(docs)
document_store.write_documents(docs_with_embeddings["documents"])

text_embedder = SentenceTransformersTextEmbedder(
    model="sentence-transformers/all-MiniLM-L6-v2"
)

retriever = InMemoryEmbeddingRetriever(document_store)

template = """
Given the following information, answer the question.

Context:
{% for document in documents %}
    {{ document.content }}
{% endfor %}

Question: {{question}}
Answer:
"""

prompt_builder = PromptBuilder(template=template)

generator = OpenAIGenerator(model="gpt-3.5-turbo")

basic_rag_pipeline = Pipeline()
basic_rag_pipeline.add_component("text_embedder", text_embedder)
basic_rag_pipeline.add_component("retriever", retriever)
basic_rag_pipeline.add_component("prompt_builder", prompt_builder)
basic_rag_pipeline.add_component("llm", generator)

basic_rag_pipeline.connect("text_embedder.embedding", "retriever.query_embedding")
basic_rag_pipeline.connect("retriever", "prompt_builder.documents")
basic_rag_pipeline.connect("prompt_builder", "llm")

question = "What does Rhodes Statue look like?"

response = basic_rag_pipeline.run(
    {"text_embedder": {"text": question}, "prompt_builder": {"question": question}}
)

print(response["llm"]["replies"][0])

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

traceai_haystack-0.1.8.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

traceai_haystack-0.1.8-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file traceai_haystack-0.1.8.tar.gz.

File metadata

  • Download URL: traceai_haystack-0.1.8.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.0 CPython/3.13.0 Darwin/24.1.0

File hashes

Hashes for traceai_haystack-0.1.8.tar.gz
Algorithm Hash digest
SHA256 0a9358918de17137b3901d8083fd6e218ee6ba78feaea9aa5a0932e002fcaf9e
MD5 20e5bac08c87677aefcd0c7b1a0ec048
BLAKE2b-256 706f650ca92fb3b68a653d3c08763c4b0b1998a0abc67d208cb485b4727a11c9

See more details on using hashes here.

File details

Details for the file traceai_haystack-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: traceai_haystack-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.0 CPython/3.13.0 Darwin/24.1.0

File hashes

Hashes for traceai_haystack-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 158c0a446b7811a57ec6ba48cd41922e8098eeb7e20bf3502875b1b085fe543d
MD5 0d929b3e96dd3b5a316f9a40bbc9be2f
BLAKE2b-256 77ce7a22217ac628bdb48e9af359215baa8cca129b48090dcafa4ee76e2eb1eb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page