Skip to content

feat(ai): add invoke_agent tracing baseline#1107

Open
constantinius wants to merge 8 commits intoconstantinius/feat/ai/integration-basefrom
constantinius/feat/ai/integration
Open

feat(ai): add invoke_agent tracing baseline#1107
constantinius wants to merge 8 commits intoconstantinius/feat/ai/integration-basefrom
constantinius/feat/ai/integration

Conversation

@constantinius
Copy link
Copy Markdown

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

  • Registers AiIntegration in the feature list.
  • Adds base AI tracing config flags:
    • tracing.gen_ai
    • tracing.gen_ai_invoke_agent
  • Implements agent lifecycle handlers:
    • PromptingAgent / StreamingAgent -> start invoke_agent span
    • AgentPrompted / AgentStreamed -> finish invoke_agent span
  • Captures baseline metadata:
    • agent name
    • request/response model
    • provider name
    • token usage
    • streaming flag
    • conversation id

Made-with: Cursor

Issues

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
@linear-code
Copy link
Copy Markdown

linear-code bot commented Mar 16, 2026

@constantinius constantinius requested a review from Litarnus March 16, 2026 14:35
@constantinius constantinius changed the base branch from master to constantinius/feat/ai/integration-base March 16, 2026 14:53
@constantinius constantinius marked this pull request as ready for review March 16, 2026 14:54
$provider = $event->prompt->provider ?? null;
$providerName = $provider !== null ? $provider->name() : null;
if ($providerName !== null) {
$data['gen_ai.provider.name'] = $providerName;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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)
Fix in Cursor Fix in Web

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).
@constantinius constantinius force-pushed the constantinius/feat/ai/integration branch from 69471c9 to 6f06a2c Compare April 2, 2026 13:31
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).
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

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);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Fix in Cursor Fix in Web

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.

1 participant