Skip to content
GitHubLog inStart free
cetra is not released yet. These docs describe the development version.

Microsoft Agent Framework

cetra traces Microsoft Agent Framework agent runs and workflows, from the spans the framework writes itself.

Terminal window
pip install cetra-sdk agent-framework-core agent-framework-openai

Turn on the framework’s instrumentation, then send its spans to cetra.

Agent Framework writes its spans to the global OpenTelemetry tracer provider. Start cetra with use_global_provider=True so that it joins that provider, then turn on the framework’s instrumentation. Set CETRA_API_KEY to your sk-cetra-… key and OPENAI_API_KEY to your OpenAI key.

import asyncio
import os
import cetra
from agent_framework import Agent, tool
from agent_framework.observability import enable_instrumentation
from agent_framework.openai import OpenAIChatCompletionClient
cetra.init(use_global_provider=True)
enable_instrumentation(enable_sensitive_data=True)
@tool
def get_weather(city: str) -> str:
"""Get the weather."""
return f"sunny in {city}"
client = OpenAIChatCompletionClient(
model="gpt-4o-mini",
api_key=os.environ["OPENAI_API_KEY"],
)
agent = Agent(
client=client,
name="WeatherAgent",
instructions="You are a weather bot.",
tools=[get_weather],
)
async def run() -> None:
await agent.run("What is the weather in Paris?")
asyncio.run(run())
cetra.flush()

enable_sensitive_data=True makes the framework record the messages and the tool arguments and results. The sample sets it.

  • Python

    • An agent run produces an invoke_agent span named after the agent, with the messages and the tool definitions, then a chat llm span for each model call with the provider, the model, the token counts and the cost, and an execute_tool tool span for each tool call.
    • A workflow produces an invoke_workflow span. Each executor and each edge group is a chain span, and each message the workflow sends is a plain span.
  • .NET

    An agent run produces:

    • an agent span named invoke_agent WeatherAgent(<id>), where the id in parentheses is the agent’s instance id and changes on every run. It carries the input and output messages; its summed token usage is not counted, the llm spans carry the tokens;
    • an llm span named chat gpt-4o-mini for each model call, with the provider openai, the model, the messages, the system instructions, the tool definitions, the token counts and the cost computed from the built-in prices;
    • a tool span named execute_tool get_weather, with the arguments as its input and the result as its output.
  • Python
    • Workflow steps are chain spans. A workflow with no model call has no llm span.
    • The fixtures were captured with agent-framework-core 1.26.0 and agent-framework-openai 1.18.2, not with the agent-framework meta package.
    • Set enable_sensitive_data=True to record content. The sample sets it.
    • Leave OTEL_SEMCONV_STABILITY_OPT_IN unset, or include gen_ai_latest_experimental in it. A value without that token (for example http) switches the framework to its older GenAI conventions, and the spans then carry no message content.
  • .NET
    • Content is off by default: set EnableSensitiveData = true or OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true to record the messages and the tool arguments and results.
    • The agent span’s name ends with the agent’s instance id, which changes on every run.
    • OpenTelemetry .NET 1.21.0 ignores OTEL_EXPORTER_OTLP_TRACES_ENDPOINT. Set OTEL_EXPORTER_OTLP_ENDPOINT, the base URL without the /v1/traces path; the exporter appends the path itself.
    • The capture sent no Authorization header; the header setting above is the library’s documented option, not part of the captured run.
    • The .NET fixture was captured with Microsoft.Agents.AI 1.28.0 and OpenTelemetry .NET 1.21.0. It covers one agent run; workflows were not captured.
  • If a field is missing, look at the span’s Attributes tab and compare it with Span attributes.