Configure Telemetry: Decorators
Decorators are the sweet spot between zero-code auto-instrumentation and manual span creation. Wrap any function with @observe (or a typed variant) and the SDK handles span naming, I/O capture, and attribute stamping for you. Use this mode for frameworks not covered by auto-instrumentation: CrewAI, OpenAI Agents SDK, or your own hand-rolled pipeline.
What You’ll Achieve
- A traced entry point (
@endpoint) that’s also registered for remote testing - Typed spans (
ai.llm.invoke,ai.tool.invoke,ai.retrieval, …) around your internal functions - Correct parent-child nesting with zero manual OpenTelemetry code
Prerequisites
RhesisClientinitialized: see Configuring Telemetry
Setup
Decorate your entry point
@endpoint registers the function for remote testing via the Rhesis connector and traces it as the root span:
Decorate internal steps with typed spans
Each typed decorator maps to a specific span name and stamps the matching semantic attributes:
Verify the trace tree
Run the endpoint once and check the dashboard. You should see:
Typed Decorator Reference
| Decorator | Span Name | Required Params |
|---|---|---|
@observe() | function.<name> | none |
@observe.llm() | ai.llm.invoke | provider`, `model |
@observe.tool() | ai.tool.invoke | name`, `tool_type |
@observe.retrieval() | ai.retrieval | backend |
@observe.embedding() | ai.embedding.generate | model |
@observe.rerank() | ai.rerank | model |
@observe.agent() | ai.agent.invoke | name |
@observe.evaluation() | ai.evaluation | metric`, `evaluator |
@observe.guardrail() | ai.guardrail | guardrail_type`, `provider |
@observe.transform() | ai.transform | transform_type`, `operation |
@endpoint() | function.<name> | none |
Multi-Agent Example
Agent handoffs are ordinary nested spans plus an explicit ai.agent.handoff span:
For frameworks with native handoff support, see Multi-Agent Tracing.
Tracking Multi-Turn Conversations
If you’re instrumenting a custom chat server (not using @endpoint’s automatic session_id handling), manage conversation context explicitly so turns are grouped into one trace:
Prefer @endpoint() with a returned session_id field when you can: the Rhesis connector manages this context for you automatically. Manual context management is only needed for custom chat servers outside the connector.
Combining with Auto-Instrumentation
The SDK deduplicates automatically: @observe.llm() sets a context flag that tells the auto-instrumentation callback to skip creating a duplicate span for the same call.
You have working traces. Need finer control over attributes or events than the typed decorators expose? See Raw OpenTelemetry.
Related:
- Decorators Reference - full
@observeand@endpointAPI - Conversation Tracing - deep reference on turn management
- Configuring Telemetry - back to the mode overview