Skip to main content
Semantic Kernel emits OpenTelemetry traces following the GenAI semantic conventions when its model diagnostics are enabled. 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

1

Install the OpenTelemetry SDK and OTLP exporter

pip install semantic-kernel \
  opentelemetry-sdk opentelemetry-exporter-otlp-proto-http
2

Enable model diagnostics

Set these before importing semantic_kernel. The first enables GenAI spans; the second adds prompt and response content as log events.
import os

os.environ["SEMANTICKERNEL_EXPERIMENTAL_GENAI_ENABLE_OTEL_DIAGNOSTICS"] = "true"
os.environ["SEMANTICKERNEL_EXPERIMENTAL_GENAI_ENABLE_OTEL_DIAGNOSTICS_SENSITIVE"] = "true"
3

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.
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)
4

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.

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 cost and latency are tracked, and token counts feed cost tracking automatically.
Semantic Kernel records prompt and response content as OpenTelemetry log events rather than span attributes, so message text does not 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 or Pydantic AI).

Next steps

OpenTelemetry

The endpoint, authentication, and GenAI conventions AgentMark reads

Traces and logs

Explore traces once they arrive

Have questions?

Reach out any time: