Can't see the workflow trace
Discussed in https://github.com/traceloop/openllmetry/discussions/1804
Originally posted by eric-easyhealth August 6, 2024 I'm using Haystack2 with latest trackloop 0.26.4, followed the offical guidance to init the traceloop by following code:
Traceloop.init(app_name="app_name", api_key="apikey")
it works perfect and shown me the openai track as following, but how can i enable the workflow track like what is suggested in the quick start document? PS: i'm using a pipeline in a python class, dummy code as below:
from haystack import Pipeline
from haystack.components.generators.chat import OpenAIChatGenerator
class ChatPipelineViaRAG:
def __init__(self, api_key:str = '')
self.retrieve_pipeline = Pipeline()
self.generator = OpenAIChatGenerator()
......
def run(self, messages: List[ChatMessage]) -> dict[str, Any]:
retrieved_documents = self.retrieve_pipeline.run(parameters...)
self.messages = process_documents(messages, retrieved_documents)
return self.generator.run(self.messages)
Hey, @eric-easyhealth! I'm here to help you with any bugs, questions, or contributions you have. Let's squash those bugs together!
I found a similar unsolved discussion where a user faced a similar issue with workflow trace visibility while using Haystack2 with Traceloop 0.26.4. You can check it out here [1].
To enable workflow tracking in Traceloop 0.26.4 when using a pipeline in a Python class with the OpenAIChatGenerator, follow these steps:
-
Install the Traceloop SDK:
pip install traceloop-sdk -
Initialize the Traceloop tracer:
from traceloop.sdk import Traceloop Traceloop.init(app_name="app_name", api_key="apikey") -
Annotate your workflows: Use the
@workflowand@taskdecorators to enable workflow tracking for your functions. Here is an example:from haystack import Pipeline from haystack.components.generators.chat import OpenAIChatGenerator from traceloop.sdk.decorators import workflow, task class ChatPipelineViaRAG: def __init__(self, api_key: str = ''): self.retrieve_pipeline = Pipeline() self.generator = OpenAIChatGenerator() @workflow(name="chat_pipeline_workflow") def run(self, messages: List[ChatMessage]) -> dict[str, Any]: retrieved_documents = self.retrieve_pipeline.run(parameters...) self.messages = self.process_documents(messages, retrieved_documents) return self.generator.run(self.messages) @task(name="process_documents_task") def process_documents(self, messages, retrieved_documents): # Your document processing logic here return processed_messages -
Configure trace exporting: Set the environment variables
TRACELOOP_API_KEYandTRACELOOP_BASE_URL:export TRACELOOP_API_KEY=your_api_key
By following these steps, you should be able to enable workflow tracking for your pipeline using Traceloop [2][3][4].
To continue talking to Dosu, mention @dosu.
this doesn't resolve my questions, this workflow should be automatically identfied according to the documentation if i used haystack.
To enable automatic workflow tracking in Traceloop 0.26.4 when using Haystack2, you do not need to add any annotations to your code. Traceloop will automatically handle the annotations for you if you are using an LLM framework like Haystack.
Here's how you can initialize Traceloop:
from traceloop.sdk import Traceloop
Traceloop.init(app_name="app_name", api_key="apikey")
If you’re running this locally and want to see the traces immediately, you can disable batch sending:
Traceloop.init(app_name="app_name", api_key="apikey", disable_batch=True)
This setup should enable automatic workflow tracking in Traceloop when using Haystack2 [1].
To continue talking to Dosu, mention @dosu.
Sorry about the bot @eric-easyhealth, we're trying something new 😅