Nat TaylorBlog, AI, Product Management & Tinkering

Test Drive: Langtrace

Published on .

Today I test drove Langtrace, “an open-source observability tool that collects and analyzes traces and metrics to help you improve your LLM apps.” I discovered it on X and I wasn’t sure what to expect, but its a pretty neat tool although it has some minor bugs. Prompts in the database makes sense, I think, although the coordination of passing the required variables at runtime seems potentially messy. Tracing is amazing, and the UI for that is quite good. Local hosting is simple. I did not try the evaluation part, yet.

The process is:

  1. git clone and docker-compose up
  2. Sign in, create a project and a key
  3. Instrument your code
  4. Mess around 😀

So my implementation is simply this:

from langtrace_python_sdk import langtrace, get_prompt_from_registry
from langtrace_python_sdk.utils.with_root_span import with_langtrace_root_span
from openai import OpenAI

langtrace.init(
    api_key="1563d6d3821cc66e3408ea8109521830a13761884b5c66cc326e0cd9c11f80f3",
    api_host="http://localhost:3000/api/trace",
)

description = """PTT Public Company Limited is a Thailand-based company engaged in the gas and petroleum businesses. The Company supplies, transports and distributes natural gas vehicle (NGV), petroleum products and lubricating oil via service stations throughout Thailand and also exports to overseas markets. Through its subsidiaries and affiliated companies, the Company is involved in exploration, production, refinery, marketing and distribution of petroleum, petrochemical products and aromatics. In addition, the Company operates international trade businesses, including import and export of crude oil, condensates, petroleum products, petrochemicals, and sourcing of international transport vessels and carriers."""

@with_langtrace_root_span()
def run(description):
    prompt = get_prompt_from_registry('cm1jhczpi000c2uwwmtw39iox', options = {'variables': {'description': description}})
    client = OpenAI()
    response = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[
            {"role": "user", "content": prompt['value']},
        ],
    )
    print(response.choices[0].message.content)

run(description)

The UI you get is nice

Post Navigation

«
»