Prerequisites
-
Install LangWatch SDK:
-
Install Semantic Kernel and OpenInference instrumentor:
- Set up your OpenAI API key: You’ll need to configure your OpenAI API key in your environment.
Instrumentation with OpenInference
LangWatch supports observability for Semantic Kernel using the OpenInference OpenAI instrumentor. This approach captures traces from your Semantic Kernel calls and sends them to LangWatch.Basic Setup (Automatic Tracing)
Here’s the simplest way to instrument your application:Optional: Using Decorators for Additional Context
If you want to add additional context or metadata to your traces, you can optionally use the@langwatch.trace()
decorator:
How it Works
-
langwatch.setup()
: Initializes the LangWatch SDK, which includes setting up an OpenTelemetry trace exporter. This exporter is ready to receive spans from any OpenTelemetry-instrumented library in your application. -
OpenAIInstrumentor()
: The OpenInference instrumentor automatically patches OpenAI client operations to create OpenTelemetry spans for their operations, including:- Chat completions
- Model calls
- Response parsing
- Error handling
- Semantic Kernel Integration: The OpenAI instrumentor captures Semantic Kernel operations (function invocations, prompt processing, etc.) as spans.
-
Optional Decorators: You can optionally use
@langwatch.trace()
to add additional context and metadata to your traces, but it’s not required for basic functionality.
Notes
- You do not need to set any OpenTelemetry environment variables or configure exporters manually—
langwatch.setup()
handles everything. - You can combine Semantic Kernel instrumentation with other instrumentors (e.g., LangChain, DSPy) by adding them to the
instrumentors
list. - The
@langwatch.trace()
decorator is optional - the OpenInference instrumentor will capture Semantic Kernel activity. - For advanced configuration (custom attributes, endpoint, etc.), see the Python integration guide.
Troubleshooting
- Make sure your
LANGWATCH_API_KEY
is set in the environment. - If you see no traces in LangWatch, check that the instrumentor is included in
langwatch.setup()
and that your Semantic Kernel code is being executed. - Ensure you have the correct OpenAI API key set.
- Verify that your Semantic Kernel functions are properly defined and invoked.