openllmetry icon indicating copy to clipboard operation
openllmetry copied to clipboard

Can't see the workflow trace

Open eric-easyhealth opened this issue 1 year ago • 4 comments

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)
        

image image

eric-easyhealth avatar Sep 18 '24 03:09 eric-easyhealth

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:

  1. Install the Traceloop SDK:

    pip install traceloop-sdk
    
  2. Initialize the Traceloop tracer:

    from traceloop.sdk import Traceloop
    
    Traceloop.init(app_name="app_name", api_key="apikey")
    
  3. Annotate your workflows: Use the @workflow and @task decorators 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
    
  4. Configure trace exporting: Set the environment variables TRACELOOP_API_KEY and TRACELOOP_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.

dosubot[bot] avatar Sep 18 '24 03:09 dosubot[bot]

this doesn't resolve my questions, this workflow should be automatically identfied according to the documentation if i used haystack.

eric-easyhealth avatar Sep 18 '24 03:09 eric-easyhealth

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.

dosubot[bot] avatar Sep 18 '24 03:09 dosubot[bot]

Sorry about the bot @eric-easyhealth, we're trying something new 😅

nirga avatar Sep 18 '24 06:09 nirga