mliviu79 / laravel-langfuse-prism
Seamless integration of Langfuse observability for Laravel and Laravel Prism.
Package info
github.com/Mliviu79/laravel-langfuse-prism
pkg:composer/mliviu79/laravel-langfuse-prism
Requires
- php: ^8.2|^8.3|^8.4
- ext-json: *
- illuminate/container: ^9.0|^10.0|^11.0|^12.0
- illuminate/http: ^9.0|^10.0|^11.0|^12.0
- illuminate/support: ^9.0|^10.0|^11.0|^12.0
- open-telemetry/exporter-otlp: ^1.3
- open-telemetry/sdk: ^1.9
- php-http/guzzle7-adapter: ^1.1
- psr/log: ^1.1|^2.0|^3.0
- ramsey/uuid: ^4.7
Requires (Dev)
- laravel/pint: ^1.10
- mockery/mockery: ^1.6
- orchestra/testbench: ^7.0|^8.0|^9.0|^10.0
- phpstan/phpstan: ^1.10|^2.0
- phpunit/phpunit: ^10.0|^11.0
This package is auto-updated.
Last update: 2026-03-14 17:43:53 UTC
README
A comprehensive PHP SDK for the Langfuse observability platform, featuring native integration with Laravel and Laravel Prism.
This package provides a seamless way to trace your LLM applications, monitor costs, and debug complex AI workflows directly within your Laravel application.
✨ Features
- 🚀 Deep Prism Integration: Automatically traces all Prism LLM operations (text, embeddings, images, audio).
- 🔍 Full Observability: Detailed span hierarchy, latency tracking, and error monitoring.
- 💰 Cost & Usage Tracking: Automatic token counting and cost calculation for supported models.
- ⚡ Performance: Non-blocking OpenTelemetry-based tracing with queued background exports.
- 🎨 Laravel Native: Service provider, Facade, config publication, and queue integration.
- 📊 Media Support: Handles image, document, and audio inputs/outputs.
📦 Installation
composer require mliviu79/laravel-langfuse-prism
Laravel Setup
- Publish the configuration file:
php artisan vendor:publish --tag=langfuse-config
- Add your Langfuse credentials to
.env:
LANGFUSE_PUBLIC_KEY=pk-lf-your-public-key LANGFUSE_SECRET_KEY=sk-lf-your-secret-key LANGFUSE_HOST=https://cloud.langfuse.com
🚀 Quick Start with Prism
The package automatically detects Prism events. Simply enable it in your config (enabled by default):
// config/langfuse.php 'prism' => [ 'auto_trace' => true, 'trace_model_params' => true, 'trace_usage' => true, 'trace_cost' => true, ],
Now, any Prism call is automatically traced:
use Prism\Prism\Facades\Prism; // This operation will be automatically traced in Langfuse $response = Prism::text() ->using('anthropic', 'claude-3-opus') ->withPrompt('Explain quantum computing like I am 5') ->generate();
Manual Tracing
For non-Prism logic or custom workflows, use the Facade:
use Langfuse\Integration\Laravel\Facades\Langfuse; $span = Langfuse::startSpan('my-custom-operation'); try { // ... your code ... $span->end(); } catch (\Exception $e) { $span->update(level: 'ERROR', statusMessage: $e->getMessage()); $span->end(); throw $e; }
⚠️ Maintenance & Philosophy
This package was originally refactored from laravel-langfuse to specifically solve our needs for native Laravel Prism integration and robust OpenTelemetry support.
We are sharing this in the spirit of open source, hoping it helps others with similar requirements. However, please note:
- Updates: We maintain this package primarily to support our own production applications. Updates will be released as our needs evolve.
- Contributions: We welcome Pull Requests! If you need a feature we don't use, please submit a PR. We are happy to merge community contributions that align with the package's goals.
- Forking: If your use case diverges significantly from ours, we encourage you to fork the repository and adapt it to your needs.
We aim to keep the package stable and usable, but we may not prioritize features that aren't relevant to our internal use cases.
🤝 Contributing
Please see CONTRIBUTING for details.
📄 License
The MIT License (MIT). Please see License File for more information.
🏆 Credits
- Original Creator: Hanan
- Maintainer: Liviu Muresan
Built with ❤️ for the Laravel community.