Code Monkey home page Code Monkey logo

laravel-time-weaver's Introduction

Laravel Time Weaver

A small footprint package designed for seamlessly tracking and logging the response time of external HTTP requests within your Laravel applications. Inspired by the realms of science fiction, this package acts as a temporal guardian, meticulously recording and analyzing the chronicles of your application's interactions with the vast digital cosmos.

Installation

composer require boserup/laravel-time-weaver

Getting Started

  1. Configure AWS Credentials: By default Laravel Time Weaver logs to CloudWatch. Set the following environment variables to configure AWS credentials:

    • AWS_REGION: Your AWS region.
    • CLOUDWATCH_KEY: Your CloudWatch access key.
    • CLOUDWATCH_SECRET: Your CloudWatch secret key.
  2. Customize Metric Namespace: If you wish to change the default metric namespace from "LaravelTimeWeaver," set the TIME_WEAVER_CLOUDWATCH_METRIC_NAMESPACE environment variable.

  3. Adjust Metric Name: To modify the default metric name from "ExternalHttpResponseTime," set the TIME_WEAVER_CLOUDWATCH_METRIC_NAME environment variable.

  4. Toggle Logging for all hosts: By default Laravel Time Weaver will log the response time for all outgoing requests. Toggle this behaviour by setting the TIME_WEAVER_LOG_ALL_HOSTS environment variable. If set to false, you'll need to publish the configuration file to define the list of allowed hosts.

    php artisan vendor:publish --tag=time-weaver-config

Using a Custom Logger

Laravel Time Weaver allows you to use a custom logger for recording response times. By default, the package ships with CloudFront metric logging. However, you have the flexibility to implement your own logger by following these steps:

  1. Publish Configuration File: If you haven't already, publish the configuration file using the following command:

    php artisan vendor:publish --tag=time-weaver-config

    This will create a configuration file (config/time-weaver.php) in the config directory.

  2. Update Configuration: Open the published configuration file. Within this file, you can customize the logger class.

    return [
       // Other configuration options...
    
       'logger' => \Your\Custom\Logger\CustomLogger::class,
    
       // Other configuration options...
    ];

    Set the `'logger' attribute to the fully-qualified class name of your custom logger.

  3. Implement Custom Logger: Your custom logger class should implement the LoggerContract interface, defined as such:

    <?php
    
    namespace Your\Custom\Logger;
    
    use Boserup\LaravelTimeWeaver\Contracts\LoggerContract;
    
    class CustomLogger implements LoggerContract
    {
       public function log(string $hostname, float $time): void
       {
          // Logic goes here...
       }
    }
    
    ?>

Contributing

We welcome contributions from fellow time travelers and developers. Feel free to fork the repository, make improvements, and submit pull requests.

License

Laravel Time Weaver is open-source software licensed under the MIT license.

Embark on a journey through time and space with Laravel Time Weaver โ€“ your trusted companion in unraveling the mysteries of response time optimization!

laravel-time-weaver's People

Contributors

boserup avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.