Skip to content

fix(prism): delegate structured/embeddings/images calls in TracingProvider - #2

Merged
cybernerdie merged 1 commit into
cybernerdie:mainfrom
olivM:fix/prism-tracing-provider-structured
Aug 6, 2026
Merged

fix(prism): delegate structured/embeddings/images calls in TracingProvider#2
cybernerdie merged 1 commit into
cybernerdie:mainfrom
olivM:fix/prism-tracing-provider-structured

Conversation

@olivM

@olivM olivM commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes: Structured is not supported by TracingProvider (and the same class of error for embeddings(), images(), moderation(), textToSpeech(), speechToText(), stream()) when using the Prism auto-instrumentation driver.

Root cause

Prism's base Prism\Prism\Providers\Provider class defines concrete (non-abstract) default methods for structured(), embeddings(), images(), moderation(), textToSpeech(), speechToText(), and stream(). Each throws:

throw PrismException::unsupportedProviderAction($method, class_basename($this));
// e.g. "Structured is not supported by TracingProvider"

Cybernerdie\Glint\Instrumentation\Prism\TracingProvider extends Provider but only overrode text(). Since the other methods are already concrete on the parent (not abstract), PHP resolves calls to them directly against the inherited implementation instead of falling through to TracingProvider::__call(). That means $this inside the thrown exception is the TracingProvider wrapper, not the real underlying driver — so the error always says "TracingProvider" regardless of which provider (OpenAI, Anthropic, Ollama, etc.) is actually configured, and the call never reaches the real driver even when it does support the action.

Fix

TracingProvider now explicitly overrides structured(), embeddings(), images(), moderation(), textToSpeech(), speechToText(), and stream(), delegating to the wrapped provider via the existing callInner() helper (same pattern already used for text()). If the wrapped provider doesn't support the action either, the error now correctly names that provider instead of TracingProvider.

Tests

The bug wasn't caught previously because the test double at tests/Stubs/Prism/Providers/Provider.php was just abstract class Provider {} — it didn't reproduce Prism's real default-throwing behavior. This PR:

  • Updates the stub Provider class to mirror the real package (default methods that throw "X is not supported by {class}").
  • Adds the minimal stub request/response classes needed (Structured, Embeddings, Images, Moderation, Audio, Exceptions\PrismException).
  • Adds regression tests proving TracingProvider now correctly delegates structured()/embeddings() when the wrapped provider supports them, and that the "unsupported" error names the wrapped provider (e.g. Anthropic), never TracingProvider.
  • Fixes an existing test that overrode embeddings() with an incompatible signature (now fatal once the stub declares the real signature).

Checks

  • composer test — 619 passed
  • composer stan — no errors
  • composer pint — passed

…vider

Prism's base Provider class defines concrete (non-abstract) default
methods for structured(), embeddings(), images(), moderation(),
textToSpeech(), speechToText(), and stream() that throw
"X is not supported by {class}". Because TracingProvider only
overrode text(), calls to these other methods resolved directly to
the inherited default on Provider instead of falling through to
__call(), so the exception incorrectly named "TracingProvider" as
the unsupported provider instead of the real wrapped driver.

TracingProvider now explicitly overrides each of these methods to
delegate to the wrapped provider via callInner(), same as text().
When the wrapped provider doesn't support the action either, the
error now correctly names that provider instead of TracingProvider.

Also updates the Prism test stubs to mirror the real package's
Provider default-throwing behavior, since the previous empty stub
class didn't reproduce this bug.
@cybernerdie
cybernerdie self-requested a review August 6, 2026 04:48
@cybernerdie

Copy link
Copy Markdown
Owner

Hey @olivM , awesome find, and great write-up in the PR description!, this has been tested

Thanks for the contribution, really appreciated! 🙌

@cybernerdie
cybernerdie merged commit ee2e750 into cybernerdie:main Aug 6, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants