This example demonstrates how to use the LaunchDarkly observability SDK plugin to monitor AI chat operations. For more details, see the Python SDK observability reference.
The observability plugin automatically captures and sends data to LaunchDarkly:
- Observability tab: SDK operations, flag evaluations, error monitoring, logging, and distributed tracing
- AI Config Monitoring tab: Token usage, duration, success/error rates, and custom metadata for filtering and analysis
View your data in the LaunchDarkly dashboard under Observability tabs.
- Python 3.10 or higher
- Poetry installed
- A LaunchDarkly account with an AI Config created
- An API key for your AI provider (e.g., OpenAI)
-
Create a
.envfile in this directory with the following variables:LAUNCHDARKLY_SDK_KEY=your-launchdarkly-sdk-key LAUNCHDARKLY_AI_CONFIG_KEY=sample-ai-config OPENAI_API_KEY=your-openai-api-keyLAUNCHDARKLY_AI_CONFIG_KEYdefaults tosample-ai-configif not set.Optionally, set service identification:
SERVICE_NAME=my-ai-service SERVICE_VERSION=1.0.0 -
Install the required dependencies:
poetry install
poetry run chat-observability-example