Log Outputs

Most auto-instrumentors automatically populate the output field without requiring manual logging. This section reviews manual instrumentation of output.

In the tracing tab, our table view looks for the span attributes "output.value" (or SpanAttributes.OUTPUT_VALUE or SemanticConventions.OUTPUT_VALUE) for to populate the Output column.

When viewing a single span, there are two output fields that are highlighted. Output messages are captured by the SpanAttributes.LLM_OUTPUT_MESSAGES key. This enables you to view the full message returned.

This example code shows how you can log outputs as well. This follows a similar convention to input logging:

from openai.types.chat import ChatCompletionAssistantMessageParam
from openinference.semconv.trace import MessageAttributes, SpanAttributes
from opentelemetry.trace import Span


def set_output_attrs(
    span: Span,
    response_message: ChatCompletionAssistantMessageParam,
) -> None:
    # OUTPUT_VALUE shows up on the table view under the output column
    # It also shows up under the `output` tab on the span
    span.set_attribute(SpanAttributes.OUTPUT_VALUE, response_message.get("content", ""))

    # This shows up under `output_messages` tab on the span page
    # This code assumes a single response
    span.set_attribute(
        f"{SpanAttributes.LLM_OUTPUT_MESSAGES}.0.{MessageAttributes.MESSAGE_ROLE}",
        response_message["role"],
    )
    span.set_attribute(
        f"{SpanAttributes.LLM_OUTPUT_MESSAGES}.0.{MessageAttributes.MESSAGE_CONTENT}",
        response_message.get("content", ""),
    )

Last updated

Copyright © 2023 Arize AI, Inc