Skip to Content
TracingSemantic Conventions

Semantic Conventions

Rhesis uses a semantic layer for consistent, framework-agnostic span naming across all AI operations.

Naming Pattern

All span names follow the pattern: ai.<domain>.<action>

Valid Span Names

Span NameConstantDescription
ai.llm.invokeAIOperationType.LLM_INVOKELLM API call
ai.tool.invokeAIOperationType.TOOL_INVOKETool/function execution
ai.retrievalAIOperationType.RETRIEVALInformation retrieval
ai.embedding.generateAIOperationType.EMBEDDING_GENERATEGenerate embeddings
ai.rerankAIOperationType.RERANKReranking operation
ai.evaluationAIOperationType.EVALUATIONEvaluation operation
ai.guardrailAIOperationType.GUARDRAILSafety check
ai.transformAIOperationType.TRANSFORMData transformation

Using Constants

app.py
from rhesis.sdk.telemetry.schemas import AIOperationType

# Span name constants
AIOperationType.LLM_INVOKE          # "ai.llm.invoke"
AIOperationType.TOOL_INVOKE         # "ai.tool.invoke"
AIOperationType.RETRIEVAL           # "ai.retrieval"
AIOperationType.EMBEDDING_GENERATE  # "ai.embedding.generate"
AIOperationType.RERANK              # "ai.rerank"
AIOperationType.EVALUATION          # "ai.evaluation"
AIOperationType.GUARDRAIL           # "ai.guardrail"
AIOperationType.TRANSFORM           # "ai.transform"

Forbidden Span Names

Framework concepts are rejected with HTTP 422:

Invalid NameReason
ai.agent.run”Agent” is a framework concept
ai.chain.execute”Chain” is an orchestration pattern
ai.workflow.start”Workflow” is a composition
ai.pipeline.process”Pipeline” is infrastructure

Why Primitive Operations?

Framework concepts are:

  • Composite - Made up of primitive operations
  • Framework-specific - Different frameworks use different terms
  • Opaque - They don’t tell you what actually happened

Instead, trace the primitive operations:

Attribute Constants

Use AIAttributes for span attributes:

app.py
from rhesis.sdk.telemetry.attributes import AIAttributes

span.set_attribute(AIAttributes.MODEL_PROVIDER, "openai")
span.set_attribute(AIAttributes.MODEL_NAME, "gpt-4")
span.set_attribute(AIAttributes.LLM_TOKENS_INPUT, 150)
span.set_attribute(AIAttributes.LLM_TOKENS_OUTPUT, 200)

Model Attributes

ConstantKeyDescription
MODEL_PROVIDERai.model.providerProvider (openai, anthropic)
MODEL_NAMEai.model.nameModel identifier (gpt-4)

LLM Attributes

ConstantKeyDescription
LLM_TOKENS_INPUTai.llm.tokens.inputInput token count
LLM_TOKENS_OUTPUTai.llm.tokens.outputOutput token count
LLM_TOKENS_TOTALai.llm.tokens.totalTotal token count
LLM_TEMPERATUREai.llm.temperatureTemperature parameter
LLM_MAX_TOKENSai.llm.max_tokensMax tokens parameter

Tool Attributes

ConstantKeyDescription
TOOL_NAMEai.tool.nameName of the tool
TOOL_TYPEai.tool.typeType (http, function, database)

Retrieval Attributes

ConstantKeyDescription
RETRIEVAL_BACKENDai.retrieval.backendBackend (pinecone, weaviate)
RETRIEVAL_TOP_Kai.retrieval.top_kNumber of results

Embedding Attributes

ConstantKeyDescription
EMBEDDING_MODELai.embedding.modelModel name
EMBEDDING_VECTOR_SIZEai.embedding.vector.sizeVector dimensions

Operation Type Values

ConstantValueDescription
OPERATION_LLM_INVOKEllm.invokeLLM operation
OPERATION_TOOL_INVOKEtool.invokeTool operation
OPERATION_RETRIEVALretrievalRetrieval operation
OPERATION_EMBEDDING_CREATEembedding.createEmbedding operation
OPERATION_RERANKrerankRerank operation
OPERATION_EVALUATIONevaluationEvaluation operation
OPERATION_GUARDRAILguardrailGuardrail operation
OPERATION_TRANSFORMtransformTransform operation

Events

Use AIEvents for span events:

app.py
from rhesis.sdk.telemetry.attributes import AIEvents, AIAttributes

with tracer.start_as_current_span("ai.llm.invoke") as span:
    # Prompt event
    span.add_event(
        name=AIEvents.PROMPT,
        attributes={
            AIAttributes.PROMPT_ROLE: "user",
            AIAttributes.PROMPT_CONTENT: prompt_text,
        }
    )
    
    response = llm.invoke(prompt_text)
    
    # Completion event
    span.add_event(
        name=AIEvents.COMPLETION,
        attributes={
            AIAttributes.COMPLETION_CONTENT: response.text,
        }
    )

Event Names

ConstantValueDescription
AIEvents.PROMPTai.promptPrompt sent to LLM
AIEvents.COMPLETIONai.completionLLM completion
AIEvents.TOOL_INPUTai.tool.inputTool input
AIEvents.TOOL_OUTPUTai.tool.outputTool output
AIEvents.RETRIEVAL_QUERYai.retrieval.queryRetrieval query
AIEvents.RETRIEVAL_RESULTSai.retrieval.resultsRetrieval results

Trace Hierarchy


Next: Learn about auto-instrumentation for zero-config tracing.