SAP Cloud SDK for Python
The SAP Cloud SDK for Python has a telemetry module that auto-instruments LLM calls and gives you context managers for agent, chat, and tool spans — all emitting the OpenTelemetry GenAI attributes Boidra Platform reads. This is the recommended path for Python agents.
Source of truth: the SDK's telemetry user guide. APIs can change upstream — check there if a signature differs.
1. Point the exporter at Boidra Platform
Boidra Platform ingests OTLP/HTTP, but this SDK defaults to gRPC. Set both the endpoint and the protocol:
export OTEL_EXPORTER_OTLP_ENDPOINT="https://<your-dashboard-host>/otel"
export OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf"Debug locally first
Set OTEL_TRACES_EXPORTER=console to print spans to your terminal before sending them to a dashboard — handy for confirming the right attributes are set.
2. Enable telemetry
Call auto_instrument() before importing your AI libraries so their calls are traced:
from sap_cloud_sdk.core.telemetry import auto_instrument
auto_instrument() # LLM calls are now automatically traced
from litellm import completion # import AI libs AFTER auto_instrument()auto_instrument(middlewares=None, disable_batch=False) — pass disable_batch=True to export spans immediately instead of batching (useful in short-lived scripts).
3. Wrap an agent turn
Use invoke_agent_span(...) around a top-level agent turn. This becomes an invoke_agent span in Boidra Platform, and the auto-instrumented LLM/tool calls nest underneath it:
from sap_cloud_sdk.core.telemetry import (
auto_instrument, invoke_agent_span, set_tenant_id,
)
auto_instrument()
from litellm import completion
def handle_request(query: str, user_id: str):
set_tenant_id("your-tenant-id") # set at the request boundary
with invoke_agent_span(
provider="openai",
agent_name="SupportBot",
attributes={"user.id": user_id},
):
return completion(
model="gpt-4",
messages=[{"role": "user", "content": query}],
)Span helpers → Boidra Platform
| SDK call | Boidra Platform span | Populates |
|---|---|---|
invoke_agent_span(provider, agent_name, conversation_id?, attributes?, propagate?) | invoke_agent | agent name, conversation id |
chat_span(model, provider, conversation_id?, attributes?) | chat | model (tokens come from auto-instrumentation) |
execute_tool_span(tool_name, tool_type?, tool_description?, attributes?) | execute_tool | tool name, tool type |
set_tenant_id(tenant_id) | — | tenant id on the spans in this request |
context_overlay(operation, attributes?) | per operation | generic operations without a dedicated helper |
conversation_idoninvoke_agent_spanmaps to Boidra Platform's context id, which groups a multi-turn conversation across traces.- Tokens are filled in automatically for auto-instrumented LLM calls (via
gen_ai.usage.*); if you create achat_spanmanually around a non-instrumented call, set those attributes yourself (see the OTel SDK guide).
Manual chat and tool spans
When autoinstrumentation doesn't cover a call, wrap it explicitly:
from sap_cloud_sdk.core.telemetry import chat_span, execute_tool_span
with chat_span(model="gpt-4o", provider="openai"):
... # your LLM call
with execute_tool_span(tool_name="get_incident", tool_type="mcp"):
... # your tool / MCP callVerify
Run your agent, then open the dashboard's Traces page (or the Live tab). You should see an invoke_agent trace for your agent with nested chat/tool spans, the model, and token counts. If nothing appears, temporarily set OTEL_TRACES_EXPORTER=console to confirm spans are being produced, and double-check OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf.
