> ## Documentation Index
> Fetch the complete documentation index at: https://puzzlet-9ba7bb98.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Semantic Kernel

> Trace Microsoft Semantic Kernel in AgentMark using its native OpenTelemetry GenAI diagnostics.

[Semantic Kernel](https://github.com/microsoft/semantic-kernel) emits OpenTelemetry traces following the GenAI semantic conventions when you enable its model diagnostics. There's no separate instrumentor to install. Turn on diagnostics, point an OpenTelemetry exporter at AgentMark, and the model spans arrive normalized. The example below is Python.

## Setup

<Steps>
  <Step title="Install the OpenTelemetry SDK and OTLP exporter">
    ```bash theme={null}
    pip install semantic-kernel \
      opentelemetry-sdk opentelemetry-exporter-otlp-proto-http
    ```
  </Step>

  <Step title="Enable model diagnostics">
    Set these before importing `semantic_kernel`. The first enables GenAI spans; the second adds prompt and response content as log events.

    ```python theme={null}
    import os

    os.environ["SEMANTICKERNEL_EXPERIMENTAL_GENAI_ENABLE_OTEL_DIAGNOSTICS"] = "true"
    os.environ["SEMANTICKERNEL_EXPERIMENTAL_GENAI_ENABLE_OTEL_DIAGNOSTICS_SENSITIVE"] = "true"
    ```
  </Step>

  <Step title="Point the exporter at AgentMark">
    Semantic Kernel reads the global tracer provider, so register one that exports to AgentMark. Use your AgentMark API key and app id from project settings.

    ```python theme={null}
    from opentelemetry import trace
    from opentelemetry.sdk.trace import TracerProvider
    from opentelemetry.sdk.trace.export import BatchSpanProcessor
    from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter

    provider = TracerProvider()
    provider.add_span_processor(
        BatchSpanProcessor(
            OTLPSpanExporter(
                endpoint="https://api.agentmark.co/v1/traces",
                headers={
                    "Authorization": "<YOUR_API_KEY>",  # raw key, no "Bearer" prefix
                    "X-Agentmark-App-Id": "<YOUR_APP_ID>",
                },
            )
        )
    )
    trace.set_tracer_provider(provider)
    ```
  </Step>

  <Step title="Run your kernel">
    Run your kernel as usual. Each model call arrives in AgentMark as a span, grouped into a trace. See [Traces and logs](/observe/traces-and-logs).
  </Step>
</Steps>

## What AgentMark captures

Semantic Kernel's GenAI spans carry the model, token counts, and finish reason, which AgentMark maps onto its normalized trace fields, so AgentMark tracks cost and latency, and token counts feed [cost tracking](/observe/cost-and-token-tracking) automatically.

<Note>
  Semantic Kernel records prompt and response **content** as OpenTelemetry log events rather than span attributes, so message text doesn't appear on the trace through this path, only the model, token counts, and timing. For full input/output capture, use a framework with an OpenInference instrumentor (for example [LangChain](/integrations/frameworks/langchain) or [Pydantic AI](/integrations/frameworks/pydantic-ai)).
</Note>

## Next steps

<CardGroup cols={2}>
  <Card title="OpenTelemetry" icon="plug" href="/integrations/tracing/opentelemetry">
    The endpoint, authentication, and GenAI conventions AgentMark reads
  </Card>

  <Card title="Traces and logs" icon="list-tree" href="/observe/traces-and-logs">
    Explore traces once they arrive
  </Card>
</CardGroup>

<div className="mt-8 rounded-lg bg-blue-50 p-6 dark:bg-blue-900/30">
  <h3 className="font-semibold mb-3">Have questions?</h3>
  <p className="mb-4">Reach out any time:</p>

  <ul>
    <li>
      Email the team at <a href="mailto:hello@agentmark.co" className="text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-200">[hello@agentmark.co](mailto:hello@agentmark.co)</a> for support
    </li>

    <li>
      Schedule an <a href="https://cal.com/ryan-randall/enterprise" className="text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-200">Enterprise Demo</a> to learn about AgentMark's business solutions
    </li>
  </ul>
</div>
