Skip to content

[opentelemetry-instrumentation-genai-dspy] Support copy and deepcopy on wrapped DSPy methods - #591

Open
DylanRussell wants to merge 4 commits into
DylanRussell/dspy_instrumentationfrom
DylanRussell/dspy_instrumentation_2
Open

[opentelemetry-instrumentation-genai-dspy] Support copy and deepcopy on wrapped DSPy methods#591
DylanRussell wants to merge 4 commits into
DylanRussell/dspy_instrumentationfrom
DylanRussell/dspy_instrumentation_2

Conversation

@DylanRussell

@DylanRussell DylanRussell commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Implements copy and deepcopy support on wrapped DSPy functions and bound methods.

DSPy optimizers and teleprompters (such as dspy.compile, BootstrapFewShot, and MIPRO) rely heavily on copy.copy and copy.deepcopy to clone module trees and bound method callables during prompt optimization. Without custom wrapper copy handlers, copying wrapped DSPy callables raises NotImplementedError: object proxy must define __deepcopy__().

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • Followed the style guidelines of this project
  • Changelog updated if the change requires an entry
  • Unit tests added
  • Documentation updated

@DylanRussell
DylanRussell marked this pull request as ready for review September 3, 2026 18:14
@DylanRussell
DylanRussell requested a review from a team as a code owner September 3, 2026 18:14
Copilot AI lite review requested due to automatic review settings September 3, 2026 18:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Pull request overview

Adds copy.copy / copy.deepcopy support for DSPy callables after they’ve been wrapped for OpenTelemetry tracing, to keep DSPy compilation/optimizers working without ObjectProxy deepcopy errors.

Changes:

  • Introduces custom copy/deepcopy-capable wrapt wrappers and switches patching to use them.
  • Adds unit tests covering copying/deepcopying wrapped Tool callables and ReAct methods (including async when available).
  • Adds a changelog entry documenting the new compatibility behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
instrumentation/opentelemetry-instrumentation-genai-dspy/tests/test_instrumentor.py Adds regression tests asserting wrapped DSPy callables can be copied/deepcopied (sync + async).
instrumentation/opentelemetry-instrumentation-genai-dspy/src/opentelemetry/instrumentation/genai/dspy/patch.py Implements copyable/deepcopyable wrapper classes and replaces wrapping mechanism.
instrumentation/opentelemetry-instrumentation-genai-dspy/.changelog/591.added Documents the added copy/deepcopy compatibility.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Sep 3, 2026

Copy link
Copy Markdown

Pull request dashboard status

Waiting on reviewers · refreshed 2026-09-04 14:32 UTC

Review the latest changes.

Also blocked by: Merge conflicts.

Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

@DylanRussell DylanRussell changed the title Support copy and deepcopy on wrapped DSPy methods [opentelemetry-instrumentation-genai-dspy] Support copy and deepcopy on wrapped DSPy methods Sep 3, 2026
@DylanRussell
DylanRussell force-pushed the DylanRussell/dspy_instrumentation_2 branch from 31c01ef to 8cd8c38 Compare September 3, 2026 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants