Integrations / Semantic Kernel

Trace Semantic Kernel agents

To trace Semantic Kernel with Tracify in Python, wrap the invocation with trace_agent and open a step around the kernel function or agent call. Plugins you mark show up as steps in order.

Your code

Semantic Kernel

Tracify

One run.

  • 01One trace per kernel invocation
  • 02A step for each function or plugin you mark
  • 03Inputs, outputs and timing
  • 04Errors in order

Setup

5 steps.

  1. 01

    Install

    The Python flavor of Semantic Kernel and the Tracify SDK.

    bash
    pip install tracify-sdk semantic-kernel
  2. 02

    Set your project key

    Create a project in Tracify, copy its API key and put it in the environment where your code runs. The SDK reads it from there, so nothing is hard-coded.

    bash
    export TRACIFY_API_KEY="tracify_sk_live_..."
  3. 03

    Wrap the invocation

    Semantic Kernel is async. trace_agent and span both work in async functions.

    python
    import tracify
    
    @tracify.trace_agent(name="sk-assistant")
    async def ask(question: str) -> str:
        with tracify.span("kernel-invoke", type="agent", input=question) as step:
            result = await kernel.invoke(plugin_name="chat", function_name="answer", question=question)
            step.set_output(str(result))
            return str(result)
  4. 04

    Show plugin calls

    A kernel function decorator is the best place for a step, because every call through it is then recorded wherever it comes from.

    python
    from semantic_kernel.functions import kernel_function
    
    class OrdersPlugin:
        @kernel_function(description="Look up an order by id")
        async def lookup(self, order_id: str) -> str:
            with tracify.span("orders.lookup", type="tool", input=order_id) as step:
                status = await orders_api.status(order_id)
                step.set_output(status)
                return status
  5. 05

    Run it once and look

    Run your code one time, then open the Tracing page of your project. Your kernel call shows up as a run with its steps in order, plus the tokens, time and any error for each call.

Good to know

Python only for now

The Tracify SDKs are available for Python and TypeScript. For Semantic Kernel in .NET or Java, you can send traces to the Tracify API directly.

Good to know

Model calls

Semantic Kernel calls models through its own connectors, so those requests are not wrapped automatically. Mark the function that makes them and you get its timing and output.

Full details in the documentation. All integrations are listed on the integrations page.

Does Tracify read Semantic Kernel's OpenTelemetry output?
Tracify accepts OTLP over HTTP with JSON. Many OpenTelemetry exporters send protobuf by default, so check your exporter's protocol before relying on it.
Can I trace planners and multi-step agents?
Yes. Wrap the planner or agent call, and add a step to each plugin function it can call.
Does it work with async kernels?
Yes. Concurrent invocations are kept in separate traces.

Send your first trace.

Free to start.