Semantic Kernel Integration via OpenTelemetry

Semantic Kernel is Microsoft’s AI orchestration framework designed to simplify the integration of AI services into applications. It provides a unified programming model for working with different AI models, memory systems, and plugins, making it easier to build intelligent applications.

Semantic Kernel’s primary advantage is its seamless integration with Microsoft’s AI ecosystem and its plugin architecture that allows developers to easily extend functionality with custom skills and connectors.

Getting started

To use the Semantic Kernel integration with Opik, you will need to have Semantic Kernel and the required OpenTelemetry packages installed:

$pip install semantic-kernel openinference-instrumentation-semantic-kernel opentelemetry-api opentelemetry-sdk opentelemetry-exporter-otlp

Environment configuration

Configure your environment variables based on your Opik deployment:

If you are using Opik Cloud, you will need to set the following environment variables:

$export OTEL_EXPORTER_OTLP_ENDPOINT=https://www.comet.com/opik/api/v1/private/otel
>export OTEL_EXPORTER_OTLP_HEADERS='Authorization=<your-api-key>,Comet-Workspace=default'

To log the traces to a specific project, you can add the projectName parameter to the OTEL_EXPORTER_OTLP_HEADERS environment variable:

$export OTEL_EXPORTER_OTLP_HEADERS='Authorization=<your-api-key>,Comet-Workspace=default,projectName=<your-project-name>'

You can also update the Comet-Workspace parameter to a different value if you would like to log the data to a different workspace.

Using Opik with Semantic Kernel

Set up OpenTelemetry instrumentation for Semantic Kernel:

1from opentelemetry import trace
2from opentelemetry.sdk.trace import TracerProvider
3from opentelemetry.sdk.trace.export import BatchSpanProcessor
4from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
5from openinference.instrumentation.semantic_kernel import SemanticKernelInstrumentor
6
7# Configure the OTLP exporter
8otlp_exporter = OTLPSpanExporter()
9
10# Set up the tracer provider
11trace.set_tracer_provider(TracerProvider())
12trace.get_tracer_provider().add_span_processor(
13 BatchSpanProcessor(otlp_exporter)
14)
15
16# Instrument Semantic Kernel
17SemanticKernelInstrumentor().instrument()
18
19# Your Semantic Kernel code will now automatically send traces to Opik
20import semantic_kernel as sk
21
22kernel = sk.Kernel()
23# ... kernel configuration

Further improvements

If you have any questions or suggestions for improving the Semantic Kernel integration, please open an issue on our GitHub repository.