Span Kind

Span Kind:

The first and most important attribute to set is the SpanKind. This will not be automatically set for you if you are using manual tracing. Setting this will enable certain types of fields to appear as well as help you organize your traces to look like your code structure.

from openinference.semconv.trace import (
    OpenInferenceSpanKindValues, 
    SpanAttributes,
)

# Agent Span
# Use this to wrap agentic flows that may involve multiple LLM and/or tool calls
span.set_attribute(
    SpanAttributes.OPENINFERENCE_SPAN_KIND,
    OpenInferenceSpanKindValues.AGENT.value
)

# LLM Span
# Use this to wrap the LLM call
span.set_attribute(
    SpanAttributes.OPENINFERENCE_SPAN_KIND,
    OpenInferenceSpanKindValues.LLM.value,
)

# Tool Span
# Use this to wrap any tool calls
span.set_attribute(
    SpanAttributes.OPENINFERENCE_SPAN_KIND,
    OpenInferenceSpanKindValues.TOOL.value,
)

# Chain span
# Use this to wrap any preparation step where a prompt template 
# is combined with prompt variables before being sent to an LLM
span.set_attribute(
    SpanAttributes.OPENINFERENCE_SPAN_KIND,
    OpenInferenceSpanKindValues.CHAIN.value,
)

# Chain span
# Use this to wrap any preparation step where a prompt template 
# is combined with prompt variables before being sent to an LLM
span.set_attribute(
    SpanAttributes.OPENINFERENCE_SPAN_KIND,
    OpenInferenceSpanKindValues.CHAIN.value,
)

# Retriever span
# Use this to wrap any step that retrieves documents before sending it to the LLM 
span.set_attribute(
    SpanAttributes.OPENINFERENCE_SPAN_KIND,
    OpenInferenceSpanKindValues.RETRIEVER.value,
)

# Embedding span
# Use this to wrap the embedding step used by the retriever
span.set_attribute(
    SpanAttributes.OPENINFERENCE_SPAN_KIND,
    OpenInferenceSpanKindValues.EMBEDDING.value,
)

# Reranker span
# Use this to wrap any reranker step used after the retriever
span.set_attribute(
    SpanAttributes.OPENINFERENCE_SPAN_KIND,
    OpenInferenceSpanKindValues.RERANKER.value,
)

Last updated

Copyright © 2023 Arize AI, Inc

#1912:

Change request updated