DocumentationAPI ReferenceRelease Notes
DocumentationLog In
Documentation

Export your traces and log them to Deepchecks

Exporting Traces to JSON

Deepchecks lets you export traces to a local JSON file instead of sending them to Deepchecks in real time. This is useful for developers who want to inspect, store, or upload traces at a later time.

To export traces to a JSON file, install the required packages:

pip install "deepchecks-llm-client[otel]"

Then, use the following code:

from deepchecks_llm_client.data_types import EnvType
from deepchecks_llm_client.otel import LanggraphIntegration # Or "import CrewaiIntegration"

LanggraphIntegration().register_json_exporter( # Or "CrewaiIntegration()."
    output_folder="Your Output Folder Here",
    log_to_console=True  # Optional: Set to True to log spans to console
)

After running this, a JSON file containing the run traces will appear in the specified output folder.


Logging a trace JSON to Deepchecks

Once you have exported traces, you can log them to Deepchecks for observability and evaluation using the following code:

from deepchecks_llm_client.otel import DeepchecksLLMClient
import os
import json
from dotenv import load_dotenv

load_dotenv()
host = os.getenv("DEEPCHECKS_HOST")
api_token = os.getenv("DEEPCHECKS_API_TOKEN")

dc_client = DeepchecksLLMClient(
    host=host,
    api_token=api_token
)

dc_client.log_spans_file(
    app_name="Your App Name",
    version_name="Your Version Name",
    env_type="EVAL",
    json_path="Path of the JSON File"
)

This process allows you to upload previously exported traces to Deepchecks for observability, evaluation, and monitoring.


Attaching Steps to Spans

You can attach custom structured data to spans using the steps parameter. Each step is a name-value pair that gets stored with the span and can be referenced as a data field in prompt property evaluation.

from deepchecks_llm_client.data_types import Span, Step, SpanKind

span = Span(
    span_id="span-1",
    span_name="planning-agent",
    span_kind=SpanKind.AGENT,
    trace_id="trace-1",
    parent_id=None,
    started_at=1700000000.0,
    finished_at=1700000010.0,
    input="Plan a trip to Berlin",
    output="Here is your itinerary...",
    steps=[
        Step(name="reasoning", value="User wants a travel plan, checking available tools..."),
        Step(name="plan", value="1. Search flights 2. Search hotels 3. Build itinerary"),
    ]
)

dc_client.log_spans(
    app_name="Travel Agent",
    version_name="v1",
    env_type="EVAL",
    spans=[span]
)

Steps appear in the interaction's processed data and can be selected as input fields when configuring prompt properties.


Did this page help you?