feat(ai): add invoke_agent tracing baseline#1107
feat(ai): add invoke_agent tracing baseline#1107constantinius wants to merge 8 commits intoconstantinius/feat/ai/integration-basefrom
Conversation
Add the initial AI integration wiring that records invoke_agent spans for prompting and prompted lifecycle events, including model/provider and token usage metadata. This establishes the stack base without chat, tool, message, or embeddings instrumentation. Made-with: Cursor
| $provider = $event->prompt->provider ?? null; | ||
| $providerName = $provider !== null ? $provider->name() : null; | ||
| if ($providerName !== null) { | ||
| $data['gen_ai.provider.name'] = $providerName; |
There was a problem hiding this comment.
Provider name normalization applied inconsistently across handlers
Low Severity
The gen_ai.provider.name value is set from $provider->name() without normalization in handlePromptingAgentForTracing, but the fallback path in handleAgentPromptedForTracing applies strtolower() to the response metadata string. If a provider's name() method returns a non-lowercase value, the same provider gets different casing in span data depending on which code path set it, leading to inconsistent telemetry that complicates filtering and aggregation in dashboards.
Additional Locations (1)
Replace inline stub definitions for Laravel AI interfaces, classes, events, attributes, and file types with the real implementations from the laravel/ai package added as a dev dependency. Drop PHP version and Laravel version skip guards from setUp() since these tests only run on PHP 8.4+. Simplify TestAgentWithConfig to use native PHP 8 attributes directly instead of the eval() workaround for older PHP versions.
Remove laravel/ai globally in both phpunit and phpunit-legacy jobs since it requires PHP 8.4+ and only supports Laravel 12. Re-add it conditionally for the supported combination (PHP 8.4+, Laravel 12).
69471c9 to
6f06a2c
Compare
The Laravel AI classes are not available when PHPStan runs on PHP 8.3 without laravel/ai installed. Add baseline ignores matching the existing pattern used for other optional packages (Sanctum, Livewire, Lumen).
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| $parts = explode('\\', \get_class($obj)); | ||
|
|
||
| return end($parts); | ||
| } |
There was a problem hiding this comment.
Custom method reimplements Laravel's built-in class_basename helper
Low Severity
The shortClassName method reimplements Laravel's built-in class_basename() helper, which has been available since Laravel 4.x. Both extract the unqualified class name by splitting a fully-qualified class name on namespace separators. Since this package already depends on laravel/framework, the custom method adds unnecessary code.


Add the initial AI integration wiring that records invoke_agent spans for prompting and prompted lifecycle events, including model/provider and token usage metadata. This establishes the stack base without chat, tool, message, or embeddings instrumentation.
Included
AiIntegrationin the feature list.tracing.gen_aitracing.gen_ai_invoke_agentPromptingAgent/StreamingAgent-> startinvoke_agentspanAgentPrompted/AgentStreamed-> finishinvoke_agentspanMade-with: Cursor
Issues