Python · Instrumentation
openinference-instrumentation-dspy
OpenInference DSPy Instrumentation
- Module
openinference.instrumentation.dspy- Version
- 0.1.55
- Python
- >=3.10, <3.15
- Instruments
dspy >= 2.6.22
Install
pip install openinference-instrumentation-dspyUsage
Instrument once, at startup, before the library is used. The DSPyInstrumentor reference below lists the options.
from opentelemetry.sdk.trace import TracerProvider
from openinference.instrumentation import TraceConfig
from openinference.instrumentation.dspy import DSPyInstrumentor
tracer_provider = TracerProvider()
# ...add a span processor that exports to Phoenix or any OTLP backend.
DSPyInstrumentor().instrument(
tracer_provider=tracer_provider,
config=TraceConfig(hide_inputs=True), # optional
)openinference.instrumentation.dspy
DSPyInstrumentor
classSource ↗class DSPyInstrumentor(BaseInstrumentor)OpenInference Instrumentor for DSPy
instrument
methoddef instrument(
*,
tracer_provider: Optional[TracerProvider] = None,
config: Optional[TraceConfig] = None,
skip_dep_check: bool = False,
) -> NoneStart tracing dspy: patch it so its calls make OpenInference spans. Calling it again does nothing. Inherited from OpenTelemetry’s BaseInstrumentor.
Parameters
| Name | Description |
|---|---|
tracer_provider | The tracer provider the spans are made with. Defaults to the global one, |
config | What the spans record: hide inputs, outputs or messages, or limit image sizes. Defaults to |
skip_dep_check | Instrument even if the installed version of |
uninstrument
methoddef uninstrument() -> NoneStop tracing: undo the patches instrument() made. Inherited from OpenTelemetry’s BaseInstrumentor.
instrumentation_dependencies
methodSource ↗def instrumentation_dependencies() -> Collection[str]CopyableBoundFunctionWrapper
classSource ↗class CopyableBoundFunctionWrapper(BoundFunctionWrapper)A bound function wrapper that can be copied and deep-copied. When used to wrap a class method, this allows the entire class to be copied and deep-copied.
For reference, see https://github.com/GrahamDumpleton/wrapt/issues/86#issuecomment-426161271 and https://wrapt.readthedocs.io/en/master/wrappers.html#custom-function-wrappers
CopyableFunctionWrapper
classSource ↗class CopyableFunctionWrapper(FunctionWrapper)A function wrapper that can be copied and deep-copied. When used to wrap a class method, this allows the entire class to be copied and deep-copied.
For reference, see https://github.com/GrahamDumpleton/wrapt/issues/86#issuecomment-426161271 and https://wrapt.readthedocs.io/en/master/wrappers.html#custom-function-wrappers
DSPyJSONEncoder
classSource ↗class DSPyJSONEncoder(json.JSONEncoder)Provides support for non-JSON-serializable objects in DSPy.
SafeJSONEncoder
classSource ↗class SafeJSONEncoder(json.JSONEncoder)Safely encodes non-JSON-serializable objects.
parse_provider_and_model
functionSource ↗def parse_provider_and_model(
model_str: Optional[str],
) -> tuple[Optional[str], Optional[str]]Parse a model string like ‘openai/gpt-4’, ‘text-completion-openai/gpt-3.5-turbo-instruct/’, etc. Returns (provider, model_name), both lowercased and stripped of trailing slashes.
unwrap_object
functionSource ↗def unwrap_object(module: Any, name: str) -> Optional[Any]Undo wrapt-style wrapping by restoring the original method that lives under the wrapped chain.
Parameters
| Name | Type | Description |
|---|---|---|
module | Any | class, instance, or module where the method was wrapped. |
name | str | attribute name to unwrap. |
Returns
| Type | Description |
|---|---|
Optional[Any] | The restored original attribute, or None if not wrapped. |