Download the PHP package ampersand/magento2-log-correlation-id without Composer

On this page you can find all versions of the php package ampersand/magento2-log-correlation-id. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package magento2-log-correlation-id

magento2-log-correlation-id

Build Status

Magento 2 log correlation id for PHP requests/processes and magento logs.

This is useful when debugging issues on a production site as high amounts of traffic can cause many logs to be written and identifying which logs belong to a specific failing request can sometimes be difficult.

With this you should easily be able to find all associated logs for a given web request or CLI process.

Install

Composer install the module.

Add the additional dependency injection config necessary to boot early in the application flow

At this point you can make any configuration changes

Run module installation

Uninstall

How it works

Entry point

This module creates a new cache decorator (src/CacheDecorator/CorrelationIdDecorator.php).

It needs to be here so that it's constructed immediately after Magento\Framework\Cache\Frontend\Decorator\Logger which is the class responsible for instantiating Magento\Framework\App\Request\Http and the Logger triggered after.

This is the earliest point in the magento stack where we can get any existing traceId from a request header (for example cf-request-id) and have it attached to any logs produced.

This cache decorator initialises the identifier which is immutable for the remainder of the request.

Exit points

Example usage

Firstly you need to expose the header in your logs, this is an example for apache logs

If you are using Nginx, that's how you can add the correlation id to the access logs

The above configuration would give log output like the following when viewing a page

You could then search for all magento logs pertaining to that request

If the request was long-running, or had an error it may also be flagged in new relic with the custom parameter amp_correlation_id

Configuration and Customisation

Add identifier to MySQL queries

Inside app/etc/ampersand_magento2_log_correlation/di.xml you can change to disabled="false"

This will add the correlation identifier to all queries like SELECT store_group.* FROM store_group /* 'cid-652918943af7b811319570' */

Change the key name from amp_correlation_id

You can change the monolog/new relic key from amp_correlation_id using app/etc/ampersand_magento2_log_correlation/di.xml

Use existing correlation id from request header

If you want to use an upstream correlation/trace ID you can define one app/etc/ampersand_magento2_log_correlation/di.xml

If this is present on the request magento will use that value for X-Log-Correlation-Id, the monolog context, and the New Relic parameter. Otherwise magento will generate one.

For example

Custom Loggers

By default this module hooks into all vanilla magento loggers.

However third party modules may define additional loggers to write to custom files. If you want the correlation ID added to those logs as well you will need to create a module that depends on both Ampersand_LogCorrelation_Id and the module with the custom logger, you will then have to add the log handler in di.xml like so

This module provides a command to try to help you keep track of the custom loggers in your system


All versions of magento2-log-correlation-id with dependencies

PHP Build Version
Package Version
Requires php Version >=7.3.0
magento/framework Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ampersand/magento2-log-correlation-id contains the following files

Loading the files please wait ....