opik icon indicating copy to clipboard operation
opik copied to clipboard

Local Deployment is wrong

Open cuongnguyengit opened this issue 6 months ago • 3 comments

Bug: Trace URL from console output results in a 404 "Trace ID not found" error

Describe the bug When running code instrumented with opik and using a custom OPIK_URL_OVERRIDE, the trace URL printed to the console leads to a 404 error page stating "Trace id: ... not found" when visited.

To Reproduce Steps to reproduce the behavior:

  1. Set the OPIK_URL_OVERRIDE environment variable (e.g., export OPIK_URL_OVERRIDE="http://myserver:9094/api" or set it within the script).
  2. Run the following Python script:
    import os, openai
    import httpx
    from opik import track
    import opik # Ensure opik is imported to recognize the env var if set globally
    
    # Set the override if not done via environment variable
    os.environ["OPIK_URL_OVERRIDE"] = "http://myserver:9094/api"
    
    client = openai.OpenAI(http_client=httpx.Client(
                           verify=False
                       ))
    @track
    def retrieve_context(input_text):
        return [
            "What specific information are you looking for?",
            "How can I assist you with your interests today?",
            "Are there any topics you'd like to explore or learn more about?",
        ]
    
    @track
    def generate_response(input_text, context):
        full_prompt = f'If the user asks a question that is not specific, use the context to provide a relevant response.\nContext: {", ".join(context)}\nUser: {input_text}\nAI:'
        response = client.chat.completions.create(
            model="gpt-3.5-turbo", messages=[{"role": "user", "content": full_prompt}]
        )
        return response.choices[0].message.content
    
    context = retrieve_context("Hi how are you?")
    print(generate_response("Hi how are you?", context))
    
  3. The script outputs a message similar to this:
    OPIK: Started logging traces to the "Default Project" project at http://myserver:9094/api/v1/session/redirect/projects/?trace_id=0196ebd9-6924-7a0f-a3e8-1b43eba331e2&path=aHR0cDovLzEwLjI0OC4yMzYuNDE6OTA5NC9hcGk=.
    Hello! I'm here to assist you with any specific information or interests you may have. Let me know how I can help!
    
  4. Copy the URL provided (e.g., http://myserver:9094/api/v1/session/redirect/projects/?trace_id=0196ebd9-6924-7a0f-a3e8-1b43eba331e2&path=...) and open it in a browser.

Expected behavior The URL should open and display the traces for the executed code on the OPIK server.

Actual behavior The browser displays a JSON response indicating a 404 error:

{"code":404,"message":"Trace id: 0196ebd1-0ff9-73db-8d1e-b465bf65f1ce not found"}

Screenshots/Logs

  • Console Output:
    OPIK: Started logging traces to the "Default Project" project at http://myserver:9094/api/v1/session/redirect/projects/?trace_id=0196ebd9-6924-7a0f-a3e8-1b43eba331e2&path=aHR0cDovLzEwLjI0OC4yMzYuNDE6OTA5NC9hcGk=.
    Hello! I'm here to assist you with any specific information or interests you may have. Let me know how I can help!
    
  • Browser Response (when visiting the link):
    {"code":404,"message":"Trace id: 0196ebd1-0ff9-73db-8d1e-b465bf65f1ce not found"}
    

Important Observation: It appears the trace_id in the console output (0196ebd9-6924-7a0f-a3e8-1b43eba331e2) is different from the trace_id mentioned in the 404 error message (0196ebd1-0ff9-73db-8d1e-b465bf65f1ce). This might be a key factor in the issue.

Additional context My OPIK server is running at http://myserver:9094. The API endpoint seems to be /api. The issue occurs consistently with the provided script.

Thank you for looking into this!

cuongnguyengit avatar May 20 '25 04:05 cuongnguyengit

Hey @cuongnguyengit , thanks for reporting this issue, we're looking into it!

aadereiko avatar May 20 '25 08:05 aadereiko

Hi @cuongnguyengit! Instead of setting the environment variable directly, could you please try to run in CLI opik configure (follow the instructions) and then share opik healthcheck output if it doesn't help?

alexkuzmik avatar May 20 '25 13:05 alexkuzmik

hey @cuongnguyengit has it helped?

aadereiko avatar May 22 '25 08:05 aadereiko

Thank you for your question! Since the original query has been answered, we are closing this issue. If you have any further questions or need additional clarification, please feel free to reopen the issue at any time. We're happy to help!

andrescrz avatar Jul 15 '25 11:07 andrescrz