> ## Documentation Index
> Fetch the complete documentation index at: https://docs.openlayer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Semantic Kernel

> Learn how to export Semantic Kernel traces to Openlayer

<img width="700" style={{ borderRadius: "0.5rem" }} src="https://mintcdn.com/openlayer-44/zlWrng2mbxttdDP9/images/integrations/semantic_kernel_hero.png?fit=max&auto=format&n=zlWrng2mbxttdDP9&q=85&s=4befe40d8d4255c9f04649a47d695f6a" alt="Semantic Kernel hero" data-path="images/integrations/semantic_kernel_hero.png" />

[Semantic Kernel](https://learn.microsoft.com/en-us/semantic-kernel/overview/) is an
open-source SDK from Microsoft that helps you build AI applications using languages
like Python, C#, and Java. It comes with built-in OpenTelemetry
instrumentation, making it easy to export trace data.

This guide shows how to export Semantic Kernel traces to Openlayer for observability
and evaluation.

<Info>
  While this guide shows code snippets in Python, the integration also works for
  all other programming languages supported by Semantic Kernel, such as
  [C#](https://learn.microsoft.com/en-us/semantic-kernel/concepts/enterprise-readiness/observability/?pivots=programming-language-csharp),
  and
  [Java](https://learn.microsoft.com/en-us/semantic-kernel/concepts/enterprise-readiness/observability/?pivots=programming-language-java).
</Info>

## Configuration

The integration works by sending trace data to Openlayer's [OpenTelemetry endpoint](/integrations/opentelemetry).

<Tip>
  The full code used in this guide is available
  [here](https://colab.research.google.com/github/openlayer-ai/openlayer-python/blob/main/examples/tracing/semantic-kernel/semantic_kernel.ipynb).
</Tip>

To set it up, you need to:

<Steps>
  <Step title="Set the environment variables">
    Set the following environment variables:

    ```bash theme={null}
    OTEL_EXPORTER_OTLP_ENDPOINT="https://api.openlayer.com/v1/otel"
    OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer YOUR_OPENLAYER_API_KEY_HERE, x-bt-parent=pipeline_id:YOUR_PIPELINE_ID_HERE"
    ```
  </Step>

  <Step title="Initialize OpenLIT and Semantic Kernel">
    Initialize OpenLIT and Semantic Kernel in your application.

    ```python theme={null}
    import openlit
    from semantic_kernel import Kernel

    openlit.init(disable_batch=True)
    kernel = Kernel()
    ```
  </Step>

  <Step title="Run LLMs and workflows as usual">
    Once instrumentation is set up, you can run your LLM calls as usual.
    Trace data will be automatically captured and exported to Openlayer, where
    you can begin testing and analyzing it.

    For example:

    ```python theme={null}
    from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion
    from semantic_kernel.prompt_template import InputVariable, PromptTemplateConfig

    kernel.add_service(
        OpenAIChatCompletion(ai_model_id="gpt-4o-mini"),
    )


    prompt = """{{$input}}
    Please provide a concise response to the question above.
    """

    prompt_template_config = PromptTemplateConfig(
        template=prompt,
        name="question_answerer",
        template_format="semantic-kernel",
        input_variables=[
            InputVariable(name="input", description="The question from the user", is_required=True),
        ]
    )

    summarize = kernel.add_function(
        function_name="answerQuestionFunc",
        plugin_name="questionAnswererPlugin",
        prompt_template_config=prompt_template_config,
    )

    await kernel.invoke(summarize, input="What's the meaning of life?")
    ```
  </Step>
</Steps>
