This package provides the setup for instrumenting the DSPy framework with OpenTelemetry Generative AI semantic conventions. DSPy operation instrumentation will be added in follow-up changes.
pip install opentelemetry-instrumentation-genai-dspy
from opentelemetry.instrumentation.genai.dspy import (
DSPyInstrumentor,
)
DSPyInstrumentor().instrument()Message content capture is disabled by default. Set
OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT to one of
NO_CONTENT, SPAN_ONLY, EVENT_ONLY, or SPAN_AND_EVENT to record
prompts, completions, and module inputs/outputs.
Instead of recording message content inline, prompts and completions can be uploaded to external storage via a completion hook. To enable the built-in upload hook, set:
OTEL_INSTRUMENTATION_GENAI_COMPLETION_HOOK=uploadOTEL_INSTRUMENTATION_GENAI_UPLOAD_BASE_PATHto anfsspec-compatible URI/path (e.g./path/to/promptsorgs://my_bucket), and install theuploadextra (pip install opentelemetry-util-genai[upload]).
A custom CompletionHook can also be passed programmatically, taking
precedence over the environment variable:
DSPyInstrumentor().instrument(completion_hook=my_hook)