Custom Spans
Create custom spans with specific names and attributes for advanced observability needs.
Custom Span Names
Use the span_name parameter to set a semantic span name:
Custom Attributes
Pass additional attributes directly to the decorator:
Attribute Constants
Import attribute constants from rhesis.sdk.telemetry:
Model Attributes
| Constant | Key | Description |
|---|---|---|
MODEL_PROVIDER | ai.model.provider | Provider name (openai, anthropic) |
MODEL_NAME | ai.model.name | Model identifier (gpt-4, claude-3) |
LLM Attributes
| Constant | Key | Description |
|---|---|---|
LLM_TOKENS_INPUT | ai.llm.tokens.input | Input token count |
LLM_TOKENS_OUTPUT | ai.llm.tokens.output | Output token count |
LLM_TOKENS_TOTAL | ai.llm.tokens.total | Total token count |
LLM_TEMPERATURE | ai.llm.temperature | Temperature parameter |
LLM_MAX_TOKENS | ai.llm.max_tokens | Max tokens parameter |
Tool Attributes
| Constant | Key | Description |
|---|---|---|
TOOL_NAME | ai.tool.name | Tool name |
TOOL_TYPE | ai.tool.type | Type (http, function, database) |
Retrieval Attributes
| Constant | Key | Description |
|---|---|---|
RETRIEVAL_BACKEND | ai.retrieval.backend | Backend (pinecone, weaviate) |
RETRIEVAL_TOP_K | ai.retrieval.top_k | Number of results |
Embedding Attributes
| Constant | Key | Description |
|---|---|---|
EMBEDDING_MODEL | ai.embedding.model | Model name |
EMBEDDING_VECTOR_SIZE | ai.embedding.vector.size | Vector dimensions |
Event Names
| Constant | Value | Description |
|---|---|---|
AIEvents.PROMPT | ai.prompt | Prompt sent to LLM |
AIEvents.COMPLETION | ai.completion | LLM completion |
AIEvents.TOOL_INPUT | ai.tool.input | Tool input data |
AIEvents.TOOL_OUTPUT | ai.tool.output | Tool output data |
Helper Functions
Use helper functions to create attribute dictionaries:
Building Custom Decorators
Create your own convenience decorators by wrapping @observe:
Example: Full Custom Implementation
Next: Learn about auto-instrumentation for zero-config tracing.