Skip to main content
A span is a single model call. A span is part of a trace. You can create a span using start_span. For example,
with tatara.start_span(event="generate_visual_description"):
    prompt = "Generate a visual description of a dog"
        response = openai_client.chat.completions.create(
            messages=[{"role": "user", "content": prompt}],
            model=model_name,
            temperature=temperature,
            frequency_penalty=freq_penalty,
            max_tokens=max_tokens,
        )
Once the span has started, you can use it to log the LLM output
tatara.current_span().log_llm_success(prompt=character_description, output=ret,
                params=LLMParams(
                model=model_name,
                temperature=temperature,
                frequency_penalty=freq_penalty,
                max_tokens=max_tokens,
                provider=ProviderEnum.OPENAI,
            ),
            usage_metrics=LLMUsageMetrics.from_oai_completion_usage(
                response.usage
            ))
If you want to keep track of the parent of the span, you can pass the parent span as an argument
with tatara.start_span(event="generate_image", parent_event="generate_visual_description"):
    # make model calls here
A parent call in this case, is a model call that your call depends on. For example, your diffusion model might depend on an LLM call. In this case, the LLM call’s span would be the parent of the diffusion call’s span.

Logging images

You can log images by providing a url for the image. For example, you can log with this:
    def log_diffusion_success_with_image_url(
        self,
        image_url: str,
        prompt: str | DiffusionPrompt,
        params: Optional[DiffusionParams] = None,
        image_url_type: Literal["ephemeral", "permalink", "permalink_copy"] = "ephemeral",
    ):
You can also log images by providing the image data and the image format. For example,
    def log_diffusion_success_with_image_data(
        self,
        image_data: str,
        image_format: Union[str, Literal["png", "jpg"]],
        prompt: str | DiffusionPrompt,
        params: Optional[DiffusionParams] = None
    ):
However this is not recommended as it will increase the size of the logs and put more memory pressure on your server. Whenever possible, use the log_diffusion_success_with_image_url function.

Logging async image generation

If the image url isn’t available at the time of generation, you can use the log_diffusion_input and log_diffusion_output_with_image_url functions to log the input and output of the diffusion model.
log_diffusion_input(
    trace_id: str,
    event: str,
    prompt: DiffusionPrompt | str,
    params: Optional[DiffusionParams] = None,
)

log_diffusion_output_with_image_url(image_url: str, trace_id: str, event: str)