Download the PHP package plopster/trace-code-maker without Composer
On this page you can find all versions of the php package plopster/trace-code-maker. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download plopster/trace-code-maker
More information about plopster/trace-code-maker
Files in plopster/trace-code-maker
Package trace-code-maker
Short Description A Laravel library designed to create and manage unique trace codes for monitoring, logging, and tracing errors or responses within services. Easy installation with automated setup commands.
License MIT
Informations about the package trace-code-maker
TraceCodeMaker Library
Overview
TraceCodeMaker
is a modern Laravel library designed to create and manage unique trace codes for monitoring, logging, and tracing errors or responses within services. The library features automatic installation, caching support, and comprehensive configuration options.
Features
- ✅ Automatic Installation: Just two commands to get started
- ✅ Auto-Discovery: Automatically registers service provider and facade
- ✅ Caching Support: Optional caching for improved performance
- ✅ Configurable: Extensive configuration options
- ✅ Validation: Built-in parameter validation
- ✅ Database Agnostic: Works with any Laravel-supported database
- ✅ Laravel 9, 10, 11, 12 Support: Compatible with modern Laravel versions
Requirements
- Laravel 9.x, 10.x, 11.x, or 12.x
- PHP 8.1 or higher
Quick Installation
Step 1: Install via Composer
Step 2: Run Installation Command
That's it! 🎉 The installation command will:
- Publish the configuration file
- Publish and run the migration
- Clear application cache
- Set up everything automatically
Manual Installation (Alternative)
If you prefer manual installation:
1. Install Package
2. Publish Files
3. Run Migration
Configuration
After installation, you can customize the library by editing the published configuration file:
Configuration Options
Default Service
Sets the default service name when none is provided.
Trace Code Format
Customize how trace codes are generated.
Database Settings
Configure database connection and table name.
Cache Settings
Enable/disable caching and set cache duration.
Validation Rules
Customize validation rules for input parameters.
Environment Variables
You can configure the library using environment variables in your .env
file:
Performance Optimization
Caching
The library includes built-in caching to improve performance:
- Trace codes are cached after creation
- Cache keys are generated based on service, HTTP code, method, and class
- Cache TTL is configurable (default: 1 hour)
Database Indexes
The migration includes optimized indexes for:
trace_code
(unique)service
http_code
method
class
timestamp
Memory Usage
- Validation rules are cached
- Database queries are optimized
- Minimal memory footprint
Usage
After installation, you can use TraceCodeMaker
anywhere in your Laravel application.
Basic Usage
Advanced Usage Examples
In Exception Handling
In Middleware
Using Configuration Defaults
Response Format
The fetchOrCreateTraceCode
method returns an array with the following structure:
Success Response:
Error Response:
Trace Code Format
Generated trace codes follow this pattern:
{SERVICE_CODE}-{HTTP_CODE}-{METHOD_HASH}-{TIMESTAMP}{RANDOM_SUFFIX}
Example: USR-500-a1b2c-240101123045ABCD
- USR: First 3 characters of service name (configurable)
- 500: HTTP status code
- a1b2c: MD5 hash of class.method (first 5 chars, configurable)
- 240101123045: Timestamp in ymdHis format (configurable)
- ABCD: Random suffix (4 chars, configurable)
Testing
The library includes comprehensive tests. To run them:
Test Database
Tests use SQLite in-memory database by default. You can configure this in phpunit.xml
.
Troubleshooting
Common Issues
Migration Not Found
Cache Issues
Service Provider Not Registered
For Laravel 10 and below, manually add to config/app.php
:
Database Connection Issues
Ensure your database configuration is correct:
Debug Mode
Enable debug logging by setting:
Version Compatibility
Laravel Version | PHP Version | Package Version |
---|---|---|
12.x | 8.1+ | 1.0+ |
11.x | 8.1+ | 1.0+ |
10.x | 8.1+ | 1.0+ |
9.x | 8.1+ | 1.0+ |
Contributing
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Development Setup
Coding Standards
- Follow PSR-12 coding standards
- Add tests for new features
- Update documentation as needed
- Ensure backward compatibility
License
This project is open-sourced software licensed under the MIT license.
Support
If you encounter any issues or have questions:
- Check the troubleshooting section
- Open an issue on GitHub
- Review existing issues and discussions
Changelog
v1.0.0
- Initial release
- Laravel 9-12 support
- Auto-discovery support
- Caching mechanism
- Configurable validation
- Artisan commands for installation
- Comprehensive documentation
All versions of trace-code-maker with dependencies
illuminate/support Version ^9.0|^10.0|^11.0|^12.0
illuminate/database Version ^9.0|^10.0|^11.0|^12.0
illuminate/console Version ^9.0|^10.0|^11.0|^12.0